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

Inconsistent context.resolvedUrl behavior in getServerSideProps after middleware rewrite #74746

Open
guinnod opened this issue Jan 10, 2025 · 0 comments
Labels
Middleware Related to Next.js Middleware. Pages Router Related to Pages Router.

Comments

@guinnod
Copy link

guinnod commented Jan 10, 2025

Link to the code that reproduces this issue

https://github.com/guinnod/next-js-issue

To Reproduce

  1. Start the application (npm run build & npm run start)
  2. Go to the page /old?param=oldValue

Current vs. Expected behavior

When accessing /old?param=oldValue
Expected resolvedUrl: /new?param=newValue
Actual resolvedUrl: /new?param=oldValue

Expected Behavior

After middleware rewrites both the pathname and query parameters, context.resolvedUrl in getServerSideProps should reflect the complete rewritten URL, including both the new pathname and the new query parameters.

Actual Behavior

While the middleware successfully rewrites the URL and the application correctly routes to the new path, context.resolvedUrl in getServerSideProps shows a mixed state:

  • Pathname in resolvedUrl is correctly updated to the rewritten value
  • Query parameters in resolvedUrl remain as the original values before rewrite

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 23.5.0: Wed May  1 20:12:58 PDT 2024; root:xnu-10063.121.3~5/RELEASE_ARM64_T6000
  Available memory (MB): 16384
  Available CPU cores: 10
Binaries:
  Node: 20.14.0
  npm: 10.7.0
  Yarn: 1.22.22
  pnpm: N/A
Relevant Packages:
  next: 15.2.0-canary.3 // Latest available version is detected (15.2.0-canary.3).
  eslint-config-next: N/A
  react: 19.0.0
  react-dom: 19.0.0
  typescript: 5.7.3
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

Middleware, Pages Router

Which stage(s) are affected? (Select all that apply)

next dev (local), next start (local), Vercel (Deployed)

Additional context

The bug exhibits inconsistent behavior across different projects and environments:

  1. Original Production Project (Next.js 14.1.2):
  • Deployed on Vercel: Bug present with incorrect pathname in resolvedUrl but correct query parameters
  • Local development: Bug not reproducible even with identical Vercel environment variables
  • Local production build (next build && next start): Bug not reproducible
  • With locales in pathname (e.g., / and /en): Bug does not manifest
  • Vercel deployment logs confirm the bug's existence in production
  1. Reproduction Project (created with npx create-next-app -e reproduction-template):
  • Shows opposite behavior: pathname is correct but query parameters are wrong
  • Demonstrates that the bug's behavior is not consistent even when attempting to reproduce it

This inconsistency in behavior makes the bug particularly concerning:

  • The same codebase behaves differently between Vercel deployment and local environment
  • Different projects exhibit opposite symptoms (either pathname or query parameters being incorrect)
  • The presence of locale routing appears to affect the bug's manifestation
  • The bug's behavior is not sustainable across different setups and configurations

This variation in behavior suggests a deeper underlying issue with how URL rewrites are handled in different contexts and configurations within Next.js.

@guinnod guinnod added the bug Issue was opened via the bug report template. label Jan 10, 2025
@github-actions github-actions bot added Middleware Related to Next.js Middleware. Pages Router Related to Pages Router. labels Jan 10, 2025
@samcx samcx removed the bug Issue was opened via the bug report template. label Jan 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Middleware Related to Next.js Middleware. Pages Router Related to Pages Router.
Projects
None yet
Development

No branches or pull requests

2 participants