-
Notifications
You must be signed in to change notification settings - Fork 27.6k
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 rewrite doesn't work with i18n #30897
Labels
Comments
From my debugging, it seems like the locale is stripped from next.js/packages/next/server/next-server.ts Lines 1830 to 1838 in 450552d
|
kodiakhq bot
pushed a commit
that referenced
this issue
Nov 9, 2021
Fixes #30897 This PR fixes the linked issue where rewrites are not being applied for locale. It adds the corresponding test but also, as it was added in debugging process, it introduces a helper to read/write into the `request` object. We are currently writing directly into the request by casting to `any` and then using flags like `_nextRewrote`. Instead, this PR puts all of this metadata under a symbol so it is not directly accessible. This also allows to have a single place where all of this metadata is listed so we can add comments describing the purpose of each flag. In the same way, there is metadata written in the querystring. This is adding some types for it in order to throw some visibility on where is this metadata accessed. In an upcoming PR we can move all of it to the `request` object if possible to simplify the system. ## Bug - [x] Related issues linked using `fixes #number` - [x] Integration tests added - [x] Errors have helpful link attached, see `contributing.md`
This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
natew
pushed a commit
to natew/next.js
that referenced
this issue
Feb 16, 2022
Fixes vercel#30897 This PR fixes the linked issue where rewrites are not being applied for locale. It adds the corresponding test but also, as it was added in debugging process, it introduces a helper to read/write into the `request` object. We are currently writing directly into the request by casting to `any` and then using flags like `_nextRewrote`. Instead, this PR puts all of this metadata under a symbol so it is not directly accessible. This also allows to have a single place where all of this metadata is listed so we can add comments describing the purpose of each flag. In the same way, there is metadata written in the querystring. This is adding some types for it in order to throw some visibility on where is this metadata accessed. In an upcoming PR we can move all of it to the `request` object if possible to simplify the system. ## Bug - [x] Related issues linked using `fixes #number` - [x] Integration tests added - [x] Errors have helpful link attached, see `contributing.md`
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Labels
What version of Next.js are you using?
12.0.2
What version of Node.js are you using?
14.17.6
What browser are you using?
Chrome
What operating system are you using?
macOS
How are you deploying your application?
next start
Describe the Bug
Next 12 Middleware rewrite doesn't handle locale correctly with i18n routing enabled. For example, if we rewrite
/test
to/fr/test
using middleware, it will still show/test
with the default locale because the locale info is lost during rewrite.So you can't do this:
or equivalently this:
Expected Behavior
The locale info should be parsed when rewriting from middleware.
To Reproduce
I modified the vercel i18n example to demonstrate the issue.
See: https://github.com/leethree/next-i18n-rewrite
Supposedly you have
fr
as your browser locale. When visiting the home page (http://localhost:3000/), it should show your current locale as detected:(ignore the flag, note the "locale: fr" below that.)
But actual behaviour:
The text was updated successfully, but these errors were encountered: