Skip to content

Commit

Permalink
[Workplace Search] Fix bug when transitioning to personal dashboard (#…
Browse files Browse the repository at this point in the history
…100061)

The unmount callback should have never been in the useEffect keyed off of the pathname. Another issue appeared earlier and I tried to fix it with the now removed conditional, but it should have been removed into it’s own useEffect that only runs when the component is unmounted, not on every route change.

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
  • Loading branch information
scottybollinger and kibanamachine authored May 13, 2021
1 parent 9d9dfe4 commit 5507ba6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,6 @@ describe('SourceRouter', () => {
});

describe('reset state', () => {
it('does not reset state when switching between source tree views', () => {
mockLocation.pathname = `/sources/${contentSource.id}`;
shallow(<SourceRouter />);
unmountHandler();

expect(resetSourceState).not.toHaveBeenCalled();
});

it('resets state when leaving source tree', () => {
mockLocation.pathname = '/home';
shallow(<SourceRouter />);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ export const SourceRouter: React.FC = () => {

useEffect(() => {
initializeSource(sourceId);
return () => {
// We only want to reset the state when leaving the source section. Otherwise there is an unwanted flash of UI.
if (!pathname.includes(sourceId)) resetSourceState();
};
}, [pathname]);

useEffect(() => {
return resetSourceState;
}, []);

if (dataLoading) return <Loading />;

const {
Expand Down

0 comments on commit 5507ba6

Please sign in to comment.