[Lens] Reload on change via history object (#81753)

This commit is contained in:
Joe Reuter 2020-11-03 14:29:56 +01:00 committed by GitHub
parent 677b373ade
commit d8c37fe890
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 0 deletions

View file

@ -151,6 +151,11 @@ export async function mountApp(
trackUiEvent('loaded_404');
return <FormattedMessage id="xpack.lens.app404" defaultMessage="404 Not Found" />;
}
// 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();
};
}

View file

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