Unverified Commit f9981272 authored by Wyatt Johnson's avatar Wyatt Johnson Committed by GitHub

Delete unused static prefetch code (#58783)

This removes the dead code related to prefetching until it can reland.
Co-authored-by: 's avatarkodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
parent 2cc88d7b
...@@ -7,11 +7,6 @@ import type { ...@@ -7,11 +7,6 @@ import type {
MockedRequest, MockedRequest,
MockedResponse, MockedResponse,
} from '../../server/lib/mock-request' } from '../../server/lib/mock-request'
import {
RSC_HEADER,
NEXT_URL,
NEXT_ROUTER_PREFETCH_HEADER,
} from '../../client/components/app-router-headers'
import { isDynamicUsageError } from '../helpers/is-dynamic-usage-error' import { isDynamicUsageError } from '../helpers/is-dynamic-usage-error'
import { import {
NEXT_CACHE_TAGS_HEADER, NEXT_CACHE_TAGS_HEADER,
...@@ -30,59 +25,6 @@ export const enum ExportedAppPageFiles { ...@@ -30,59 +25,6 @@ export const enum ExportedAppPageFiles {
POSTPONED = 'POSTPONED', POSTPONED = 'POSTPONED',
} }
async function generatePrefetchRsc(
req: MockedRequest,
path: string,
res: MockedResponse,
pathname: string,
htmlFilepath: string,
renderOpts: RenderOpts,
fileWriter: FileWriter
): Promise<boolean> {
// TODO: Re-enable once this is better supported client-side
// It's currently not reliable to generate these prefetches because the client router
// depends on the RSC payload being generated with FlightRouterState. When we generate these prefetches
// without router state, it causes mismatches on client-side nav, resulting in subtle navigation bugs
// like unnecessarily re-rendering layouts.
return false
// When we're in PPR, the RSC payload is emitted as the prefetch payload, so
// attempting to generate a prefetch RSC is an error.
if (renderOpts.experimental.ppr) {
throw new Error(
'Invariant: explicit prefetch RSC cannot be generated with PPR enabled'
)
}
req.headers[RSC_HEADER.toLowerCase()] = '1'
req.headers[NEXT_URL.toLowerCase()] = path
req.headers[NEXT_ROUTER_PREFETCH_HEADER.toLowerCase()] = '1'
renderOpts.supportsDynamicHTML = true
renderOpts.isPrefetch = true
delete renderOpts.isRevalidate
const prefetchRenderResult = await lazyRenderAppPage(
req,
res,
pathname,
{},
renderOpts
)
const prefetchRscData = await prefetchRenderResult.toUnchunkedString(true)
if ((renderOpts as any).store.staticPrefetchBailout) return false
await fileWriter(
ExportedAppPageFiles.FLIGHT,
htmlFilepath.replace(/\.html$/, RSC_PREFETCH_SUFFIX),
prefetchRscData
)
return true
}
export async function exportAppPage( export async function exportAppPage(
req: MockedRequest, req: MockedRequest,
res: MockedResponse, res: MockedResponse,
...@@ -94,7 +36,6 @@ export async function exportAppPage( ...@@ -94,7 +36,6 @@ export async function exportAppPage(
htmlFilepath: string, htmlFilepath: string,
debugOutput: boolean, debugOutput: boolean,
isDynamicError: boolean, isDynamicError: boolean,
isAppPrefetch: boolean,
fileWriter: FileWriter fileWriter: FileWriter
): Promise<ExportRouteResult> { ): Promise<ExportRouteResult> {
// 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`.
...@@ -103,22 +44,6 @@ export async function exportAppPage( ...@@ -103,22 +44,6 @@ export async function exportAppPage(
} }
try { try {
if (isAppPrefetch) {
const generated = await generatePrefetchRsc(
req,
path,
res,
pathname,
htmlFilepath,
renderOpts,
fileWriter
)
if (generated) {
return { revalidate: 0 }
}
}
const result = await lazyRenderAppPage( const result = await lazyRenderAppPage(
req, req,
res, res,
...@@ -143,19 +68,6 @@ export async function exportAppPage( ...@@ -143,19 +68,6 @@ export async function exportAppPage(
`Page with dynamic = "error" encountered dynamic data method on ${path}.` `Page with dynamic = "error" encountered dynamic data method on ${path}.`
) )
} }
if (!(renderOpts as any).store.staticPrefetchBailout) {
await generatePrefetchRsc(
req,
path,
res,
pathname,
htmlFilepath,
renderOpts,
fileWriter
)
}
const { staticBailoutInfo = {} } = metadata const { staticBailoutInfo = {} } = metadata
if (revalidate === 0 && debugOutput && staticBailoutInfo?.description) { if (revalidate === 0 && debugOutput && staticBailoutInfo?.description) {
......
...@@ -79,8 +79,9 @@ async function exportPageImpl( ...@@ -79,8 +79,9 @@ async function exportPageImpl(
// 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. // TODO: use this when we've re-enabled app prefetching https://github.com/vercel/next.js/pull/58609
_isAppPrefetch: isAppPrefetch = 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,
...@@ -289,7 +290,6 @@ async function exportPageImpl( ...@@ -289,7 +290,6 @@ async function exportPageImpl(
htmlFilepath, htmlFilepath,
debugOutput, debugOutput,
isDynamicError, isDynamicError,
isAppPrefetch,
fileWriter fileWriter
) )
} }
......
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