Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[next] Update data route handling for i18n and static routes #8304

Merged
merged 2 commits into from
Aug 3, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 21 additions & 6 deletions packages/next/src/server-build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1384,6 +1384,15 @@ export async function serverBuild({
// re-build /_next/data URL after resolving
...denormalizeNextDataRoute(),

...(isNextDataServerResolving
? dataRoutes.filter(route => {
// filter to only static data routes as dynamic routes will be handled
// below
const { pathname } = new URL(route.dest || '/', 'http://n');
return !isDynamicRoute(pathname.replace(/\.json$/, ''));
})
: []),

// /_next/data routes for getServerProps/getStaticProps pages
...(isNextDataServerResolving
? // when resolving data routes for middleware we need to include
Expand All @@ -1401,16 +1410,22 @@ export async function serverBuild({
);

const { pathname } = new URL(route.dest || '/', 'http://n');
let prerenderPathname = pathname;
let isPrerender = !!prerenders[path.join('./', pathname)];

if (routesManifest.i18n) {
prerenderPathname = pathname.replace(
/^\/\$nextLocale/,
`/${routesManifest.i18n.defaultLocale}`
);
for (const locale of routesManifest.i18n?.locales || []) {
const prerenderPathname = pathname.replace(
/^\/\$nextLocale/,
`/${locale}`
);
if (prerenders[path.join('./', prerenderPathname)]) {
isPrerender = true;
break;
}
}
}

if (prerenders[path.join('./', prerenderPathname)]) {
if (isPrerender) {
route.dest = `/_next/data/${buildId}${pathname}.json`;
}
return route;
Expand Down
7 changes: 7 additions & 0 deletions packages/next/test/fixtures/00-middleware-i18n/vercel.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@
}
],
"probes": [
{
"path": "/_next/data/testing-build-id/en/about.json",
"status": 200,
"responseHeaders": {
"x-matched-path": "/en/about"
}
},
{
"path": "/_next/data/testing-build-id/en/dynamic/static.json",
"status": 200,
Expand Down
7 changes: 7 additions & 0 deletions packages/next/test/fixtures/00-middleware/vercel.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@
}
],
"probes": [
{
"path": "/_next/data/testing-build-id/about.json",
"status": 200,
"responseHeaders": {
"x-matched-path": "/about"
}
},
{
"path": "/_next/data/testing-build-id/dynamic/static.json",
"status": 200,
Expand Down