Skip to content

Commit 5893ae3

Browse files
author
Peter Bengtsson
authored
don't let the href depend on the router hash in client-side rendering (#24106)
1 parent 0da2942 commit 5893ae3

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

components/page-header/LanguagePicker.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ export const LanguagePicker = ({ variant }: Props) => {
1414
const langs = Object.values(languages)
1515
const selectedLang = languages[locale]
1616

17+
// The `router.asPath` will always be without a hash in SSR
18+
// So to avoid a hydraration failure on the client, we have to
19+
// normalize it to be without the hash. That way the path is treated
20+
// in a "denormalized" way.
21+
const routerPath = router.asPath.split('#')[0]
22+
1723
return (
1824
<Picker
1925
variant={variant}
@@ -25,7 +31,7 @@ export const LanguagePicker = ({ variant }: Props) => {
2531
text: lang.nativeName || lang.name,
2632
selected: lang === selectedLang,
2733
item: (
28-
<Link href={router.asPath} locale={lang.code}>
34+
<Link href={routerPath} locale={lang.code}>
2935
{lang.nativeName ? (
3036
<>
3137
<span lang={lang.code}>{lang.nativeName}</span> (

0 commit comments

Comments
 (0)