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

In middleware.js nextUrl.locale is always default for client-side routing if skipMiddlewareUrlNormalize is true #53646

Closed
1 task done
matthewcc opened this issue Aug 7, 2023 · 1 comment · Fixed by #54357
Labels
bug Issue was opened via the bug report template. locked Navigation Related to Next.js linking (e.g., <Link>) and navigation. Runtime Related to Node.js or Edge Runtime with Next.js.

Comments

@matthewcc
Copy link

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
      Platform: darwin
      Arch: x64
      Version: Darwin Kernel Version 22.5.0: Mon Apr 24 20:51:50 PDT 2023; root:xnu-8796.121.2~5/RELEASE_X86_64
    Binaries:
      Node: 18.16.0
      npm: 9.5.1
      Yarn: 1.22.17
      pnpm: 8.1.0
    Relevant Packages:
      next: 13.4.13-canary.17
      eslint-config-next: 13.4.12
      react: 18.2.0
      react-dom: 18.2.0
      typescript: 5.1.6
    Next.js Config:
      output: N/A

Which area(s) of Next.js are affected? (leave empty if unsure)

Internationalization (i18n), Middleware / Edge (API routes, runtime), Routing (next/router, next/navigation, next/link)

Link to the code that reproduces this issue or a replay of the bug

https://github.com/matthewcc/middlware-test

To Reproduce

Clone the attached repo, or

  • make a new project with create-nextjs-app.
  • Add skipMiddlewareUrlNormalize: true to next.config.js
  • add support for locales in the navigation and in next.config.js
  • add middleware.js and log out req.nextUrl.locale

After cloning the attached repo or following the steps above, when doing client-side routing (NextLink or browser buttons) the value logged out for req.nextUrl.locale is always the default (in this case, "en-US").

This is using the classic Next.js setup, I do not know if the behavior is the same for app router or not.

Describe the Bug

If skipMiddlewareUrlNormalize: true is in next.config.js, then during client-side routing middleware.js's req.nextUrl.locale is always the default value even if the page is on another locale,

The string in req.nextUrl.pathname does contain the correct locale during client side routing, if skipMiddlewareUrlNormalize is set to true.

Expected Behavior

req.nextUrl.locale in middleware.js should always be accurate.

Which browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

Vercel

@matthewcc matthewcc added the bug Issue was opened via the bug report template. label Aug 7, 2023
@github-actions github-actions bot added Runtime Related to Node.js or Edge Runtime with Next.js. Navigation Related to Next.js linking (e.g., <Link>) and navigation. labels Aug 7, 2023
@kodiakhq kodiakhq bot closed this as completed in #54357 Aug 21, 2023
kodiakhq bot pushed a commit that referenced this issue Aug 21, 2023
This ensures we properly populate locale information with `skipMiddlewareUrlNormalize` enabled as we shouldn't provide incorrect values even if we are skipping normalizing. 

Fixes: #53646
@github-actions
Copy link
Contributor

github-actions bot commented Sep 5, 2023

This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot added the locked label Sep 5, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 5, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template. locked Navigation Related to Next.js linking (e.g., <Link>) and navigation. Runtime Related to Node.js or Edge Runtime with Next.js.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant