diff --git a/packages/next/src/server/app-render/app-render.tsx b/packages/next/src/server/app-render/app-render.tsx index 44f2834b66778..a177bdb4e3154 100644 --- a/packages/next/src/server/app-render/app-render.tsx +++ b/packages/next/src/server/app-render/app-render.tsx @@ -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 }), - isPrefetch && !Boolean(components.loading) + isPrefetch && + !Boolean(components.loading) && + !hasLoadingComponentInTree(loaderTree) ? null : (() => { const { layoutOrPagePath } = diff --git a/test/e2e/app-dir/app/app/linking/about/loading.js b/test/e2e/app-dir/app/app/linking/about/loading.js new file mode 100644 index 0000000000000..3d9aa325a9cf7 --- /dev/null +++ b/test/e2e/app-dir/app/app/linking/about/loading.js @@ -0,0 +1,3 @@ +export default function AboutLoading() { + return

About loading...

+} diff --git a/test/e2e/app-dir/app/index.test.ts b/test/e2e/app-dir/app/index.test.ts index 08babe21860c8..b431964b671b6 100644 --- a/test/e2e/app-dir/app/index.test.ts +++ b/test/e2e/app-dir/app/index.test.ts @@ -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'