-
-
Notifications
You must be signed in to change notification settings - Fork 272
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
feat: Allow optimal routing by bypassing middleware #1742
base: main
Are you sure you want to change the base?
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
@syrusakbary is attempting to deploy a commit to the next-intl Team on Vercel. A member of the Team first needs to authorize it. |
c2ce127
to
f53d80b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for sharing the link to vercel/next.js#38273, I haven't heard about this yet! Seems like the Next.js team is tracking this issue in their bug tracker.
As for this PR, I'm having a bit a hard time to understand what you're trying to achieve. The middleware is required for i18n routing for quite a few features:
- Locale-prefix-based rewrites
- Domain-based rewrites
- Localized pathnames
- Setting a cookie (e.g. when changing a locale)
- Handling redirects as necessary
- …
I don't really understand what kind of shortcut you want to take here, but the middleware is relevant for the default locale just as much as for non-default locales.
Can you provide more details on what exactly the issue is that you're facing?
As a side note, rootParams
is coming to Next.js and will make it easier than ever to provide your own middleware in case you have special requirements. I hope to have more to share on this soon!
Sure! Let me explain our use case at Wasmer. We want to use localization in a similar fashion as apple (via path routing). That means, that the urls that we have are:
And also localized routes:
Basically, the default locale is english (and as such, it should not have prefixed urls) and we also want the default one to not use middlewares if possible (as they can slow down requests). We want to see if we could achieve this by preserving the same app structure as we had before i18n the urls (that means having the So in summary: Locale is mainly dictated by the path (not domain or a cookie). By doing this simple change, we can use Happy to provide more insight if useful via text or even a Zoom call!
|
Introduced a new field to allow bypassing middleware when possible
f53d80b
to
b43cdf2
Compare
029214d
to
a0e732d
Compare
a0e732d
to
b43cdf2
Compare
For the routing structure you're describing, the
You probably still only want to define your pages once for all locales, right? For this to work, you need some kind of middleware. For the time being, if avoiding a middleware is the most important aspect for you, I think a prefix for the default locale might be required. However, if you're willing to declare your pages separately for the default and secondary locales, this could theoretically be done with such a setup:
Your pages could still share components (as much as the whole page), but it's required to define the Separately from this, it seems like the Next.js team is tracking vercel/next.js#38273 to hopefully improve this. They're actively working on the middleware currently to enable Node.js support, maybe that could yield some improvements 🤞. Edit: Added a question here. So as a conclusion, I don't see |
Unfortunately, the
Next.js will rightfully error here, since it will not know what page you are trying to access when accessing If this small setting change is too much hassle, perhaps other way would be to export all the functions that middleware uses so I can recreate the |
@syrusakbary Right, another top-level param like Anyway, based on the currently available information, I don't really see fit for this adjustment currently in the Next.js 15.2 just shipped and includes
Sorry, currently I don't really see a good time for this. Next.js is working on reshaping their middleware API (ref) and I don't want to expose more public API in this area currently that might break soon. I hope you can understand. |
This PR optimizes
next-intl
by using middeware only for non-default locales.Currently, using next-intl with app-routing localization, requires using the middleware always.
Since middleware in Next.js 13+ can be costly to run, this PR allows:
[locale]
directory