Skip to content

Commit

Permalink
fix possible stale hashHistory.location in discover
Browse files Browse the repository at this point in the history
  • Loading branch information
Dosant committed Jun 24, 2020
1 parent 45f4cc4 commit 9b5739a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/plugins/discover/public/kibana_services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,24 @@ export const [getDocViewsRegistry, setDocViewsRegistry] = createGetterSetter<Doc
'DocViewsRegistry'
);
/**
* Makes sure discover and context are using one instance of history
* Makes sure discover and context are using one instance of history.
*/
export const getHistory = _.once(() => 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>(
'scopedHistory'
);
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/discover/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import {
setServices,
setScopedHistory,
getScopedHistory,
ensureHashHistoryLocation,
} from './kibana_services';
import { createSavedSearchesLoader } from './saved_searches';
import { registerFeature } from './register_feature';
Expand Down Expand Up @@ -242,6 +243,7 @@ export class DiscoverPlugin
throw Error('Discover plugin method initializeInnerAngular is undefined');
}
setScopedHistory(params.history);
ensureHashHistoryLocation();
appMounted();
const {
plugins: { data: dataStart },
Expand Down

0 comments on commit 9b5739a

Please sign in to comment.