amannn / next-intl

🌐 Internationalization (i18n) for Next.js
https://next-intl-docs.vercel.app
MIT License
2.58k stars 236 forks source link

The getTranslations and useTranslations methods will fail when the server component sets dynamic to force-static #1319

Closed luokelong closed 2 months ago

luokelong commented 2 months ago

Description

I used the "export const dynamic = "force-static"; " syntax in the server component to make the cache-control attribute of the header set in the middleware take effect. Unfortunately, at this time, using the "const t = await getTranslations();" or "const t= useTranslations();" methods in page.tsx will fail and the page will return a not found 404 page.

"next": "14.2.1",
"next-intl": "^3.11.1",

App Router with src dir

Verifications

Mandatory reproduction URL

App Router

Reproduction description

Steps to reproduce:

  1. Open reproduction
  2. Click on …
  3. See error: …
  4. no more

Expected behaviour

Work well

amannn commented 2 months ago

force-static is not intended to be supported, this section should be linked to from an error you're probably seeing in your app. To implement static rendering properly, please follow the static rendering guide (theoretically, after you've set this up, force-static might even work).

to make the cache-control attribute of the header set in the middleware take effect

Is that actually the case? That's quite interesting, I wonder if that behavior is intended.

luokelong commented 2 months ago

force-static is not intended to be supported, this section should be linked to from an error you're probably seeing in your app. To implement static rendering properly, please follow the static rendering guide (theoretically, after you've set this up, force-static might even work).

to make the cache-control attribute of the header set in the middleware take effect

Is that actually the case? That's quite interesting, I wonder if that behavior is intended.

The problem has been solved with your help, thank you very much.