From 8f780a8ca6802e9248a3bc8c398286dc1e679138 Mon Sep 17 00:00:00 2001 From: Claas Augner <495429+caugner@users.noreply.github.com> Date: Thu, 7 Nov 2024 09:54:28 +0100 Subject: [PATCH] fix(ssr): ensure locale is set (#12096) * fix(ssr): ensure locale is set * fix(ssr): always set html[lang] to en-US --- ssr/render.tsx | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/ssr/render.tsx b/ssr/render.tsx index 7859de7d28bc..1bbf62e7894c 100644 --- a/ssr/render.tsx +++ b/ssr/render.tsx @@ -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; @@ -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. @@ -158,7 +159,7 @@ export default function render( return ( "" + renderToString( - +