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

Middleware enhancements after new Next.js middleware architecture #1362

Open
amannn opened this issue Sep 23, 2024 · 3 comments
Open

Middleware enhancements after new Next.js middleware architecture #1362

amannn opened this issue Sep 23, 2024 · 3 comments
Labels
area: routing enhancement New feature or request

Comments

@amannn
Copy link
Owner

amannn commented Sep 23, 2024

Is your feature request related to a problem? Please describe.

It seems like there's work happening on the Next.js side on a middleware revamp: vercel/next.js#46722 (comment)

I'm using this thread to collect aspects about the current next-intl middleware that we could potentially address in case a revamp is relevant after the Next.js change.

Describe the solution you'd like

My personal wishlist for Next.js:

  1. Passing a locale to the rendering phase (see Reading params deeply in Server Components (e.g. for i18n / multi-tenancy) vercel/next.js#58862). Ideally this would be possible without a middleware in the first place though.
  2. A dynamically created matcher

Mentioned both here.

Separately from this, there are some use cases we could support better that do not rely on Next.js:

  1. Get the locale within middleware #1356
  2. Locale detection could be more flexible #1369
  3. Maybe opting out of root-redirect? Possibly already by adapting the matcher, but would there be an advantage to make this more explicit?
  4. Should the middleware automatically decide if a request should be handled or not (see example from docs), allowing us to remove the default matcher? (might need an option to opt-out) We'd only be able to do it for the localePrefix: 'always' case though (and only if the user doesn't want to automatically redirect /users → /en/users). Is this helpful?

We can make these changes in any case, but in case a refactoring is necessary after the Next.js change, maybe it'd be worth waiting a bit.

@amannn amannn added enhancement New feature or request area: routing labels Sep 23, 2024
@apavlinovic

This comment was marked as off-topic.

@amannn

This comment was marked as off-topic.

@amannn amannn changed the title Middleware enhancements Middleware enhancements after new Next.js middleware architecture Oct 1, 2024
@amannn
Copy link
Owner Author

amannn commented Oct 8, 2024

Seems like there's some movement here: vercel/next.js#70961.

As far as I understand the feature, it's mostly targeted at validation. The best I can think of is a validation that the [locale] param contains a valid value and alternatively call notFound(). This would be a slight improvement, but if the mere presence of an interceptor opts the page into dynamic rendering, this already has a downside in comparison to running the validation in [locale]/layout.tsx.

From a first glance, the new interceptors feature currently doesn't look like it could help with the pain points that were mentioned above. I'll keep an eye on it though.

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

No branches or pull requests

2 participants