-
Notifications
You must be signed in to change notification settings - Fork 27k
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
i18n: Wrong locale on getServerSideProps when using next.config.js rewrite #53988
Comments
Huge thanks to @iljamulders I finally solve it returning to 13.2.4! For me, problem was getServerSideProps({locale}) was always returning my default locale and not my current one |
same as #50498 |
Thank you @iljamulders |
@iljamulders thanks for the heads up. Looks like last working version for us is |
I've updated my example to use the latest version |
Still broken for me in 13.5.1 if middleware is being used, even though the middleware is not even triggered for the paths. It just needs to exist. Ref: #54217 |
@raRaRa I had to remove |
I see, that makes the middleware run for every URL even though it's not needed (more costly AFAIK). But either way this is still a bug. |
Yeah you're right @raRaRa, leaving out the |
Have you tried on latest version? I think this is not happening anymore on next 14.1.0 |
I think I'm running into this on 14.2.4. Found this by searching. I have a link like But clicking a link on the page, whose destination is e.g., This seems to be the most relevant issue. So just pitching a vote here 😅 I just discovered this, so haven't yet had time to see if there are open PRs related to this. UPDATE: As mentioned on related tickets, if I delete the Wut. |
I tried out #61561 with I see there are some test failures there, but I'm new to Next internals, so don't know if that's flake or legit. |
Removing Thankfully, we don't appear to require that. Our conditional check is pretty lightweight as-is. |
Is there any resolution on this that doesn't require subbing out the matcher for Conditional Statements? |
do you have an example of what it looks like to replace a matcher with a conditional statement? |
Solution I found: add the route paths that use getServerSideProps (where the locale mismatch happens) to your config matcher array in middleware.js. This solved the problem for me and allowed me to continue using my config matchers |
Verify canary release
Provide environment information
Operating System: Platform: linux Arch: x64 Version: #1 SMP PREEMPT_DYNAMIC Sun Aug 6 20:05:33 UTC 2023 Binaries: Node: 18.14.2 npm: 9.5.0 Yarn: 1.22.19 pnpm: N/A Relevant Packages: next: 13.4.14-canary.5 eslint-config-next: 13.4.12 react: 18.2.0 react-dom: 18.2.0 typescript: 5.0.4 Next.js Config: output: N/A
Which area(s) of Next.js are affected? (leave empty if unsure)
Data fetching (gS(S)P, getInitialProps), Internationalization (i18n), Routing (next/router, next/navigation, next/link)
Link to the code that reproduces this issue or a replay of the bug
https://codesandbox.io/p/sandbox/routing-i18n-bug-gfc94t?file=%2Fnext.config.js%3A1%2C1
To Reproduce
If you click on "Link to Page1 PT" you will see that both
props
androuter
will output the correct locale,pt
.However, if you click on "Link to Pagina1 (Redirect to Page1) PT",
props
will be thedefaultLocale
(which isen
), whereasrouter
be the expected locale,pt
.The only difference between both links is that the second one works via a
next.config.js
rewrite
property.Describe the Bug
getServerSideProps
is not getting the correctlocale
if the route was using anext.config.js
rewrite
.This was working as expected up until and including version
13.2.5-canary.16
. On version13.2.5-canary.17
it has stopped working and has not being fixed yet (example on CodeSandbox is using the latest version13.4.14-canary.5
).Expected Behavior
getServerSideProps
should have the correctlocale
value regardless of the routing strategy.Which browser are you using? (if relevant)
No response
How are you deploying your application? (if relevant)
No response
The text was updated successfully, but these errors were encountered: