Skip to content

Commit 0f759bd

Browse files
committed
revert SSR prefetch payloads
1 parent cf3d73a commit 0f759bd

File tree

8 files changed

+2
-194
lines changed

8 files changed

+2
-194
lines changed

packages/next/src/build/index.ts

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@ import { eventSwcPlugins } from '../telemetry/events/swc-plugins'
132132
import { normalizeAppPath } from '../shared/lib/router/utils/app-paths'
133133
import {
134134
ACTION,
135-
NEXT_ROUTER_PREFETCH,
136135
RSC,
137136
RSC_CONTENT_TYPE_HEADER,
138137
RSC_VARY_HEADER,
@@ -230,7 +229,6 @@ export type RoutesManifest = {
230229
rsc: {
231230
header: typeof RSC
232231
varyHeader: typeof RSC_VARY_HEADER
233-
prefetchHeader: typeof NEXT_ROUTER_PREFETCH
234232
}
235233
skipMiddlewareUrlNormalize?: boolean
236234
caseSensitive?: boolean
@@ -799,7 +797,6 @@ export default async function build(
799797
rsc: {
800798
header: RSC,
801799
varyHeader: RSC_VARY_HEADER,
802-
prefetchHeader: NEXT_ROUTER_PREFETCH,
803800
contentTypeHeader: RSC_CONTENT_TYPE_HEADER,
804801
},
805802
skipMiddlewareUrlNormalize: config.skipMiddlewareUrlNormalize,
@@ -1153,7 +1150,6 @@ export default async function build(
11531150
const additionalSsgPaths = new Map<string, Array<string>>()
11541151
const additionalSsgPathsEncoded = new Map<string, Array<string>>()
11551152
const appStaticPaths = new Map<string, Array<string>>()
1156-
const appPrefetchPaths = new Map<string, string>()
11571153
const appStaticPathsEncoded = new Map<string, Array<string>>()
11581154
const appNormalizedPaths = new Map<string, string>()
11591155
const appDynamicParamPaths = new Set<string>()
@@ -1653,14 +1649,6 @@ export default async function build(
16531649
appDynamicParamPaths.add(originalAppPath)
16541650
}
16551651
appDefaultConfigs.set(originalAppPath, appConfig)
1656-
1657-
if (
1658-
!isStatic &&
1659-
!isAppRouteRoute(originalAppPath) &&
1660-
!isDynamicRoute(originalAppPath)
1661-
) {
1662-
appPrefetchPaths.set(originalAppPath, page)
1663-
}
16641652
}
16651653
} else {
16661654
if (isEdgeRuntime(pageRuntime)) {
@@ -2561,15 +2549,6 @@ export default async function build(
25612549
})
25622550
})
25632551

2564-
for (const [originalAppPath, page] of appPrefetchPaths) {
2565-
defaultMap[page] = {
2566-
page: originalAppPath,
2567-
query: {},
2568-
_isAppDir: true,
2569-
_isAppPrefetch: true,
2570-
}
2571-
}
2572-
25732552
if (i18n) {
25742553
for (const page of [
25752554
...staticPages,

packages/next/src/export/routes/app-page.ts

Lines changed: 1 addition & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,6 @@ import type { NextParsedUrlQuery } from '../../server/request-meta'
66

77
import fs from 'fs/promises'
88
import { MockedRequest, MockedResponse } from '../../server/lib/mock-request'
9-
import {
10-
RSC,
11-
NEXT_URL,
12-
NEXT_ROUTER_PREFETCH,
13-
} from '../../client/components/app-router-headers'
149
import { isDynamicUsageError } from '../helpers/is-dynamic-usage-error'
1510
import { NEXT_CACHE_TAGS_HEADER } from '../../lib/constants'
1611
import { hasNextSupport } from '../../telemetry/ci-info'
@@ -24,41 +19,6 @@ const render: AppPageRender = (...args) => {
2419
)
2520
}
2621

27-
export async function generatePrefetchRsc(
28-
req: MockedRequest,
29-
path: string,
30-
res: MockedResponse,
31-
pathname: string,
32-
query: NextParsedUrlQuery,
33-
htmlFilepath: string,
34-
renderOpts: RenderOpts
35-
) {
36-
req.headers[RSC.toLowerCase()] = '1'
37-
req.headers[NEXT_URL.toLowerCase()] = path
38-
req.headers[NEXT_ROUTER_PREFETCH.toLowerCase()] = '1'
39-
40-
renderOpts.supportsDynamicHTML = true
41-
delete renderOpts.isRevalidate
42-
43-
const prefetchRenderResult = await render(
44-
req,
45-
res,
46-
pathname,
47-
query,
48-
renderOpts
49-
)
50-
51-
prefetchRenderResult.pipe(res)
52-
await res.hasStreamed
53-
54-
const prefetchRscData = Buffer.concat(res.buffers)
55-
56-
await fs.writeFile(
57-
htmlFilepath.replace(/\.html$/, '.prefetch.rsc'),
58-
prefetchRscData
59-
)
60-
}
61-
6222
export async function exportAppPage(
6323
req: MockedRequest,
6424
res: MockedResponse,
@@ -69,29 +29,14 @@ export async function exportAppPage(
6929
renderOpts: RenderOpts,
7030
htmlFilepath: string,
7131
debugOutput: boolean,
72-
isDynamicError: boolean,
73-
isAppPrefetch: boolean
32+
isDynamicError: boolean
7433
): Promise<ExportPageResult> {
7534
// If the page is `/_not-found`, then we should update the page to be `/404`.
7635
if (page === '/_not-found') {
7736
pathname = '/404'
7837
}
7938

8039
try {
81-
if (isAppPrefetch) {
82-
await generatePrefetchRsc(
83-
req,
84-
path,
85-
res,
86-
pathname,
87-
query,
88-
htmlFilepath,
89-
renderOpts
90-
)
91-
92-
return { fromBuildExportRevalidate: 0 }
93-
}
94-
9540
const result = await render(req, res, pathname, query, renderOpts)
9641
const html = result.toUnchunkedString()
9742
const { metadata } = result
@@ -105,16 +50,6 @@ export async function exportAppPage(
10550
)
10651
}
10752

108-
await generatePrefetchRsc(
109-
req,
110-
path,
111-
res,
112-
pathname,
113-
query,
114-
htmlFilepath,
115-
renderOpts
116-
)
117-
11853
const { staticBailoutInfo = {} } = metadata
11954

12055
if (revalidate === 0 && debugOutput && staticBailoutInfo?.description) {

packages/next/src/export/worker.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,6 @@ async function exportPageImpl(input: ExportPageInput) {
108108
// Check if this is an `app/` page.
109109
_isAppDir: isAppDir = false,
110110

111-
// Check if this is an `app/` prefix request.
112-
_isAppPrefetch: isAppPrefetch = false,
113-
114111
// Check if this should error when dynamic usage is detected.
115112
_isDynamicError: isDynamicError = false,
116113

@@ -309,8 +306,7 @@ async function exportPageImpl(input: ExportPageInput) {
309306
renderOpts,
310307
htmlFilepath,
311308
debugOutput,
312-
isDynamicError,
313-
isAppPrefetch
309+
isDynamicError
314310
)
315311
}
316312

packages/next/src/server/base-server.ts

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,6 @@ import {
8686
FLIGHT_PARAMETERS,
8787
NEXT_RSC_UNION_QUERY,
8888
ACTION,
89-
NEXT_ROUTER_PREFETCH,
90-
RSC_CONTENT_TYPE_HEADER,
9189
} from '../client/components/app-router-headers'
9290
import {
9391
MatchOptions,
@@ -2122,31 +2120,6 @@ export default abstract class Server<ServerOptions extends Options = Options> {
21222120
} else if (
21232121
components.routeModule?.definition.kind === RouteKind.APP_PAGE
21242122
) {
2125-
const isAppPrefetch = req.headers[NEXT_ROUTER_PREFETCH.toLowerCase()]
2126-
2127-
if (
2128-
isAppPrefetch &&
2129-
ssgCacheKey &&
2130-
process.env.NODE_ENV === 'production'
2131-
) {
2132-
try {
2133-
const prefetchRsc = await this.getPrefetchRsc(ssgCacheKey)
2134-
2135-
if (prefetchRsc) {
2136-
res.setHeader(
2137-
'cache-control',
2138-
'private, no-cache, no-store, max-age=0, must-revalidate'
2139-
)
2140-
res.setHeader('content-type', RSC_CONTENT_TYPE_HEADER)
2141-
res.body(prefetchRsc).send()
2142-
return null
2143-
}
2144-
} catch (_) {
2145-
// we fallback to invoking the function if prefetch
2146-
// data is not available
2147-
}
2148-
}
2149-
21502123
const module = components.routeModule as AppPageRouteModule
21512124

21522125
// Due to the way we pass data by mutating `renderOpts`, we can't extend the

test/e2e/app-dir/app-static/app-static.test.ts

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -505,11 +505,9 @@ createNextDescribe(
505505
'stale-cache-serving-edge/app-page/page.js',
506506
'stale-cache-serving-edge/app-page/page_client-reference-manifest.js',
507507
'stale-cache-serving-edge/route-handler/route.js',
508-
'stale-cache-serving/app-page.prefetch.rsc',
509508
'stale-cache-serving/app-page/page.js',
510509
'stale-cache-serving/app-page/page_client-reference-manifest.js',
511510
'stale-cache-serving/route-handler/route.js',
512-
'custom.prefetch.rsc',
513511
'force-cache/page.js',
514512
'ssg-draft-mode.html',
515513
'(new)/custom/page.js',
@@ -525,23 +523,17 @@ createNextDescribe(
525523
'force-static/first.html',
526524
'force-static/second.rsc',
527525
'ssg-draft-mode/test.rsc',
528-
'ssr-forced.prefetch.rsc',
529526
'blog/seb/second-post.rsc',
530527
'blog/tim/first-post.html',
531528
'force-static/second.html',
532529
'ssg-draft-mode/test.html',
533530
'blog/seb/second-post.html',
534-
'force-static.prefetch.rsc',
535531
'ssg-draft-mode/test-2.rsc',
536532
'blog/styfle/first-post.rsc',
537-
'default-cache.prefetch.rsc',
538533
'dynamic-error/[id]/page.js',
539-
'response-url.prefetch.rsc',
540534
'ssg-draft-mode/test-2.html',
541535
'blog/styfle/first-post.html',
542536
'blog/styfle/second-post.rsc',
543-
'fetch-no-cache.prefetch.rsc',
544-
'force-no-store.prefetch.rsc',
545537
'force-static/[slug]/page.js',
546538
'hooks/use-pathname/slug.rsc',
547539
'hooks/use-search-params.rsc',
@@ -567,11 +559,9 @@ createNextDescribe(
567559
'react-fetch-deduping-node/page.js',
568560
'variable-revalidate/encoding.html',
569561
'variable-revalidate/cookie/page.js',
570-
'gen-params-dynamic/one.prefetch.rsc',
571562
'ssg-draft-mode/[[...route]]/page.js',
572563
'variable-revalidate/post-method.rsc',
573564
'dynamic-no-gen-params/[slug]/page.js',
574-
'ssr-auto/cache-no-store.prefetch.rsc',
575565
'static-to-dynamic-error/[id]/page.js',
576566
'variable-revalidate/encoding/page.js',
577567
'variable-revalidate/no-store/page.js',
@@ -585,7 +575,6 @@ createNextDescribe(
585575
'variable-revalidate/revalidate-3.html',
586576
'force-dynamic-prerender/[slug]/page.js',
587577
'gen-params-dynamic-revalidate/one.html',
588-
'react-fetch-deduping-node.prefetch.rsc',
589578
'ssr-auto/fetch-revalidate-zero/page.js',
590579
'variable-revalidate/authorization.html',
591580
'force-dynamic-no-prerender/[id]/page.js',
@@ -596,7 +585,6 @@ createNextDescribe(
596585
'partial-gen-params/[lang]/[slug]/page.js',
597586
'variable-revalidate/headers-instance.rsc',
598587
'variable-revalidate/revalidate-3/page.js',
599-
'force-dynamic-catch-all/slug.prefetch.rsc',
600588
'hooks/use-search-params/force-static.html',
601589
'hooks/use-search-params/with-suspense.rsc',
602590
'route-handler/revalidate-360-isr/route.js',
@@ -606,10 +594,8 @@ createNextDescribe(
606594
'variable-revalidate/headers-instance.html',
607595
'hooks/use-search-params/with-suspense.html',
608596
'route-handler-edge/revalidate-360/route.js',
609-
'variable-revalidate/no-store.prefetch.rsc',
610597
'variable-revalidate/revalidate-360-isr.rsc',
611598
'variable-revalidate/revalidate-360/page.js',
612-
'ssr-auto/fetch-revalidate-zero.prefetch.rsc',
613599
'static-to-dynamic-error-forced/[id]/page.js',
614600
'variable-config-revalidate/revalidate-3.rsc',
615601
'variable-revalidate/revalidate-360-isr.html',
@@ -619,7 +605,6 @@ createNextDescribe(
619605
'variable-config-revalidate/revalidate-3.html',
620606
'variable-revalidate-edge/post-method/page.js',
621607
'variable-revalidate/headers-instance/page.js',
622-
'variable-revalidate/status-code.prefetch.rsc',
623608
'force-cache/page_client-reference-manifest.js',
624609
'hooks/use-search-params/with-suspense/page.js',
625610
'variable-revalidate-edge/revalidate-3/page.js',
@@ -629,10 +614,8 @@ createNextDescribe(
629614
'variable-revalidate/revalidate-360-isr/page.js',
630615
'blog/[author]/page_client-reference-manifest.js',
631616
'default-cache/page_client-reference-manifest.js',
632-
'force-dynamic-prerender/frameworks.prefetch.rsc',
633617
'variable-config-revalidate/revalidate-3/page.js',
634618
'variable-revalidate/post-method-request/page.js',
635-
'variable-revalidate/revalidate-360.prefetch.rsc',
636619
'fetch-no-cache/page_client-reference-manifest.js',
637620
'force-dynamic-catch-all/[slug]/[[...id]]/page.js',
638621
'force-no-store/page_client-reference-manifest.js',
@@ -661,7 +644,6 @@ createNextDescribe(
661644
'partial-gen-params-no-additional-lang/fr/second.html',
662645
'partial-gen-params-no-additional-slug/en/second.html',
663646
'partial-gen-params-no-additional-slug/fr/second.html',
664-
'variable-revalidate/post-method-request.prefetch.rsc',
665647
'variable-revalidate-edge/post-method-request/page.js',
666648
'force-static/[slug]/page_client-reference-manifest.js',
667649
'blog/[author]/[slug]/page_client-reference-manifest.js',

test/e2e/app-dir/app/index.test.ts

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ import { createNextDescribe } from 'e2e-utils'
22
import { check, getRedboxHeader, hasRedbox, waitFor } from 'next-test-utils'
33
import cheerio from 'cheerio'
44
import stripAnsi from 'strip-ansi'
5-
import { BrowserInterface } from 'test/lib/browsers/base'
6-
import { Request } from 'playwright-core'
75

86
createNextDescribe(
97
'app dir',
@@ -12,59 +10,6 @@ createNextDescribe(
1210
},
1311
({ next, isNextDev: isDev, isNextStart, isNextDeploy }) => {
1412
if (isNextStart) {
15-
it('should use RSC prefetch data from build', async () => {
16-
expect(
17-
await next.readFile('.next/server/app/linking.prefetch.rsc')
18-
).toBeTruthy()
19-
expect(
20-
await next.readFile('.next/server/app/linking/about.prefetch.rsc')
21-
).toContain('About loading...')
22-
expect(
23-
await next.readFile(
24-
'.next/server/app/dashboard/deployments/breakdown.prefetch.rsc'
25-
)
26-
).toBeTruthy()
27-
expect(
28-
await next
29-
.readFile(
30-
'.next/server/app/dashboard/deployments/[id].prefetch.rsc'
31-
)
32-
.catch(() => false)
33-
).toBeFalsy()
34-
35-
const outputStart = next.cliOutput.length
36-
const browser: BrowserInterface = await next.browser('/')
37-
const rscReqs = []
38-
39-
browser.on('request', (req: Request) => {
40-
if (req.headers()['rsc']) {
41-
rscReqs.push(req.url())
42-
}
43-
})
44-
45-
await browser.eval('window.location.href = "/linking"')
46-
47-
await check(async () => {
48-
return rscReqs.length > 3 ? 'success' : JSON.stringify(rscReqs)
49-
}, 'success')
50-
51-
const trimmedOutput = next.cliOutput.substring(outputStart)
52-
53-
expect(trimmedOutput).not.toContain(
54-
'rendering dashboard/(custom)/deployments/breakdown'
55-
)
56-
expect(trimmedOutput).not.toContain(
57-
'rendering /dashboard/deployments/[id]'
58-
)
59-
expect(trimmedOutput).not.toContain('rendering linking about page')
60-
61-
await browser.elementByCss('#breakdown').click()
62-
await check(
63-
() => next.cliOutput.substring(outputStart),
64-
/rendering .*breakdown/
65-
)
66-
})
67-
6813
it('should have correct size in build output', async () => {
6914
expect(next.cliOutput).toMatch(
7015
/\/dashboard\/another.*? [^0]{1,} [\w]{1,}B/

0 commit comments

Comments
 (0)