From 68483afe32a8546bf3269164f1c9a671a08d906f Mon Sep 17 00:00:00 2001 From: Aral Roca Gomez Date: Mon, 4 Jul 2022 14:16:26 +0200 Subject: [PATCH] fix namespaces in Next.js +11 after history.back() --- package.json | 2 +- src/I18nProvider.tsx | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index cf957c0e..e2d4ef19 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "next-translate", - "version": "1.5.0-canary.3", + "version": "1.5.0-canary.4", "description": "Tiny and powerful i18n tools (Next plugin + API) to translate your Next.js pages.", "license": "MIT", "keywords": [ diff --git a/src/I18nProvider.tsx b/src/I18nProvider.tsx index 02df0f99..13c95e1e 100644 --- a/src/I18nProvider.tsx +++ b/src/I18nProvider.tsx @@ -17,6 +17,7 @@ export default function I18nProvider({ const { locale, defaultLocale } = useRouter() || {} const internal = useContext(InternalContext) const allNamespaces: Record = { + ...initialBrowserNamespaces(), ...internal.ns, ...namespaces, } @@ -35,3 +36,8 @@ export default function I18nProvider({ ) } + +function initialBrowserNamespaces() { + if (typeof window === 'undefined') return {} + return window.__NEXT_DATA__?.props?.__namespaces || {} +}