Unverified Commit 4cfb0acd authored by Zack Tanner's avatar Zack Tanner Committed by GitHub

Revert: "Generate prefetch RSC payload during build for SSR paths (#54403)" (#56059)

Investigating problems this is causing where incorrect flight data is being generated (potentially not correctly bailing on non-static data) causing navigation issues. 

Reverts #54403
parent 12c800e3
...@@ -132,7 +132,6 @@ import { eventSwcPlugins } from '../telemetry/events/swc-plugins' ...@@ -132,7 +132,6 @@ import { eventSwcPlugins } from '../telemetry/events/swc-plugins'
import { normalizeAppPath } from '../shared/lib/router/utils/app-paths' import { normalizeAppPath } from '../shared/lib/router/utils/app-paths'
import { import {
ACTION, ACTION,
NEXT_ROUTER_PREFETCH,
RSC, RSC,
RSC_CONTENT_TYPE_HEADER, RSC_CONTENT_TYPE_HEADER,
RSC_VARY_HEADER, RSC_VARY_HEADER,
...@@ -230,7 +229,6 @@ export type RoutesManifest = { ...@@ -230,7 +229,6 @@ export type RoutesManifest = {
rsc: { rsc: {
header: typeof RSC header: typeof RSC
varyHeader: typeof RSC_VARY_HEADER varyHeader: typeof RSC_VARY_HEADER
prefetchHeader: typeof NEXT_ROUTER_PREFETCH
} }
skipMiddlewareUrlNormalize?: boolean skipMiddlewareUrlNormalize?: boolean
caseSensitive?: boolean caseSensitive?: boolean
...@@ -799,7 +797,6 @@ export default async function build( ...@@ -799,7 +797,6 @@ export default async function build(
rsc: { rsc: {
header: RSC, header: RSC,
varyHeader: RSC_VARY_HEADER, varyHeader: RSC_VARY_HEADER,
prefetchHeader: NEXT_ROUTER_PREFETCH,
contentTypeHeader: RSC_CONTENT_TYPE_HEADER, contentTypeHeader: RSC_CONTENT_TYPE_HEADER,
}, },
skipMiddlewareUrlNormalize: config.skipMiddlewareUrlNormalize, skipMiddlewareUrlNormalize: config.skipMiddlewareUrlNormalize,
...@@ -1153,7 +1150,6 @@ export default async function build( ...@@ -1153,7 +1150,6 @@ export default async function build(
const additionalSsgPaths = new Map<string, Array<string>>() const additionalSsgPaths = new Map<string, Array<string>>()
const additionalSsgPathsEncoded = new Map<string, Array<string>>() const additionalSsgPathsEncoded = new Map<string, Array<string>>()
const appStaticPaths = new Map<string, Array<string>>() const appStaticPaths = new Map<string, Array<string>>()
const appPrefetchPaths = new Map<string, string>()
const appStaticPathsEncoded = new Map<string, Array<string>>() const appStaticPathsEncoded = new Map<string, Array<string>>()
const appNormalizedPaths = new Map<string, string>() const appNormalizedPaths = new Map<string, string>()
const appDynamicParamPaths = new Set<string>() const appDynamicParamPaths = new Set<string>()
...@@ -1653,14 +1649,6 @@ export default async function build( ...@@ -1653,14 +1649,6 @@ export default async function build(
appDynamicParamPaths.add(originalAppPath) appDynamicParamPaths.add(originalAppPath)
} }
appDefaultConfigs.set(originalAppPath, appConfig) appDefaultConfigs.set(originalAppPath, appConfig)
if (
!isStatic &&
!isAppRouteRoute(originalAppPath) &&
!isDynamicRoute(originalAppPath)
) {
appPrefetchPaths.set(originalAppPath, page)
}
} }
} else { } else {
if (isEdgeRuntime(pageRuntime)) { if (isEdgeRuntime(pageRuntime)) {
...@@ -2561,15 +2549,6 @@ export default async function build( ...@@ -2561,15 +2549,6 @@ export default async function build(
}) })
}) })
for (const [originalAppPath, page] of appPrefetchPaths) {
defaultMap[page] = {
page: originalAppPath,
query: {},
_isAppDir: true,
_isAppPrefetch: true,
}
}
if (i18n) { if (i18n) {
for (const page of [ for (const page of [
...staticPages, ...staticPages,
......
...@@ -6,11 +6,6 @@ import type { NextParsedUrlQuery } from '../../server/request-meta' ...@@ -6,11 +6,6 @@ import type { NextParsedUrlQuery } from '../../server/request-meta'
import fs from 'fs/promises' import fs from 'fs/promises'
import { MockedRequest, MockedResponse } from '../../server/lib/mock-request' import { MockedRequest, MockedResponse } from '../../server/lib/mock-request'
import {
RSC,
NEXT_URL,
NEXT_ROUTER_PREFETCH,
} from '../../client/components/app-router-headers'
import { isDynamicUsageError } from '../helpers/is-dynamic-usage-error' import { isDynamicUsageError } from '../helpers/is-dynamic-usage-error'
import { NEXT_CACHE_TAGS_HEADER } from '../../lib/constants' import { NEXT_CACHE_TAGS_HEADER } from '../../lib/constants'
import { hasNextSupport } from '../../telemetry/ci-info' import { hasNextSupport } from '../../telemetry/ci-info'
...@@ -24,41 +19,6 @@ const render: AppPageRender = (...args) => { ...@@ -24,41 +19,6 @@ const render: AppPageRender = (...args) => {
) )
} }
export async function generatePrefetchRsc(
req: MockedRequest,
path: string,
res: MockedResponse,
pathname: string,
query: NextParsedUrlQuery,
htmlFilepath: string,
renderOpts: RenderOpts
) {
req.headers[RSC.toLowerCase()] = '1'
req.headers[NEXT_URL.toLowerCase()] = path
req.headers[NEXT_ROUTER_PREFETCH.toLowerCase()] = '1'
renderOpts.supportsDynamicHTML = true
delete renderOpts.isRevalidate
const prefetchRenderResult = await render(
req,
res,
pathname,
query,
renderOpts
)
prefetchRenderResult.pipe(res)
await res.hasStreamed
const prefetchRscData = Buffer.concat(res.buffers)
await fs.writeFile(
htmlFilepath.replace(/\.html$/, '.prefetch.rsc'),
prefetchRscData
)
}
export async function exportAppPage( export async function exportAppPage(
req: MockedRequest, req: MockedRequest,
res: MockedResponse, res: MockedResponse,
...@@ -69,8 +29,7 @@ export async function exportAppPage( ...@@ -69,8 +29,7 @@ export async function exportAppPage(
renderOpts: RenderOpts, renderOpts: RenderOpts,
htmlFilepath: string, htmlFilepath: string,
debugOutput: boolean, debugOutput: boolean,
isDynamicError: boolean, isDynamicError: boolean
isAppPrefetch: boolean
): Promise<ExportPageResult> { ): Promise<ExportPageResult> {
// If the page is `/_not-found`, then we should update the page to be `/404`. // If the page is `/_not-found`, then we should update the page to be `/404`.
if (page === '/_not-found') { if (page === '/_not-found') {
...@@ -78,20 +37,6 @@ export async function exportAppPage( ...@@ -78,20 +37,6 @@ export async function exportAppPage(
} }
try { try {
if (isAppPrefetch) {
await generatePrefetchRsc(
req,
path,
res,
pathname,
query,
htmlFilepath,
renderOpts
)
return { fromBuildExportRevalidate: 0 }
}
const result = await render(req, res, pathname, query, renderOpts) const result = await render(req, res, pathname, query, renderOpts)
const html = result.toUnchunkedString() const html = result.toUnchunkedString()
const { metadata } = result const { metadata } = result
...@@ -105,16 +50,6 @@ export async function exportAppPage( ...@@ -105,16 +50,6 @@ export async function exportAppPage(
) )
} }
await generatePrefetchRsc(
req,
path,
res,
pathname,
query,
htmlFilepath,
renderOpts
)
const { staticBailoutInfo = {} } = metadata const { staticBailoutInfo = {} } = metadata
if (revalidate === 0 && debugOutput && staticBailoutInfo?.description) { if (revalidate === 0 && debugOutput && staticBailoutInfo?.description) {
......
...@@ -108,9 +108,6 @@ async function exportPageImpl(input: ExportPageInput) { ...@@ -108,9 +108,6 @@ async function exportPageImpl(input: ExportPageInput) {
// Check if this is an `app/` page. // Check if this is an `app/` page.
_isAppDir: isAppDir = false, _isAppDir: isAppDir = false,
// Check if this is an `app/` prefix request.
_isAppPrefetch: isAppPrefetch = false,
// Check if this should error when dynamic usage is detected. // Check if this should error when dynamic usage is detected.
_isDynamicError: isDynamicError = false, _isDynamicError: isDynamicError = false,
...@@ -309,8 +306,7 @@ async function exportPageImpl(input: ExportPageInput) { ...@@ -309,8 +306,7 @@ async function exportPageImpl(input: ExportPageInput) {
renderOpts, renderOpts,
htmlFilepath, htmlFilepath,
debugOutput, debugOutput,
isDynamicError, isDynamicError
isAppPrefetch
) )
} }
......
...@@ -86,8 +86,6 @@ import { ...@@ -86,8 +86,6 @@ import {
FLIGHT_PARAMETERS, FLIGHT_PARAMETERS,
NEXT_RSC_UNION_QUERY, NEXT_RSC_UNION_QUERY,
ACTION, ACTION,
NEXT_ROUTER_PREFETCH,
RSC_CONTENT_TYPE_HEADER,
} from '../client/components/app-router-headers' } from '../client/components/app-router-headers'
import { import {
MatchOptions, MatchOptions,
...@@ -2122,31 +2120,6 @@ export default abstract class Server<ServerOptions extends Options = Options> { ...@@ -2122,31 +2120,6 @@ export default abstract class Server<ServerOptions extends Options = Options> {
} else if ( } else if (
components.routeModule?.definition.kind === RouteKind.APP_PAGE components.routeModule?.definition.kind === RouteKind.APP_PAGE
) { ) {
const isAppPrefetch = req.headers[NEXT_ROUTER_PREFETCH.toLowerCase()]
if (
isAppPrefetch &&
ssgCacheKey &&
process.env.NODE_ENV === 'production'
) {
try {
const prefetchRsc = await this.getPrefetchRsc(ssgCacheKey)
if (prefetchRsc) {
res.setHeader(
'cache-control',
'private, no-cache, no-store, max-age=0, must-revalidate'
)
res.setHeader('content-type', RSC_CONTENT_TYPE_HEADER)
res.body(prefetchRsc).send()
return null
}
} catch (_) {
// we fallback to invoking the function if prefetch
// data is not available
}
}
const module = components.routeModule as AppPageRouteModule const module = components.routeModule as AppPageRouteModule
// Due to the way we pass data by mutating `renderOpts`, we can't extend the // Due to the way we pass data by mutating `renderOpts`, we can't extend the
......
...@@ -505,11 +505,9 @@ createNextDescribe( ...@@ -505,11 +505,9 @@ createNextDescribe(
'stale-cache-serving-edge/app-page/page.js', 'stale-cache-serving-edge/app-page/page.js',
'stale-cache-serving-edge/app-page/page_client-reference-manifest.js', 'stale-cache-serving-edge/app-page/page_client-reference-manifest.js',
'stale-cache-serving-edge/route-handler/route.js', 'stale-cache-serving-edge/route-handler/route.js',
'stale-cache-serving/app-page.prefetch.rsc',
'stale-cache-serving/app-page/page.js', 'stale-cache-serving/app-page/page.js',
'stale-cache-serving/app-page/page_client-reference-manifest.js', 'stale-cache-serving/app-page/page_client-reference-manifest.js',
'stale-cache-serving/route-handler/route.js', 'stale-cache-serving/route-handler/route.js',
'custom.prefetch.rsc',
'force-cache/page.js', 'force-cache/page.js',
'ssg-draft-mode.html', 'ssg-draft-mode.html',
'(new)/custom/page.js', '(new)/custom/page.js',
...@@ -525,23 +523,17 @@ createNextDescribe( ...@@ -525,23 +523,17 @@ createNextDescribe(
'force-static/first.html', 'force-static/first.html',
'force-static/second.rsc', 'force-static/second.rsc',
'ssg-draft-mode/test.rsc', 'ssg-draft-mode/test.rsc',
'ssr-forced.prefetch.rsc',
'blog/seb/second-post.rsc', 'blog/seb/second-post.rsc',
'blog/tim/first-post.html', 'blog/tim/first-post.html',
'force-static/second.html', 'force-static/second.html',
'ssg-draft-mode/test.html', 'ssg-draft-mode/test.html',
'blog/seb/second-post.html', 'blog/seb/second-post.html',
'force-static.prefetch.rsc',
'ssg-draft-mode/test-2.rsc', 'ssg-draft-mode/test-2.rsc',
'blog/styfle/first-post.rsc', 'blog/styfle/first-post.rsc',
'default-cache.prefetch.rsc',
'dynamic-error/[id]/page.js', 'dynamic-error/[id]/page.js',
'response-url.prefetch.rsc',
'ssg-draft-mode/test-2.html', 'ssg-draft-mode/test-2.html',
'blog/styfle/first-post.html', 'blog/styfle/first-post.html',
'blog/styfle/second-post.rsc', 'blog/styfle/second-post.rsc',
'fetch-no-cache.prefetch.rsc',
'force-no-store.prefetch.rsc',
'force-static/[slug]/page.js', 'force-static/[slug]/page.js',
'hooks/use-pathname/slug.rsc', 'hooks/use-pathname/slug.rsc',
'hooks/use-search-params.rsc', 'hooks/use-search-params.rsc',
...@@ -567,11 +559,9 @@ createNextDescribe( ...@@ -567,11 +559,9 @@ createNextDescribe(
'react-fetch-deduping-node/page.js', 'react-fetch-deduping-node/page.js',
'variable-revalidate/encoding.html', 'variable-revalidate/encoding.html',
'variable-revalidate/cookie/page.js', 'variable-revalidate/cookie/page.js',
'gen-params-dynamic/one.prefetch.rsc',
'ssg-draft-mode/[[...route]]/page.js', 'ssg-draft-mode/[[...route]]/page.js',
'variable-revalidate/post-method.rsc', 'variable-revalidate/post-method.rsc',
'dynamic-no-gen-params/[slug]/page.js', 'dynamic-no-gen-params/[slug]/page.js',
'ssr-auto/cache-no-store.prefetch.rsc',
'static-to-dynamic-error/[id]/page.js', 'static-to-dynamic-error/[id]/page.js',
'variable-revalidate/encoding/page.js', 'variable-revalidate/encoding/page.js',
'variable-revalidate/no-store/page.js', 'variable-revalidate/no-store/page.js',
...@@ -585,7 +575,6 @@ createNextDescribe( ...@@ -585,7 +575,6 @@ createNextDescribe(
'variable-revalidate/revalidate-3.html', 'variable-revalidate/revalidate-3.html',
'force-dynamic-prerender/[slug]/page.js', 'force-dynamic-prerender/[slug]/page.js',
'gen-params-dynamic-revalidate/one.html', 'gen-params-dynamic-revalidate/one.html',
'react-fetch-deduping-node.prefetch.rsc',
'ssr-auto/fetch-revalidate-zero/page.js', 'ssr-auto/fetch-revalidate-zero/page.js',
'variable-revalidate/authorization.html', 'variable-revalidate/authorization.html',
'force-dynamic-no-prerender/[id]/page.js', 'force-dynamic-no-prerender/[id]/page.js',
...@@ -596,7 +585,6 @@ createNextDescribe( ...@@ -596,7 +585,6 @@ createNextDescribe(
'partial-gen-params/[lang]/[slug]/page.js', 'partial-gen-params/[lang]/[slug]/page.js',
'variable-revalidate/headers-instance.rsc', 'variable-revalidate/headers-instance.rsc',
'variable-revalidate/revalidate-3/page.js', 'variable-revalidate/revalidate-3/page.js',
'force-dynamic-catch-all/slug.prefetch.rsc',
'hooks/use-search-params/force-static.html', 'hooks/use-search-params/force-static.html',
'hooks/use-search-params/with-suspense.rsc', 'hooks/use-search-params/with-suspense.rsc',
'route-handler/revalidate-360-isr/route.js', 'route-handler/revalidate-360-isr/route.js',
...@@ -606,10 +594,8 @@ createNextDescribe( ...@@ -606,10 +594,8 @@ createNextDescribe(
'variable-revalidate/headers-instance.html', 'variable-revalidate/headers-instance.html',
'hooks/use-search-params/with-suspense.html', 'hooks/use-search-params/with-suspense.html',
'route-handler-edge/revalidate-360/route.js', 'route-handler-edge/revalidate-360/route.js',
'variable-revalidate/no-store.prefetch.rsc',
'variable-revalidate/revalidate-360-isr.rsc', 'variable-revalidate/revalidate-360-isr.rsc',
'variable-revalidate/revalidate-360/page.js', 'variable-revalidate/revalidate-360/page.js',
'ssr-auto/fetch-revalidate-zero.prefetch.rsc',
'static-to-dynamic-error-forced/[id]/page.js', 'static-to-dynamic-error-forced/[id]/page.js',
'variable-config-revalidate/revalidate-3.rsc', 'variable-config-revalidate/revalidate-3.rsc',
'variable-revalidate/revalidate-360-isr.html', 'variable-revalidate/revalidate-360-isr.html',
...@@ -619,7 +605,6 @@ createNextDescribe( ...@@ -619,7 +605,6 @@ createNextDescribe(
'variable-config-revalidate/revalidate-3.html', 'variable-config-revalidate/revalidate-3.html',
'variable-revalidate-edge/post-method/page.js', 'variable-revalidate-edge/post-method/page.js',
'variable-revalidate/headers-instance/page.js', 'variable-revalidate/headers-instance/page.js',
'variable-revalidate/status-code.prefetch.rsc',
'force-cache/page_client-reference-manifest.js', 'force-cache/page_client-reference-manifest.js',
'hooks/use-search-params/with-suspense/page.js', 'hooks/use-search-params/with-suspense/page.js',
'variable-revalidate-edge/revalidate-3/page.js', 'variable-revalidate-edge/revalidate-3/page.js',
...@@ -629,10 +614,8 @@ createNextDescribe( ...@@ -629,10 +614,8 @@ createNextDescribe(
'variable-revalidate/revalidate-360-isr/page.js', 'variable-revalidate/revalidate-360-isr/page.js',
'blog/[author]/page_client-reference-manifest.js', 'blog/[author]/page_client-reference-manifest.js',
'default-cache/page_client-reference-manifest.js', 'default-cache/page_client-reference-manifest.js',
'force-dynamic-prerender/frameworks.prefetch.rsc',
'variable-config-revalidate/revalidate-3/page.js', 'variable-config-revalidate/revalidate-3/page.js',
'variable-revalidate/post-method-request/page.js', 'variable-revalidate/post-method-request/page.js',
'variable-revalidate/revalidate-360.prefetch.rsc',
'fetch-no-cache/page_client-reference-manifest.js', 'fetch-no-cache/page_client-reference-manifest.js',
'force-dynamic-catch-all/[slug]/[[...id]]/page.js', 'force-dynamic-catch-all/[slug]/[[...id]]/page.js',
'force-no-store/page_client-reference-manifest.js', 'force-no-store/page_client-reference-manifest.js',
...@@ -661,7 +644,6 @@ createNextDescribe( ...@@ -661,7 +644,6 @@ createNextDescribe(
'partial-gen-params-no-additional-lang/fr/second.html', 'partial-gen-params-no-additional-lang/fr/second.html',
'partial-gen-params-no-additional-slug/en/second.html', 'partial-gen-params-no-additional-slug/en/second.html',
'partial-gen-params-no-additional-slug/fr/second.html', 'partial-gen-params-no-additional-slug/fr/second.html',
'variable-revalidate/post-method-request.prefetch.rsc',
'variable-revalidate-edge/post-method-request/page.js', 'variable-revalidate-edge/post-method-request/page.js',
'force-static/[slug]/page_client-reference-manifest.js', 'force-static/[slug]/page_client-reference-manifest.js',
'blog/[author]/[slug]/page_client-reference-manifest.js', 'blog/[author]/[slug]/page_client-reference-manifest.js',
......
...@@ -2,8 +2,6 @@ import { createNextDescribe } from 'e2e-utils' ...@@ -2,8 +2,6 @@ import { createNextDescribe } from 'e2e-utils'
import { check, getRedboxHeader, hasRedbox, waitFor } from 'next-test-utils' import { check, getRedboxHeader, hasRedbox, waitFor } from 'next-test-utils'
import cheerio from 'cheerio' import cheerio from 'cheerio'
import stripAnsi from 'strip-ansi' import stripAnsi from 'strip-ansi'
import { BrowserInterface } from 'test/lib/browsers/base'
import { Request } from 'playwright-core'
createNextDescribe( createNextDescribe(
'app dir', 'app dir',
...@@ -12,59 +10,6 @@ createNextDescribe( ...@@ -12,59 +10,6 @@ createNextDescribe(
}, },
({ next, isNextDev: isDev, isNextStart, isNextDeploy }) => { ({ next, isNextDev: isDev, isNextStart, isNextDeploy }) => {
if (isNextStart) { if (isNextStart) {
it('should use RSC prefetch data from build', async () => {
expect(
await next.readFile('.next/server/app/linking.prefetch.rsc')
).toBeTruthy()
expect(
await next.readFile('.next/server/app/linking/about.prefetch.rsc')
).toContain('About loading...')
expect(
await next.readFile(
'.next/server/app/dashboard/deployments/breakdown.prefetch.rsc'
)
).toBeTruthy()
expect(
await next
.readFile(
'.next/server/app/dashboard/deployments/[id].prefetch.rsc'
)
.catch(() => false)
).toBeFalsy()
const outputStart = next.cliOutput.length
const browser: BrowserInterface = await next.browser('/')
const rscReqs = []
browser.on('request', (req: Request) => {
if (req.headers()['rsc']) {
rscReqs.push(req.url())
}
})
await browser.eval('window.location.href = "/linking"')
await check(async () => {
return rscReqs.length > 3 ? 'success' : JSON.stringify(rscReqs)
}, 'success')
const trimmedOutput = next.cliOutput.substring(outputStart)
expect(trimmedOutput).not.toContain(
'rendering dashboard/(custom)/deployments/breakdown'
)
expect(trimmedOutput).not.toContain(
'rendering /dashboard/deployments/[id]'
)
expect(trimmedOutput).not.toContain('rendering linking about page')
await browser.elementByCss('#breakdown').click()
await check(
() => next.cliOutput.substring(outputStart),
/rendering .*breakdown/
)
})
it('should have correct size in build output', async () => { it('should have correct size in build output', async () => {
expect(next.cliOutput).toMatch( expect(next.cliOutput).toMatch(
/\/dashboard\/another.*? [^0]{1,} [\w]{1,}B/ /\/dashboard\/another.*? [^0]{1,} [\w]{1,}B/
......
...@@ -2660,7 +2660,6 @@ const runTests = (isDev = false, isTurbo = false) => { ...@@ -2660,7 +2660,6 @@ const runTests = (isDev = false, isTurbo = false) => {
contentTypeHeader: 'text/x-component', contentTypeHeader: 'text/x-component',
varyHeader: varyHeader:
'RSC, Next-Router-State-Tree, Next-Router-Prefetch, Next-Url', 'RSC, Next-Router-State-Tree, Next-Router-Prefetch, Next-Url',
prefetchHeader: 'Next-Router-Prefetch',
}, },
}) })
}) })
......
...@@ -1494,7 +1494,6 @@ function runTests({ dev }) { ...@@ -1494,7 +1494,6 @@ function runTests({ dev }) {
contentTypeHeader: 'text/x-component', contentTypeHeader: 'text/x-component',
varyHeader: varyHeader:
'RSC, Next-Router-State-Tree, Next-Router-Prefetch, Next-Url', 'RSC, Next-Router-State-Tree, Next-Router-Prefetch, Next-Url',
prefetchHeader: 'Next-Router-Prefetch',
}, },
}) })
}) })
......
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