From 8f5286ef501d2e88cffbe4f7d8cdeb23a4af6cf1 Mon Sep 17 00:00:00 2001 From: osdnk Date: Thu, 9 Jul 2020 18:20:27 +0200 Subject: [PATCH] fix: ensure correct document title after going back on Chrome --- packages/native/src/__mocks__/window.tsx | 1 + packages/native/src/useLinking.tsx | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/packages/native/src/__mocks__/window.tsx b/packages/native/src/__mocks__/window.tsx index 273a81c9..b5abef39 100644 --- a/packages/native/src/__mocks__/window.tsx +++ b/packages/native/src/__mocks__/window.tsx @@ -62,6 +62,7 @@ const removeEventListener = (type: 'popstate', listener: () => void) => { }; export default { + document: { title: '' }, location, history, addEventListener, diff --git a/packages/native/src/useLinking.tsx b/packages/native/src/useLinking.tsx index a82159b8..9268fc66 100644 --- a/packages/native/src/useLinking.tsx +++ b/packages/native/src/useLinking.tsx @@ -116,6 +116,19 @@ const createMemoryHistory = () => { pending = true; const done = () => { + // There seems to be a bug in Chrome regarding updating the title + // If we set a title just before calling `history.go`, the title gets lost + // However the value of `document.title` is still what we set it to + // It's just not displayed in the tab bar + // To update the tab bar, we need to reset the title to something else first (e.g. '') + // And set the title to what it was before so it gets applied + // It won't work without setting it to empty string coz otherwise title isn't changing + // Which means that the browser won't do anything after setting the title + const { title } = window.document; + + window.document.title = ''; + window.document.title = title; + pending = false; window.removeEventListener('popstate', done);