vercel / vercel/next.js

Redirects not working correctly together with middleware

Open
#56,154 6 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug Linking and Navigating not stale Runtime
Dominant language
JavaScript
Stars
142k
Forks
32.5k
Avg merge
2d 13h
Merged PRs (30d)
334

Description

Link to the code that reproduces this issue

https://github.com/serGlazkov/next-redirect-middleware-bug

To Reproduce
  • Set up redirects in the next.config.js file.
  • Confirm that the redirects are working as expected.
  • Add a middleware.ts file to the project.
  • Click a link that should trigger a redirect.
Current vs. Expected behavior

Actual Result
The user is redirected to the page, but it's rendered without any properties.

Expected Result
The user should be redirected to the intended page with all the expected properties. (Should work the same as without middleware)

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.6.0: Wed Jul  5 22:21:56 PDT 2023; root:xnu-8796.141.3~6/RELEASE_X86_64
Binaries:
  Node: 18.14.2
  npm: 9.5.0
  Yarn: 1.22.19
  pnpm: N/A
Relevant Packages:
  next: 13.5.3
  eslint-config-next: N/A
  react: 18.2.0
  react-dom: 18.2.0
  typescript: 5.2.2
Next.js Config:
  output: N/A
Which area(s) are affected? (Select all that apply)

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

Additional context

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked reproduction repository, then compare the redirect behavior with and without middleware.ts using the redirects configured in next.config.js. Verify that the redirected page receives and renders all expected properties, matching behavior when middleware is absent.

Written by the indexing model from the issue text.

Assessment

Tech stack
nextjs, react, typescript
Domain
backend, frontend, web-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.