diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/source_router.test.tsx b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/source_router.test.tsx
index 528065da23af6..dda3eeea54926 100644
--- a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/source_router.test.tsx
+++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/source_router.test.tsx
@@ -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();
- unmountHandler();
-
- expect(resetSourceState).not.toHaveBeenCalled();
- });
-
it('resets state when leaving source tree', () => {
mockLocation.pathname = '/home';
shallow();
diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/source_router.tsx b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/source_router.tsx
index cd20e32def16d..d5d6c8e541e4f 100644
--- a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/source_router.tsx
+++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/source_router.tsx
@@ -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 ;
const {