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

Issue with dynamic segment in Middleware and NextConfig using trailingSlash: true #71197

Open
1 task done
kutan138 opened this issue Oct 12, 2024 · 0 comments
Open
1 task done
Labels
examples Issue/PR related to examples

Comments

@kutan138
Copy link

kutan138 commented Oct 12, 2024

Verify canary release

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

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 23.0.0: Fri Sep 15 14:41:34 PDT 2023; root:xnu-10002.1.13~1/RELEASE_ARM64_T8103
  Available memory (MB): 8192
  Available CPU cores: 8
Binaries:
  Node: 20.12.2
  npm: 10.5.0
  Yarn: 1.22.22
  pnpm: N/A
Relevant Packages:
  next: 14.2.15 // Latest available version is detected (14.2.15).
  eslint-config-next: 14.2.15
  react: 18.3.1
  react-dom: 18.3.1
  typescript: 5.6.3
Next.js Config:
  output: N/A

Which example does this report relate to?

Custom Next.js configuration using middleware with trailingSlash: true and generateBuildId

What browser are you using? (if relevant)

Browser: Chrome 117.0.5938.132

How are you deploying your application? (if relevant)

next start (local development)

Describe the Bug

When using Next.js with the following configuration:
const nextConfig = { trailingSlash: true, generateBuildId: () => "release/v1", };
The initial page load at http://localhost:3000/product/1234/?Page=2 (with seriesCode being part of the dynamic route /product/[seriesCode]/?Page=2) works as expected, with seriesCode correctly set to 1234.

However, when clicking a link that navigates to another product page such as http://localhost:3000/product/5678/?Page=2 from within the current page, the seriesCode is not passed or recognized, and only the Page=2 parameter is retained.

Expected Behavior

Upon navigating to a new product page with the format /product/[seriesCode]/?Page=[number], the seriesCode should be updated correctly with the new value. In this case, seriesCode should be 5678 when navigating to http://localhost:3000/product/5678/?Page=2.

To Reproduce

My reproduce on github link:
https://github.com/kutan138/test-middle
image

Copy code

  1. Set up Next.js with the following configuration:
    next.config.js

const nextConfig = { trailingSlash: true, generateBuildId: () => "release/v1", };

  1. Create a middleware
image
  1. Access the URL http://localhost:3000/product/1234/?Page=2. You should see that seriesCode=1234.

  2. Now click a link or navigate programmatically to http://localhost:3000/product/5678/?Page=2. The seriesCode should update to 5678, but it is undefined with console log

Screenshots

First render (no issue):
image

After clicking link (issue occurs):
image

@kutan138 kutan138 added the examples Issue/PR related to examples label Oct 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
examples Issue/PR related to examples
Projects
None yet
Development

No branches or pull requests

1 participant