Skip to content

fix: custom headers for root route when using i18n #1893

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

Merged
merged 3 commits into from
Jan 24, 2023

Conversation

orinokai
Copy link
Contributor

Summary

When generating custom headers, the Runtime reads Next.js config rules and translates them into the required format for the TOML file. Part of that translation involves converting the :nextInternalLocale placeholder to a single localised rule for each locale.

However, the condition for the conversion was not being matched when one or more of the locales included a special regex character because Next.js escapes the locale names before writing the routes-manifest.json file and we were not doing the same before matching.

This PR lifts the escapeStringRegexp function from Next.js and uses it to escape the locales before creating the path, in the same way that Next.js does.

Note: in this case the problematic character was a -, which isn't a special character in regex, but one that Next.js escapes regardless.

Test plan

  1. Tests have been amended to catch this condition.

Relevant links (GitHub issues, Notion docs, etc.) or a picture of cute animal

Fixes #1883

@orinokai orinokai requested a review from a team January 19, 2023 11:56
@netlify
Copy link

netlify bot commented Jan 19, 2023

Deploy Preview for netlify-plugin-nextjs-export-demo ready!

Name Link
🔨 Latest commit 21517a5
🔍 Latest deploy log https://app.netlify.com/sites/netlify-plugin-nextjs-export-demo/deploys/63cfbbc6ee8afa0009ec1df5
😎 Deploy Preview https://deploy-preview-1893--netlify-plugin-nextjs-export-demo.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@netlify
Copy link

netlify bot commented Jan 19, 2023

Deploy Preview for netlify-plugin-nextjs-nx-monorepo-demo ready!

Name Link
🔨 Latest commit 21517a5
🔍 Latest deploy log https://app.netlify.com/sites/netlify-plugin-nextjs-nx-monorepo-demo/deploys/63cfbbc663575500096a9afa
😎 Deploy Preview https://deploy-preview-1893--netlify-plugin-nextjs-nx-monorepo-demo.netlify.app/
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@netlify
Copy link

netlify bot commented Jan 19, 2023

Deploy Preview for netlify-plugin-nextjs-static-root-demo ready!

Name Link
🔨 Latest commit 21517a5
🔍 Latest deploy log https://app.netlify.com/sites/netlify-plugin-nextjs-static-root-demo/deploys/63cfbbc63254aa000cc377e8
😎 Deploy Preview https://deploy-preview-1893--netlify-plugin-nextjs-static-root-demo.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@orinokai orinokai self-assigned this Jan 19, 2023
@netlify
Copy link

netlify bot commented Jan 19, 2023

Deploy Preview for next-plugin-edge-middleware ready!

Name Link
🔨 Latest commit 21517a5
🔍 Latest deploy log https://app.netlify.com/sites/next-plugin-edge-middleware/deploys/63cfbbc6e80b320008509924
😎 Deploy Preview https://deploy-preview-1893--next-plugin-edge-middleware.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@github-actions github-actions bot added the type: bug code to address defects in shipped code label Jan 19, 2023
@netlify
Copy link

netlify bot commented Jan 19, 2023

Deploy Preview for next-plugin-canary ready!

Name Link
🔨 Latest commit 21517a5
🔍 Latest deploy log https://app.netlify.com/sites/next-plugin-canary/deploys/63cfbbc6ee8afa0009ec1dfa
😎 Deploy Preview https://deploy-preview-1893--next-plugin-canary.netlify.app/
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@netlify
Copy link

netlify bot commented Jan 19, 2023

Deploy Preview for netlify-plugin-nextjs-next-auth-demo ready!

Name Link
🔨 Latest commit 21517a5
🔍 Latest deploy log https://app.netlify.com/sites/netlify-plugin-nextjs-next-auth-demo/deploys/63cfbbc63254aa000cc377ed
😎 Deploy Preview https://deploy-preview-1893--netlify-plugin-nextjs-next-auth-demo.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@netlify
Copy link

netlify bot commented Jan 19, 2023

Deploy Preview for nextjs-plugin-custom-routes-demo ready!

Name Link
🔨 Latest commit 21517a5
🔍 Latest deploy log https://app.netlify.com/sites/nextjs-plugin-custom-routes-demo/deploys/63cfbbc69ec9f90008391c82
😎 Deploy Preview https://deploy-preview-1893--nextjs-plugin-custom-routes-demo.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@netlify
Copy link

netlify bot commented Jan 19, 2023

Deploy Preview for next-i18next-demo ready!

Name Link
🔨 Latest commit 21517a5
🔍 Latest deploy log https://app.netlify.com/sites/next-i18next-demo/deploys/63cfbbc6fa7eef0008c9489d
😎 Deploy Preview https://deploy-preview-1893--next-i18next-demo.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@netlify
Copy link

netlify bot commented Jan 19, 2023

Deploy Preview for netlify-plugin-nextjs-demo ready!

Name Link
🔨 Latest commit 21517a5
🔍 Latest deploy log https://app.netlify.com/sites/netlify-plugin-nextjs-demo/deploys/63cfbbc611e1a70008ddb0e2
😎 Deploy Preview https://deploy-preview-1893--netlify-plugin-nextjs-demo.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

Copy link
Contributor

@ascorbic ascorbic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great. For future reference, we also have escapeStringRegexp available in next-utils for edge functions

Copy link

@nickytonline nickytonline left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix @orinokai! 🚢

@kodiakhq kodiakhq bot merged commit 9be3382 into main Jan 24, 2023
@kodiakhq kodiakhq bot deleted the rs/i18n-custom-headers branch January 24, 2023 11:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge type: bug code to address defects in shipped code
Projects
None yet
3 participants