Skip to content

Commit 05e6b82

Browse files
authored
[ppr] Data route fixes (#66109)
Ensures that app routes (like the `favicon.ico` added in the test case in this PR which is represented as an app route) do not have a prefetch RSC also attached.
1 parent 39ccec8 commit 05e6b82

File tree

2 files changed

+20
-20
lines changed

2 files changed

+20
-20
lines changed

packages/next/src/build/index.ts

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2791,10 +2791,9 @@ export default async function build(
27912791
}
27922792

27932793
let prefetchDataRoute: string | null | undefined
2794-
27952794
// We write the `.prefetch.rsc` when the app has PPR enabled, so
27962795
// always add the prefetch data route to the manifest.
2797-
if (isAppPPREnabled) {
2796+
if (!isRouteHandler && experimentalPPR) {
27982797
prefetchDataRoute = path.posix.join(
27992798
`${normalizedRoute}${RSC_PREFETCH_SUFFIX}`
28002799
)
@@ -2858,15 +2857,17 @@ export default async function build(
28582857

28592858
if (!hasDynamicData && isDynamicRoute(originalAppPath)) {
28602859
const normalizedRoute = normalizePagePath(page)
2861-
const dataRoute = path.posix.join(
2862-
`${normalizedRoute}${RSC_SUFFIX}`
2863-
)
28642860

2865-
let prefetchDataRoute: string | null | undefined
2861+
let dataRoute: string | null = null
2862+
if (!isRouteHandler) {
2863+
dataRoute = path.posix.join(`${normalizedRoute}${RSC_SUFFIX}`)
2864+
}
2865+
2866+
let prefetchDataRoute: string | undefined
28662867

28672868
// We write the `.prefetch.rsc` when the app has PPR enabled, so
28682869
// always add the prefetch data route to the manifest.
2869-
if (isAppPPREnabled) {
2870+
if (!isRouteHandler && isAppPPREnabled) {
28702871
prefetchDataRoute = path.posix.join(
28712872
`${normalizedRoute}${RSC_PREFETCH_SUFFIX}`
28722873
)
@@ -2894,7 +2895,7 @@ export default async function build(
28942895
fallback: appDynamicParamPaths.has(originalAppPath)
28952896
? null
28962897
: false,
2897-
dataRouteRegex: isRouteHandler
2898+
dataRouteRegex: !dataRoute
28982899
? null
28992900
: normalizeRouteRegex(
29002901
getNamedRouteRegex(
@@ -2903,18 +2904,17 @@ export default async function build(
29032904
).re.source.replace(/\(\?:\\\/\)\?\$$/, '\\.rsc$')
29042905
),
29052906
prefetchDataRoute,
2906-
prefetchDataRouteRegex:
2907-
isRouteHandler || !prefetchDataRoute
2908-
? undefined
2909-
: normalizeRouteRegex(
2910-
getNamedRouteRegex(
2911-
prefetchDataRoute.replace(/\.prefetch\.rsc$/, ''),
2912-
false
2913-
).re.source.replace(
2914-
/\(\?:\\\/\)\?\$$/,
2915-
'\\.prefetch\\.rsc$'
2916-
)
2917-
),
2907+
prefetchDataRouteRegex: !prefetchDataRoute
2908+
? undefined
2909+
: normalizeRouteRegex(
2910+
getNamedRouteRegex(
2911+
prefetchDataRoute.replace(/\.prefetch\.rsc$/, ''),
2912+
false
2913+
).re.source.replace(
2914+
/\(\?:\\\/\)\?\$$/,
2915+
'\\.prefetch\\.rsc$'
2916+
)
2917+
),
29182918
}
29192919
}
29202920
}
14.7 KB
Binary file not shown.

0 commit comments

Comments
 (0)