From d8c37fe890e5d38bd8ce5373417a30f5d8c7938f Mon Sep 17 00:00:00 2001 From: Joe Reuter Date: Tue, 3 Nov 2020 14:29:56 +0100 Subject: [PATCH] [Lens] Reload on change via history object (#81753) --- x-pack/plugins/lens/public/app_plugin/mounter.tsx | 6 ++++++ x-pack/plugins/lens/public/editor_frame_service/service.tsx | 1 + 2 files changed, 7 insertions(+) diff --git a/x-pack/plugins/lens/public/app_plugin/mounter.tsx b/x-pack/plugins/lens/public/app_plugin/mounter.tsx index c74ac951907e..bd43a1dcc20b 100644 --- a/x-pack/plugins/lens/public/app_plugin/mounter.tsx +++ b/x-pack/plugins/lens/public/app_plugin/mounter.tsx @@ -151,6 +151,11 @@ export async function mountApp( trackUiEvent('loaded_404'); return ; } + // dispatch synthetic hash change event to update hash history objects + // this is necessary because hash updates triggered by using popState won't trigger this event naturally. + const unlistenParentHistory = params.history.listen(() => { + window.dispatchEvent(new HashChangeEvent('hashchange')); + }); params.element.classList.add('lnsAppWrapper'); render( @@ -171,5 +176,6 @@ export async function mountApp( return () => { instance.unmount(); unmountComponentAtNode(params.element); + unlistenParentHistory(); }; } diff --git a/x-pack/plugins/lens/public/editor_frame_service/service.tsx b/x-pack/plugins/lens/public/editor_frame_service/service.tsx index d1df63780594..90e96be9e7ad 100644 --- a/x-pack/plugins/lens/public/editor_frame_service/service.tsx +++ b/x-pack/plugins/lens/public/editor_frame_service/service.tsx @@ -154,6 +154,7 @@ export class EditorFrameService { initialVisualizationId={ (doc && doc.visualizationType) || firstVisualizationId || null } + key={doc?.savedObjectId} // ensures rerendering when switching to another visualization inside of lens (eg global search) core={core} plugins={plugins} ExpressionRenderer={plugins.expressions.ReactExpressionRenderer}