Skip to content

Commit 6478b4a

Browse files
pettinaripclaude
andcommitted
[recovery] fix: setRequestLocale ordering in [...slug] generateMetadata
The catch-all [locale]/[...slug] generateMetadata never called setRequestLocale before invoking next-intl APIs. getMdMetadata -> getMetadata calls getTranslations("common"), and the catch block also calls getTranslations("common"). Without setRequestLocale, next-intl reads the locale from request headers for on-demand slugs, opting the route into dynamic rendering and throwing "Page changed from static to dynamic at runtime ... reason: headers". Observed in production via /images/videos/Clw-qf1sUZg.jpg, which maps to the catch-all with locale="images". Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 1473dc4 commit 6478b4a

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

app/[locale]/[...slug]/page.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,13 @@ export async function generateMetadata(props: {
154154
const params = await props.params
155155
const { locale, slug } = params
156156

157+
// Set the locale before any next-intl API (getMdMetadata -> getMetadata and
158+
// the catch-block getTranslations both call getTranslations). Otherwise
159+
// next-intl reads the locale from request headers and opts the route into
160+
// dynamic rendering, triggering "Page changed from static to dynamic at
161+
// runtime" for on-demand slugs not covered by generateStaticParams.
162+
setRequestLocale(locale)
163+
157164
try {
158165
return await getMdMetadata({
159166
locale,

0 commit comments

Comments
 (0)