question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

/_next/data is permanently redirected if a middleware is present and trailingSlash is enabled

See original GitHub issue

Verify 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

  1. Star the app using yarn dev
  2. Click on the “Go to dummy” link

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:10
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
kodkrokencommented, Jun 30, 2022

We’re also experiencing the same issue when upgrading from 12.1.6 -> 12.2.

0reactions
github-actions[bot]commented, Aug 4, 2022

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Next.js Redirect from / to another page - Stack Overflow
Now you can do redirects using middleware, create a _middleware.js ... server side rendering: we render the page if allowed, HTTP redirect ......
Read more >
Trailing Slash Middleware | Echo - High performance ...
Example above will add a trailing slash to the request URI and redirect with 301 - StatusMovedPermanently . Configuration. TrailingSlashConfig struct { // ......
Read more >
Rewrites - next.config.js
Rewrites act as a URL proxy and mask the destination path, making it appear the user hasn't changed their location on the site....
Read more >
Release 2.0.2 - aiohttp Documentation
Compression has to be enabled explicitly with the compress parameter. If compression is enabled, adding a content-.
Read more >
Project Config with vercel.json
Note: If you are using Next.js and running vercel dev , you will get a 404 ... permanent : A boolean to toggle...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found