-
Notifications
You must be signed in to change notification settings - Fork 86
fix: preserve original path after middleware rewrite #2177
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
fix: preserve original path after middleware rewrite #2177
Conversation
✅ Deploy Preview for netlify-plugin-nextjs-nx-monorepo-demo ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
✅ Deploy Preview for netlify-plugin-nextjs-static-root-demo ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
✅ Deploy Preview for netlify-plugin-nextjs-next-auth-demo ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
✅ Deploy Preview for netlify-plugin-nextjs-demo ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
✅ Deploy Preview for nextjs-plugin-custom-routes-demo ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
✅ Deploy Preview for next-plugin-canary ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
✅ Deploy Preview for next-plugin-edge-middleware ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
✅ Deploy Preview for next-i18next-demo ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
✅ Deploy Preview for netlify-plugin-nextjs-export-demo ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
8e86daa
to
9de97eb
Compare
9de97eb
to
2b5b6f8
Compare
if (!parsedUrl && typeof req?.headers?.['x-middleware-rewrite'] === 'string') { | ||
parsedUrl = parse(req.headers['x-middleware-rewrite'], true) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Next does same parsing in https://github.com/vercel/next.js/blob/7dfa56c7141ae2556af0d7fd837e0af686d8fa55/packages/next/src/server/base-server.ts#L662-L665 and later on does a lot of checking on it and potentially messing with it.
Passing parsedUrl
along the request handler route allows some control
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch here, thanks @pieh. I'd been wondering what the significance was of the parsedUrl
and why it was always empty.
Description
This looks to address issue with
locale
not being set correctly (or at least not in the same way asnext build
+next start
behaves) when there is rewrite happening in middleware which in turn cause weirdness with client-side routing.Documentation
Tests
Added a test case to cypress tests
Relevant links (GitHub issues, etc.) or a picture of cute animal