Skip to content

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

Merged
merged 8 commits into from
Jan 16, 2023

Conversation

orinokai
Copy link
Contributor

@orinokai orinokai commented Jan 5, 2023

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

@orinokai orinokai self-assigned this Jan 5, 2023
@orinokai orinokai requested a review from a team January 5, 2023 15:27
@netlify
Copy link

netlify bot commented Jan 5, 2023

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

Name Link
🔨 Latest commit 8f98fa9
🔍 Latest deploy log https://app.netlify.com/sites/netlify-plugin-nextjs-nx-monorepo-demo/deploys/63c52c8f75aefc00091e2ee3
😎 Deploy Preview https://deploy-preview-1867--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 5, 2023

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

Name Link
🔨 Latest commit 8f98fa9
🔍 Latest deploy log https://app.netlify.com/sites/netlify-plugin-nextjs-static-root-demo/deploys/63c52c8f58e41600092ee37c
😎 Deploy Preview https://deploy-preview-1867--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.

@netlify
Copy link

netlify bot commented Jan 5, 2023

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

Name Link
🔨 Latest commit 8f98fa9
🔍 Latest deploy log https://app.netlify.com/sites/netlify-plugin-nextjs-next-auth-demo/deploys/63c52c9058e41600092ee381
😎 Deploy Preview https://deploy-preview-1867--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.

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

netlify bot commented Jan 5, 2023

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

Name Link
🔨 Latest commit 8f98fa9
🔍 Latest deploy log https://app.netlify.com/sites/netlify-plugin-nextjs-export-demo/deploys/63c52c90e72c3300097a1f24
😎 Deploy Preview https://deploy-preview-1867--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 5, 2023

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

Name Link
🔨 Latest commit 8f98fa9
🔍 Latest deploy log https://app.netlify.com/sites/netlify-plugin-nextjs-demo/deploys/63c52c9075aefc00091e2eed
😎 Deploy Preview https://deploy-preview-1867--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.

@netlify
Copy link

netlify bot commented Jan 5, 2023

Deploy Preview for next-i18next-demo ready!

Name Link
🔨 Latest commit 8f98fa9
🔍 Latest deploy log https://app.netlify.com/sites/next-i18next-demo/deploys/63c52c909bb33d00098a1c17
😎 Deploy Preview https://deploy-preview-1867--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 5, 2023

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

Name Link
🔨 Latest commit 8f98fa9
🔍 Latest deploy log https://app.netlify.com/sites/nextjs-plugin-custom-routes-demo/deploys/63c52c90f4ad1000093274ee
😎 Deploy Preview https://deploy-preview-1867--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 5, 2023

Deploy Preview for next-plugin-canary ready!

Name Link
🔨 Latest commit 8f98fa9
🔍 Latest deploy log https://app.netlify.com/sites/next-plugin-canary/deploys/63c52c9047d2a50008b94902
😎 Deploy Preview https://deploy-preview-1867--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 5, 2023

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

Name Link
🔨 Latest commit 8f98fa9
🔍 Latest deploy log https://app.netlify.com/sites/next-plugin-edge-middleware/deploys/63c52c9075aefc00091e2ee8
😎 Deploy Preview https://deploy-preview-1867--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.

@@ -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}`)) {
Copy link
Contributor

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

Copy link
Contributor Author

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

Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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

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.

🎉

@kodiakhq kodiakhq bot merged commit 14ad486 into main Jan 16, 2023
@kodiakhq kodiakhq bot deleted the rs/isr-i18n-homepage-revisit branch January 16, 2023 12:44
@orinokai orinokai mentioned this pull request Jan 24, 2023
2 tasks
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
Development

Successfully merging this pull request may close these issues.

2 participants