Skip to content

Commit

Permalink
fix(ssr): ensure locale is set
Browse files Browse the repository at this point in the history
  • Loading branch information
caugner committed Nov 7, 2024
1 parent 22d6890 commit 12cb8ec
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions ssr/render.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ export default function render(
blogMeta = null,
}: HydrationData = { url }
) {
if (!locale) {
locale = (doc && doc.locale) || DEFAULT_LOCALE;
}

const canonicalURL = `${BASE_URL}${url}`;

let realPageTitle = pageTitle;
Expand Down Expand Up @@ -139,10 +143,7 @@ export default function render(
}

// Open Graph protocol expects `language_TERRITORY` format.
const ogLocale = (locale || (doc && doc.locale) || DEFAULT_LOCALE).replace(
"-",
"_"
);
const ogLocale = locale.replace("-", "_");

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

0 comments on commit 12cb8ec

Please sign in to comment.