/_next/data is permanently redirected if a middleware is present and trailingSlash is enabled
See original GitHub issueVerify canary release
- I verified that the issue exists in the latest Next.js canary release
Provide environment information
Operating System:
Platform: win32
Arch: x64
Version: Windows 10 Pro
Binaries:
Node: 16.10.0
npm: N/A
Yarn: N/A
pnpm: N/A
Relevant packages:
next: 12.2.1-canary.1
eslint-config-next: 12.2.0
react: 18.2.0
react-dom: 18.2.0
What browser are you using? (if relevant)
Irrelevant
How are you deploying your application? (if relevant)
Irrelevant
Describe the Bug
We have an app that uses the next@12.2
middleware features and at the same time has trailingSlash
set to true
in next.config.js
.
When the app is opened for the first time in a browser tab it works correctly. However, navigating to any page with getServerSideProps
via the Link
component results in the corresponding /_next/data
request getting a 308 response and therefore in the server-side data not reaching the client-side.
The issue reproduces if both, a middleware is present and trailingSlash
is set to true
. It doesn’t matter what the middleware
does (it can just return NextResponse.next()
), it just needs to be present.
Expected Behavior
The /_next/data
request gets a 200 OK response containing the data from the server-side.
Link to reproduction
https://codesandbox.io/s/trailing-slash-middleware-issue-rhvbbx
To Reproduce
- Star the app using
yarn dev
- Click on the “Go to dummy” link
Issue Analytics
- State:
- Created a year ago
- Reactions:10
- Comments:6 (1 by maintainers)
Top GitHub Comments
We’re also experiencing the same issue when upgrading from 12.1.6 -> 12.2.
This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.