Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NextJS 14 with Next-intl (3.23.5) making every page dynamic #1477

Closed
3 tasks done
mycvlnn opened this issue Oct 28, 2024 · 9 comments
Closed
3 tasks done

NextJS 14 with Next-intl (3.23.5) making every page dynamic #1477

mycvlnn opened this issue Oct 28, 2024 · 9 comments
Labels
bug Something isn't working reproduction-missing unconfirmed Needs triage.

Comments

@mycvlnn
Copy link

mycvlnn commented Oct 28, 2024

Description

I followed the instructions in the documentation for the latest version. However, when I build, all my pages switch to dynamic rendering (even though my pages are not in a dynamic route like [locale]).
Even though I used setRequestLocale, it still doesn’t switch to static rendering.
You can check the screenshot below.

image
image

Verifications

Mandatory reproduction URL

https://github.com/amannn/next-intl/tree/main/examples/example-app-router

Reproduction description

Steps to reproduce:

Clone this example Next.js project from next-intl:
https://github.com/amannn/next-intl/tree/main/examples/example-app-router

Create a new page in the app folder, for example: app/test/page.tsx.

After creating the page, run npm run build in the project’s terminal.

You'll notice in the terminal that my test page is now set to dynamic rendering, even though it’s not part of a dynamic [locale] route.

Expected behaviour

Pages that are not within a dynamic route should, by default, be statically rendered during the build process.

@mycvlnn mycvlnn added bug Something isn't working unconfirmed Needs triage. labels Oct 28, 2024
@tosh79kt
Copy link

I can confirm this behavior with next 15.0.1 and next-intl 3.23.5.

Copy link

Thank you for your report!

Unfortunately, the reproduction is missing or incomplete, and as such we cannot investigate this issue. Please add a reproduction to the issue, otherwise it will be closed automatically.

Templates:

Creating a good reproduction takes time.

To help us resolve the issue quickly, please simplify the reproduction as much as possible by removing any unnecessary code, files, and dependencies that are not directly related to the problem. The easier it is for us to see the issue, the faster we can help you.

Apart from the reproduction, make sure to include the precise steps on how to reproduce the issue, e.g.:

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

Thank you for your understanding!

FAQ

"I've included a reproduction, what is missing?"

This comment might have been added because your reproduction doesn't point to a destination where the issue can be reproduced. Please make sure that the latest changes were saved in the reproduction and that the link is correct.

@reiv
Copy link

reiv commented Oct 30, 2024

Can confirm this happening as well. Next 15.0.2 with next-intl 3.23.5. I'm explicitly setting locale in all getTranslations(), but headers() still seems to be getting used to get the locale from the middleware.

Edit: patched in some logging and it looks like receiveRuntimeConfigImpl is getting called twice, the first time with localeOverride set to the specified locale and the second time undefined. Not sure what's going here.

@mycvlnn
Copy link
Author

mycvlnn commented Nov 2, 2024

I resolved this by adding the setRequestLocale(routing.defaultLocale) function inside the not-found.tsx file in the app directory. You can check the screenshot for details.

Thank you all very much! 🇻🇳

image

@mycvlnn mycvlnn closed this as completed Nov 2, 2024
@amannn
Copy link
Owner

amannn commented Nov 2, 2024

Interesting, could be this bug in Next.js: vercel/next.js#71623

@chrilis
Copy link

chrilis commented Nov 9, 2024

While this resolves the static rendering I don't think it allows localized not-found.tsx pages. Adding setRequestLocale(routing.defaultLocale) to next-intl/examples/example-app-router/src/app/not-found.tsx results in english translations and routing (routing.defaultLocale == 'en') for URLs like http://localhost:3000/de/unknown-route.

Is there another way to make localized not-found.tsx pages work without breaking static rendering or do we have to wait for the Next.js team to confirm and fix this issue first? Thank you!

PS: I'm happy to create a repro if that helps!

@amannn
Copy link
Owner

amannn commented Nov 11, 2024

Is there another way to make localized not-found.tsx pages work without breaking static rendering or do we have to wait for the Next.js team to confirm and fix this issue first? Thank you!

@chrilis As far as I know this is still possible in Next.js 14 (see App Router example):

In Next.js 15 I haven't found a way to achieve this yet, related to the bug that's mentioned above.

Note that the Next.js team is working on a new API specifically for cases like i18n to improve locale handling (see #663 (comment)). I think this could help to solve this in a clean way in the future without having to rely on setRequestLocale.

@chrilis
Copy link

chrilis commented Nov 11, 2024

Thank you for your quick reply @amannn! Maybe I'm wrong, but I think it's also relevant for Next.js 14, see [repro] (https://github.com/chrilis/next-intl/tree/repro/localized-404-static-rendering).

@amannn
Copy link
Owner

amannn commented Nov 12, 2024

Why would you want to add setRequestLocale to app/not-found.tsx in the example? Your comment in the commit says it "fixes static rendering of all pages (and the build error)" but I don't see which problems the example has with static rendering/building in the first place. Can you point to a practical issue that the example has on Next.js 14?

As a side note, it seems like we can get rid of setRequestLocale in the long run as the Next.js team is working on an official API for reading the [locale] param deeply: #663 (comment).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working reproduction-missing unconfirmed Needs triage.
Projects
None yet
Development

No branches or pull requests

5 participants