-
Notifications
You must be signed in to change notification settings - Fork 89
fix: correctly handle matchers with lookaheads and i18n #1693
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
Conversation
✅ Deploy Preview for netlify-plugin-nextjs-export-demo ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
✅ Deploy Preview for next-plugin-edge-middleware ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
✅ Deploy Preview for netlify-plugin-nextjs-static-root-demo ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
✅ Deploy Preview for netlify-plugin-nextjs-nx-monorepo-demo ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
✅ Deploy Preview for netlify-plugin-nextjs-next-auth-demo ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
✅ Deploy Preview for next-plugin-canary ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
✅ Deploy Preview for next-plugin-rsc-demo ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
✅ Deploy Preview for netlify-plugin-nextjs-demo ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
✅ Deploy Preview for next-plugin-rsc-demo ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
✅ Deploy Preview for next-plugin-canary ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
✅ Deploy Preview for next-i18next-demo ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
✅ Deploy Preview for nextjs-plugin-custom-routes-demo ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
✅ Deploy Preview for netlify-plugin-nextjs-demo ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
✅ Deploy Preview for next-i18next-demo ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
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.
LGTM!
Summary
Currently we translate the Next.js middleware matcher regex into a regex used to target the edge function. We double-check when the edge funciton runs, because there are addiitonal conditions that can be set in matchers that can't be expressed in the path regex. However the Next.js and Netlify Edge Function regexes are not fully compatible, because for performance reasons the Go regexp library (used in the Netlify proxy) doesn't support lookaheads like JavaScript does, and the Next.js docs now suggest using these.
This PR parses the matcher regexes, and strips any lookahead clauses before writing them to the Netlify manifest. Loosening them in this way doesn't prevent them from working, because it retains the lookaheads in the matchers used in the edge functions themselves, so the condition is still enfored at that point.
Additionally, if a site uses i18n, the generated regex was not matching the default locale. This is because Next.js checks the path after it has been normalized and the default locale interpolated. However Netlify runs the match before it it normalised. This PR loosens that regex by making the locale slug optional, meaning it matches the default locale with no slug included.
Test plan
x-modified-edge
header is not set in the response. Load this page and see that it is set.Relevant links (GitHub issues, Notion docs, etc.) or a picture of cute animal
Standard checks:
🧪 Once merged, make sure to update the version if needed and that it was published correctly.