-
Notifications
You must be signed in to change notification settings - Fork 86
fix: correctly rewrite default locale ISR homepage to ODB handler #1867
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-nx-monorepo-demo 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-next-auth-demo ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
✅ 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 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. |
✅ 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 next-plugin-canary 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. |
@@ -143,8 +143,8 @@ const generateStaticIsrRewrites = ({ | |||
return | |||
} | |||
// The default locale is served from the root, not the localised path | |||
if (i18n?.defaultLocale && route.startsWith(`/${i18n.defaultLocale}/`)) { | |||
route = route.slice(i18n.defaultLocale.length + 1) | |||
if (i18n?.defaultLocale && route.startsWith(`/${i18n.defaultLocale}`)) { |
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.
Wouldn't this cause false positives? e.g. if there's a site with en
default locale, but also a route called /entry
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.
hi @ascorbic, it doesn't appear to - both this and the previous condition would match /en/entry
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.
Right, but would this match /entry
and turn it into try
?
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.
ah, i see what you mean - no it won't because with i18n the routes are always matched with the locale prefix, so for the route /entry
it will be matched against /en/entry
and /fr/entry
, etc.
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.
Aah, gotcha. Unfortunately I just checked the manifest for the default demo in my ISR branch and it looks like appDir pages don't have the prefix.
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.
great catch, i'd forgotten that appDir doesn't implement i18n - i've made the condition more specific, which is a good thing anyway 7cef5fe
…lify-plugin-nextjs into rs/isr-i18n-homepage-revisit
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.
🎉
Summary
ISR homepages with i18n were not correctly matched as static routes and were being served as SSR pages because no rewrite was created. This was because the matcher only worked for URLs with subpaths.
This PR updates the logic to match URLs prefixed with the default locale, with or without a subpath, and ensures that, when slicing off the locale, an index page at the root defaults to '/'.
Test plan
Snapshots have been updated with the new redirects. Tests should pass as before.
Relevant links (GitHub issues, Notion docs, etc.) or a picture of cute animal
Fixes netlify/pod-ecosystem-frameworks#233