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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/runtime/src/helpers/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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


// Default locale is served from root, not localized
export const localizeRoute = (route: string, locale: string, defaultLocale: string) =>
Expand Down
12 changes: 6 additions & 6 deletions test/__snapshots__/index.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,12 @@ Array [
"status": 200,
"to": "/.netlify/builders/_ipx",
},
Object {
"force": true,
"from": "/_next/data/build-id/en.json",
"status": 200,
"to": "/.netlify/builders/___netlify-odb-handler",
},
Object {
"force": false,
"from": "/_next/data/build-id/en/500.json",
Expand Down Expand Up @@ -844,12 +850,6 @@ Array [
"status": 200,
"to": "/.netlify/functions/___netlify-handler",
},
Object {
"force": true,
"from": "/_next/data/build-id/en/index.json",
"status": 200,
"to": "/.netlify/builders/___netlify-odb-handler",
},
Object {
"force": false,
"from": "/_next/data/build-id/en/layouts.json",
Expand Down