From 8f270980c240587cb30f12d6100ee25d83e1fb51 Mon Sep 17 00:00:00 2001 From: Bartosz Prusinowski Date: Tue, 12 Sep 2023 16:07:52 +0200 Subject: [PATCH] fix: Overwriting of locale when redirecting to versioned cube ...there is no need to specify the locale in pathname. Using this led to overwiting the locale, as we used the old locale, while the router was setting a new one on route change. --- CHANGELOG.md | 1 + app/components/use-redirect-to-versioned-cube.spec.tsx | 4 ++-- app/components/use-redirect-to-versioned-cube.tsx | 2 +- app/pages/_app.tsx | 3 +-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 60c9d99aa..20927259a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ You can also check the [release page](https://github.com/visualize-admin/visuali - Fixes - Table docs now work correctly again + - Changing the locale when previewing a larger cube no longer triggers multiple locale switches # [3.22.5] - 2023-09-12 diff --git a/app/components/use-redirect-to-versioned-cube.spec.tsx b/app/components/use-redirect-to-versioned-cube.spec.tsx index 9c05ddf10..ef3cee332 100644 --- a/app/components/use-redirect-to-versioned-cube.spec.tsx +++ b/app/components/use-redirect-to-versioned-cube.spec.tsx @@ -87,7 +87,7 @@ describe("use redirect to versioned cube", () => { versionedCube: { iri: "https://versioned-cube" }, }); expect(router.replace).toHaveBeenCalledWith({ - pathname: "/de/browse", + pathname: "/browse", query: { dataset: "https://versioned-cube", }, @@ -100,7 +100,7 @@ describe("use redirect to versioned cube", () => { versionedCube: { iri: "https://versioned-cube2" }, }); expect(router.replace).toHaveBeenCalledWith({ - pathname: "/de/browse", + pathname: "/browse", query: { dataset: "https://versioned-cube2", }, diff --git a/app/components/use-redirect-to-versioned-cube.tsx b/app/components/use-redirect-to-versioned-cube.tsx index d6a9618f7..a5902f1f7 100644 --- a/app/components/use-redirect-to-versioned-cube.tsx +++ b/app/components/use-redirect-to-versioned-cube.tsx @@ -48,7 +48,7 @@ export const useRedirectToVersionedCube = ({ if (resp) { router.replace({ - pathname: `/${locale}/browse`, + pathname: `/browse`, query: { ...router.query, ...(router.query.iri ? { iri: resp.iri } : { dataset: resp.iri }), diff --git a/app/pages/_app.tsx b/app/pages/_app.tsx index 0c877b157..dfc60d377 100644 --- a/app/pages/_app.tsx +++ b/app/pages/_app.tsx @@ -26,11 +26,10 @@ export default function App({ pageProps: { session, ...pageProps }, }: AppProps) { const { events: routerEvents, asPath, locale: routerLocale } = useRouter(); + const locale = parseLocaleString(routerLocale ?? ""); useNProgress(); - const locale = parseLocaleString(routerLocale ?? ""); - // Immediately activate locale to avoid re-render if (i18n.locale !== locale) { i18n.activate(locale);