Unverified Commit 0db78041 authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Fix edge index page _next/data route (#90611)

Fixes failing assertion with turbopack

Verified against turbopack + adapter deploy test locally
<img width="2076" height="1336" alt="CleanShot 2026-02-26 at 13 25
30@2x"
src="https://github.com/user-attachments/assets/a8c66314-8163-4371-b02a-dc7146989425"
/>


x-ref:
https://github.com/vercel/next.js/pull/90600#issuecomment-3968044160
parent b6d47641
...@@ -677,6 +677,11 @@ export async function handleBuildComplete({ ...@@ -677,6 +677,11 @@ export async function handleBuildComplete({
} }
const route = page.page.replace(/^(app|pages)\//, '') const route = page.page.replace(/^(app|pages)\//, '')
const pathname = isAppPrefix
? normalizeAppPath(route)
: route === '/index'
? '/'
: route
const output: Omit<AdapterOutput[typeof type], 'type'> & { const output: Omit<AdapterOutput[typeof type], 'type'> & {
type: any type: any
...@@ -685,7 +690,7 @@ export async function handleBuildComplete({ ...@@ -685,7 +690,7 @@ export async function handleBuildComplete({
id: page.name, id: page.name,
runtime: 'edge', runtime: 'edge',
sourcePage: route, sourcePage: route,
pathname: isAppPrefix ? normalizeAppPath(route) : route, pathname,
filePath: path.join( filePath: path.join(
distDir, distDir,
page.files.find( page.files.find(
...@@ -766,16 +771,15 @@ export async function handleBuildComplete({ ...@@ -766,16 +771,15 @@ export async function handleBuildComplete({
pathname: rscPathname, pathname: rscPathname,
id: page.name + '.rsc', id: page.name + '.rsc',
}) })
} else if (serverPropsPages.has(route === '/index' ? '/' : route)) { } else if (serverPropsPages.has(pathname)) {
const nextDataPath = path.posix.join( const nextDataPath = path.posix.join(
'/_next/data/', '/_next/data/',
buildId, buildId,
normalizePagePath(output.pathname) + '.json' normalizePagePath(pathname) + '.json'
) )
outputs.appPages.push({ outputs.pages.push({
...output, ...output,
pathname: nextDataPath, pathname: nextDataPath,
id: page.name,
}) })
} }
} }
......
module.exports = {
onBuildComplete({ outputs }) {
const pagesDataPathnames = outputs.pages
.map((item) => item.pathname)
.filter((item) => item.startsWith('/_next/data/'))
const appPagesDataPathnames = outputs.appPages
.map((item) => item.pathname)
.filter((item) => item.startsWith('/_next/data/'))
const hasIndexData = pagesDataPathnames.some((item) =>
/^\/_next\/data\/[^/]+\/index\.json$/.test(item)
)
const hasDynamicData = pagesDataPathnames.some((item) =>
/^\/_next\/data\/[^/]+\/\[id\]\.json$/.test(item)
)
const hasDoubleIndexData = [
...pagesDataPathnames,
...appPagesDataPathnames,
].some((item) => /^\/_next\/data\/[^/]+\/index\/index\.json$/.test(item))
if (!hasIndexData || !hasDynamicData || hasDoubleIndexData) {
throw new Error(
[
'Unexpected edge pages data output from adapter build:',
`pagesDataPathnames=${JSON.stringify(pagesDataPathnames)}`,
`appPagesDataPathnames=${JSON.stringify(appPagesDataPathnames)}`,
`hasIndexData=${hasIndexData}`,
`hasDynamicData=${hasDynamicData}`,
`hasDoubleIndexData=${hasDoubleIndexData}`,
].join('\n')
)
}
if (appPagesDataPathnames.length > 0) {
throw new Error(
`Expected no pages-router data outputs in appPages: ${JSON.stringify(appPagesDataPathnames)}`
)
}
},
}
...@@ -11,4 +11,8 @@ module.exports = { ...@@ -11,4 +11,8 @@ module.exports = {
}, },
] ]
}, },
experimental: {
adapterPath:
process.env.NEXT_ADAPTER_PATH ?? require.resolve('./my-adapter.js'),
},
} }
...@@ -8,7 +8,9 @@ describe('edge render - custom _document with edge runtime', () => { ...@@ -8,7 +8,9 @@ describe('edge render - custom _document with edge runtime', () => {
'pages/index.js': new FileRef( 'pages/index.js': new FileRef(
join(__dirname, 'app', 'pages', 'index.js') join(__dirname, 'app', 'pages', 'index.js')
), ),
'pages/[id].js': new FileRef(join(__dirname, 'app', 'pages', '[id].js')),
'next.config.js': new FileRef(join(__dirname, 'app', 'next.config.js')), 'next.config.js': new FileRef(join(__dirname, 'app', 'next.config.js')),
'my-adapter.js': new FileRef(join(__dirname, 'app', 'my-adapter.js')),
'pages/_document.js': ` 'pages/_document.js': `
import Document, { Html, Head, Main, NextScript } from 'next/document' import Document, { Html, Head, Main, NextScript } from 'next/document'
export default class MyDocument extends Document { export default class MyDocument extends Document {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment