Skip to content

fix: data route rewrite for i18n root route #2002

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
Mar 22, 2023
Merged

Conversation

orinokai
Copy link
Contributor

Summary

The runtime creates rewrites that route ISR pages (and their data routes) to the ODB handler. However, the runtime was not correctly handling data route rewrites on ISR index pages for i18n sites.

On non-i18n sites, the index data route has the 'index' suffix, e.g. /_next/data/build-id/index.json
On i18n sites, the index data route uses the locale instead, e.g. /_next/data/build-id/en.json, but the runtime was still using the 'index' suffix. This PR fixes that.

Test plan

  1. Visit the Deploy Preview and navigate away from the home page
  2. Open the network inspector and mouseover any link back to the homepage
  3. Observe a request is made to /_next/data/build-id/en.json instead of /_next/data/build-id/index.json
  4. Observe the response has an x-nf-render-mode: odb ttl=60 header and not an x-nf-render-mode: ssr header

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

Closes netlify/pod-ecosystem-frameworks#429

danger cat

@orinokai orinokai requested a review from a team March 21, 2023 17:48
@netlify
Copy link

netlify bot commented Mar 21, 2023

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

Name Link
🔨 Latest commit f2c56bb
🔍 Latest deploy log https://app.netlify.com/sites/next-plugin-edge-middleware/deploys/641ac0ac306f690008a30c6a
😎 Deploy Preview https://deploy-preview-2002--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.

@netlify
Copy link

netlify bot commented Mar 21, 2023

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

Name Link
🔨 Latest commit f2c56bb
🔍 Latest deploy log https://app.netlify.com/sites/netlify-plugin-nextjs-static-root-demo/deploys/641ac0aced8c150008d17c92
😎 Deploy Preview https://deploy-preview-2002--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.

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

netlify bot commented Mar 21, 2023

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

Name Link
🔨 Latest commit f2c56bb
🔍 Latest deploy log https://app.netlify.com/sites/netlify-plugin-nextjs-demo/deploys/641ac0ac5e7bca00081882c7
😎 Deploy Preview https://deploy-preview-2002--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 Mar 21, 2023

Deploy Preview for next-plugin-canary ready!

Name Link
🔨 Latest commit f2c56bb
🔍 Latest deploy log https://app.netlify.com/sites/next-plugin-canary/deploys/641ac0ac39a4e10008778920
😎 Deploy Preview https://deploy-preview-2002--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 Mar 21, 2023

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

Name Link
🔨 Latest commit f2c56bb
🔍 Latest deploy log https://app.netlify.com/sites/nextjs-plugin-custom-routes-demo/deploys/641ac0ac2a07b60008e957ee
😎 Deploy Preview https://deploy-preview-2002--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 Mar 21, 2023

Deploy Preview for next-i18next-demo ready!

Name Link
🔨 Latest commit f2c56bb
🔍 Latest deploy log https://app.netlify.com/sites/next-i18next-demo/deploys/641ac0ad0cc7c40008a0c12b
😎 Deploy Preview https://deploy-preview-2002--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 Mar 21, 2023

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

Name Link
🔨 Latest commit f2c56bb
🔍 Latest deploy log https://app.netlify.com/sites/netlify-plugin-nextjs-export-demo/deploys/641ac0ace460cb000807f918
😎 Deploy Preview https://deploy-preview-2002--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 Mar 21, 2023

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

Name Link
🔨 Latest commit f2c56bb
🔍 Latest deploy log https://app.netlify.com/sites/netlify-plugin-nextjs-nx-monorepo-demo/deploys/641ac0ac5e7bca00081882be
😎 Deploy Preview https://deploy-preview-2002--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 Mar 21, 2023

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

Name Link
🔨 Latest commit f2c56bb
🔍 Latest deploy log https://app.netlify.com/sites/netlify-plugin-nextjs-next-auth-demo/deploys/641ac0ae47005b0008be3ea7
😎 Deploy Preview https://deploy-preview-2002--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.

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.

Tested this and it works as expected.

CleanShot 2023-03-21 at 14 28 47

@@ -74,7 +74,7 @@ export const generateNetlifyRoutes = ({
}) => [...(withData ? toNetlifyRoute(dataRoute) : []), ...toNetlifyRoute(route)]

export const routeToDataRoute = (route: string, buildId: string, locale?: string) =>
`/_next/data/${buildId}${locale ? `/${locale}` : ''}${route === '/' ? '/index' : route}.json`
`/_next/data/${buildId}${locale ? `/${locale}` : ''}${route === '/' ? (locale ? '' : '/index') : route}.json`

Choose a reason for hiding this comment

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

[dust] I get what's happening here but it's hard to grok with the multiple/nested ternaries.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, I agree. i did try to refactor this but ended up in a knot because it really needs to broken up into 2 different functions - one for i18n and one for non-i18n - but it's difficult because of the various places it gets called. hopefully all this will be replaced soon with edge routing and/or improved CDN redirects

@orinokai orinokai self-assigned this Mar 22, 2023
@kodiakhq kodiakhq bot merged commit 4f6cdd9 into main Mar 22, 2023
@kodiakhq kodiakhq bot deleted the rs/isr-i18n-root-route branch March 22, 2023 10:59
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