Open amannn opened 5 days ago
The latest updates on your projects. Learn more about Vercel for Git ↗︎
Name | Status | Preview | Comments | Updated (UTC) |
---|---|---|---|---|
next-intl-docs | ✅ Ready (Inspect) | Visit Preview | 💬 Add feedback | Nov 14, 2024 2:19pm |
next-intl-example-app-router | ❌ Failed (Inspect) | Nov 14, 2024 2:19pm | ||
next-intl-example-app-router-without-i18n-routing | ✅ Ready (Inspect) | Visit Preview | 💬 Add feedback | Nov 14, 2024 2:19pm |
An exploration of how
next-intl
can adapt better forppr
anddynamicIO
(see https://github.com/amannn/next-intl/issues/1493).Centralized validation of
[locale]
segment withdynamicParams = false
If params can be read statically, we could use
dynamicParams = false
to return a 404 for unknown locales (see https://github.com/amannn/next-intl/commit/d1a0308e72d7f5111a7dcc6f34efd22d8ad0e576).However, it seems like this isn't a good idea to introduce yet:
dynamicParams
is not compatible withdynamicIO
—and maybe never will:However, it seems like Next.js is working on an alternative to
dynamicParams = false
. With this, maybe we'll have a reasonable solution for centralized validation of the[locale]
segment.Usage of
setRequestLocale
Calling
setRequestLocale
within a'use cache'
boundary doesn't seem to work. We need a mechanism from Next.js to read params deeply to get rid of this API.Reading the
locale
param without suspendingCurrently not easily possible, waiting for an alternative to
dynamicParams = false
: https://github.com/vercel/next.js/discussions/71927.What did work in my test though is to use
'use cache'
on both the layout and page entry point. This might not fit your application though and furthermore makes it impossible to read request-specific params in components. EDIT: It only works in dev, not when building the app.Another use case to be tested would be mixing a statically known
[locale]
param with a dynamic child page (see https://nextjs.org/blog/our-journey-with-caching#partial).Importing of JSON messages
Dynamic imports currently cause an error: https://github.com/vercel/next.js/issues/72589.
Effect of
use(…)
andawait
For the APIs that
next-intl
offers, these seem to not require a suspense boundary for async data—that's helpful.Effect of client-side hooks on caching
Hooks like
useParams
,useSelectedLayoutSegment
andusePathname
work fine in development but error out during the build when used in a dynamic segment like[locale]
, asking for a suspense boundary or'use cache'
. Not sure what the expected behavior is, but there's definitely an inconsistency here. See https://github.com/vercel/next.js/issues/72756.EDIT: This would probably also require a replacement for
dynamicParams = false
.Conclusion
ppr
anddynamicIO
might work (but requires https://github.com/amannn/next-intl/pull/1536)API considerations for
next-intl
to consider in the future:i18n/request.ts
. This way we can avoid hardcoding the[locale]
segment and also don't need to bump the peer dependency aggressively once this API is introduced.getLocale
is called ini18n/request.ts
? Would requireAsyncLocalStorage
./
? This will be possible once reading params deeply is a thing.