Inconsistent context.resolvedUrl
behavior in getServerSideProps
after middleware rewrite
#74746
Labels
context.resolvedUrl
behavior in getServerSideProps
after middleware rewrite
#74746
Link to the code that reproduces this issue
https://github.com/guinnod/next-js-issue
To Reproduce
(npm run build & npm run start)
/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
ingetServerSideProps
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:
resolvedUrl
is correctly updated to the rewritten valueresolvedUrl
remain as the original values before rewriteProvide 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:
next build && next start
): Bug not reproduciblee.g., / and /en
): Bug does not manifestnpx create-next-app -e reproduction-template
):This inconsistency in behavior makes the bug particularly concerning:
This variation in behavior suggests a deeper underlying issue with how URL rewrites are handled in different contexts and configurations within Next.js.
The text was updated successfully, but these errors were encountered: