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
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.
  • Loading branch information
scottybollinger committed May 13, 2021
1 parent 5487657 commit 4094219
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 4094219

Please sign in to comment.