Unverified Commit ca57258d authored by Jimmy Lai's avatar Jimmy Lai Committed by GitHub

app router: ensure static prefetch renders loading.js (#55950)

Should fix the problem surfaced in https://github.com/vercel/next.js/issues/43548#issuecomment-1732416492 

The scenario in which this breaks is when we're asking the app renderer to generate a prefetch payload statically. The renderer was not checking if there were loading.js below the current rendering level, which is the root when statically rendering, so it would always render null, which was incorrect.

Tested out with the original repro  https://next-instant-loading-8nv6psqod-feedthejim.vercel.app
parent 69439d85
......@@ -1119,7 +1119,9 @@ export const renderToHTMLOrFlight: AppPageRender = (
getDynamicParamFromSegment,
query
),
isPrefetch && !Boolean(components.loading)
isPrefetch &&
!Boolean(components.loading) &&
!hasLoadingComponentInTree(loaderTree)
? null
: // Create component tree using the slice of the loaderTree
// @ts-expect-error TODO-APP: fix async component type
......@@ -1142,7 +1144,9 @@ export const renderToHTMLOrFlight: AppPageRender = (
return <Component />
}),
isPrefetch && !Boolean(components.loading)
isPrefetch &&
!Boolean(components.loading) &&
!hasLoadingComponentInTree(loaderTree)
? null
: (() => {
const { layoutOrPagePath } =
......
export default function AboutLoading() {
return <p id="about-loading">About loading...</p>
}
......@@ -19,7 +19,7 @@ createNextDescribe(
).toBeTruthy()
expect(
await next.readFile('.next/server/app/linking/about.prefetch.rsc')
).toBeTruthy()
).toContain('About loading...')
expect(
await next.readFile(
'.next/server/app/dashboard/deployments/breakdown.prefetch.rsc'
......
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