Skip to content

Commit 8f780a8

Browse files
authored
fix(ssr): ensure locale is set (#12096)
* fix(ssr): ensure locale is set * fix(ssr): always set html[lang] to en-US
1 parent 22d6890 commit 8f780a8

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

Diff for: ssr/render.tsx

+6-5
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ export default function render(
7676
blogMeta = null,
7777
}: HydrationData = { url }
7878
) {
79+
if (!locale) {
80+
locale = (doc && doc.locale) || DEFAULT_LOCALE;
81+
}
82+
7983
const canonicalURL = `${BASE_URL}${url}`;
8084

8185
let realPageTitle = pageTitle;
@@ -139,10 +143,7 @@ export default function render(
139143
}
140144

141145
// Open Graph protocol expects `language_TERRITORY` format.
142-
const ogLocale = (locale || (doc && doc.locale) || DEFAULT_LOCALE).replace(
143-
"-",
144-
"_"
145-
);
146+
const ogLocale = locale.replace("-", "_");
146147

147148
if (locale === "de") {
148149
// Prevent experimental German locale from being indexed.
@@ -158,7 +159,7 @@ export default function render(
158159
return (
159160
"<!doctype html>" +
160161
renderToString(
161-
<html lang={locale || DEFAULT_LOCALE} prefix="og: https://ogp.me/ns#">
162+
<html lang={DEFAULT_LOCALE} prefix="og: https://ogp.me/ns#">
162163
<head>
163164
<meta charSet="utf-8" />
164165
<meta name="viewport" content="width=device-width,initial-scale=1" />

0 commit comments

Comments
 (0)