From 9b5739a886488f3c07c8bafb3456d3d250315250 Mon Sep 17 00:00:00 2001 From: Anton Dosov Date: Wed, 24 Jun 2020 17:53:02 +0200 Subject: [PATCH] fix possible stale hashHistory.location in discover --- src/plugins/discover/public/kibana_services.ts | 16 +++++++++++++++- src/plugins/discover/public/plugin.ts | 2 ++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/plugins/discover/public/kibana_services.ts b/src/plugins/discover/public/kibana_services.ts index bbd0357f41ed4..b8d3129878970 100644 --- a/src/plugins/discover/public/kibana_services.ts +++ b/src/plugins/discover/public/kibana_services.ts @@ -59,10 +59,24 @@ export const [getDocViewsRegistry, setDocViewsRegistry] = createGetterSetter createHashHistory()); +/** + * Discover & context are using same hash history instance, + * When getting back to discover internal history.location could get out of sync with window.location + * This helper function syncs window.location state to internal hash history + * + * Using this on discover mount also workarounds possible issues with async hash event: https://github.com/elastic/kibana/pull/65163 + * This helper is temp until: https://github.com/elastic/kibana/issues/65161 resolved + */ +export const ensureHashHistoryLocation = () => { + const h = getHistory(); + Object.assign(h.location, createHashHistory().location); + return h; +}; + export const [getScopedHistory, setScopedHistory] = createGetterSetter( 'scopedHistory' ); diff --git a/src/plugins/discover/public/plugin.ts b/src/plugins/discover/public/plugin.ts index 091288e3e65aa..5416462147b31 100644 --- a/src/plugins/discover/public/plugin.ts +++ b/src/plugins/discover/public/plugin.ts @@ -55,6 +55,7 @@ import { setServices, setScopedHistory, getScopedHistory, + ensureHashHistoryLocation, } from './kibana_services'; import { createSavedSearchesLoader } from './saved_searches'; import { registerFeature } from './register_feature'; @@ -242,6 +243,7 @@ export class DiscoverPlugin throw Error('Discover plugin method initializeInnerAngular is undefined'); } setScopedHistory(params.history); + ensureHashHistoryLocation(); appMounted(); const { plugins: { data: dataStart },