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

Prepare for ppr and dynamicIO #1493

Open
amannn opened this issue Oct 31, 2024 · 5 comments
Open

Prepare for ppr and dynamicIO #1493

amannn opened this issue Oct 31, 2024 · 5 comments
Labels
enhancement New feature or request

Comments

@amannn
Copy link
Owner

amannn commented Oct 31, 2024

Next.js is changing the rendering behavior. It's still very early, and things are moving, but it would be interesting to see if we can adapt next-intl to better suit the needs of these rendering modes.

For now, this issue is meant to collect related resources.

Related

@zipme
Copy link

zipme commented Nov 6, 2024

Hi @amannn, thank you for the great work on next-intl!

Just to confirm, does next-intl currently not support per-page revalidation partial prerendering (PPR) for Next 15? Since params are now asynchronous, it seems we need to do something like this:

export default async function Layout(
  props: { params: Promise<{locale: string}> }
) {
  const params = await props.params;
  setRequestLocale(params.locale);

Would this approach opt out of static rendering?

@amannn
Copy link
Owner Author

amannn commented Nov 7, 2024

Hmm, are we talking about the same thing? PPR in Next.js refers to partial prerendering, but based on your comment I think you mean the same thing?

I haven't had the time to experiment with PPR yet, but am planning to do this in the next few days. I'd be curious if generateStaticParams has an effect on whether reading params requires dynamic rendering—at least from a user perspective I'd expect it to render fine statically. Not sure if other pieces are relevant though like 'use cache';.

I'll update this thread here with my findings!

@zipme
Copy link

zipme commented Nov 7, 2024

Thanks for the update! Yes, I was referring to partial prerendering (I updated my comment). I would have expected generateStaticParams to influence this behavior, and it indeed worked in Next 14. However, after upgrading to 15, it no longer functions as expected.

It's still unclear whether params qualifies as a dynamic API. It's not listed here: https://nextjs.org/docs/app/building-your-application/rendering/server-components#dynamic-apis, but in the version 15 upgrade guide, it does mention an async request dynamic API change, and params appears in the list.

@amannn
Copy link
Owner Author

amannn commented Nov 7, 2024

That's interesting, yes. There seems to be a new API coming for accessing top-level params: #663 (comment). Maybe that one will have a different behavior when used with PPR.

@amannn
Copy link
Owner Author

amannn commented Nov 14, 2024

Ok, I was heads-down exploring implications of dynamicIO and ppr for next-intl over the last few days.

Two insights led to minor changes for the upcoming next-intl@4:

  1. feat!: Remove default of now={new Date()} from NextIntlClientProvider for usage with format.relativeTime (preparation for dynamicIO) #1536
  2. feat!: Require NextIntlClientProvider for using useLocale on the client side (preparation for dynamicIO) #1541

Apart from this, my impression was that ppr + dynamicIO have some rather rough edges currently. That being said, I hope the changes mentioned above cover all potential adaptions relevant for next-intl, so when the development on the Next.js side progresses, users should be able to upgrade without any changes in next-intl.

I made a few notes during my exploration, but it mostly comes down to apps with i18n routing requiring these currently missing pieces:

  1. A replacement for dynamicParams = false
  2. An API to read params deeply

For apps without i18n routing, I think next-intl@4 and the patterns suggested in the docs might work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants