[Workplace Search] Fix bug when transitioning to personal dashboard (#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>
This commit is contained in:
Scotty Bollinger 2021-05-13 16:16:28 -05:00 committed by GitHub
parent 9d9dfe4bbf
commit 5507ba6226
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 12 deletions

View file

@ -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 />);

View file

@ -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 {