Skip to content

Commit 8cac7f7

Browse files
committed
fix: LanguageSwitcher sets cookie before activation and uses href navigation
- Write cookie before dynamicActivateLocale so the SSR request always carries the new locale even if the dynamic import is slow - Replace window.location.reload() with href navigation to bypass browser back-forward cache that can serve stale SSR HTML
1 parent 21b3c76 commit 8cac7f7

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

  • frontend/src/components/common/LanguageSwitcher

frontend/src/components/common/LanguageSwitcher/index.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,13 @@ export const LanguageSwitcher = () => {
6565
}))}
6666
defaultValue={getClientLocale()}
6767
placeholder={t`English`}
68-
onChange={(value) =>
69-
dynamicActivateLocale(value as string).then(() => {
70-
document.cookie = `locale=${value};path=/;max-age=31536000`;
71-
// this shouldn't be necessary, but it is due to the wide use of t`...` in the codebase
72-
window.location.reload();
73-
})}
68+
onChange={(value) => {
69+
if (!value) return;
70+
document.cookie = `locale=${value};path=/;max-age=31536000`;
71+
dynamicActivateLocale(value).finally(() => {
72+
window.location.href = window.location.pathname + window.location.search;
73+
});
74+
}}
7475
/>
7576
</>
7677
)

0 commit comments

Comments
 (0)