[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.
This commit is contained in:
Wyatt Johnson 2024-05-23 02:24:00 -06:00 committed by GitHub
parent 39ccec8900
commit 05e6b82576
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 20 additions and 20 deletions

View file

@ -2791,10 +2791,9 @@ export default async function build(
} }
let prefetchDataRoute: string | null | undefined let prefetchDataRoute: string | null | undefined
// We write the `.prefetch.rsc` when the app has PPR enabled, so // We write the `.prefetch.rsc` when the app has PPR enabled, so
// always add the prefetch data route to the manifest. // always add the prefetch data route to the manifest.
if (isAppPPREnabled) { if (!isRouteHandler && experimentalPPR) {
prefetchDataRoute = path.posix.join( prefetchDataRoute = path.posix.join(
`${normalizedRoute}${RSC_PREFETCH_SUFFIX}` `${normalizedRoute}${RSC_PREFETCH_SUFFIX}`
) )
@ -2858,15 +2857,17 @@ export default async function build(
if (!hasDynamicData && isDynamicRoute(originalAppPath)) { if (!hasDynamicData && isDynamicRoute(originalAppPath)) {
const normalizedRoute = normalizePagePath(page) const normalizedRoute = normalizePagePath(page)
const dataRoute = path.posix.join(
`${normalizedRoute}${RSC_SUFFIX}`
)
let prefetchDataRoute: string | null | undefined let dataRoute: string | null = null
if (!isRouteHandler) {
dataRoute = path.posix.join(`${normalizedRoute}${RSC_SUFFIX}`)
}
let prefetchDataRoute: string | undefined
// We write the `.prefetch.rsc` when the app has PPR enabled, so // We write the `.prefetch.rsc` when the app has PPR enabled, so
// always add the prefetch data route to the manifest. // always add the prefetch data route to the manifest.
if (isAppPPREnabled) { if (!isRouteHandler && isAppPPREnabled) {
prefetchDataRoute = path.posix.join( prefetchDataRoute = path.posix.join(
`${normalizedRoute}${RSC_PREFETCH_SUFFIX}` `${normalizedRoute}${RSC_PREFETCH_SUFFIX}`
) )
@ -2894,7 +2895,7 @@ export default async function build(
fallback: appDynamicParamPaths.has(originalAppPath) fallback: appDynamicParamPaths.has(originalAppPath)
? null ? null
: false, : false,
dataRouteRegex: isRouteHandler dataRouteRegex: !dataRoute
? null ? null
: normalizeRouteRegex( : normalizeRouteRegex(
getNamedRouteRegex( getNamedRouteRegex(
@ -2903,18 +2904,17 @@ export default async function build(
).re.source.replace(/\(\?:\\\/\)\?\$$/, '\\.rsc$') ).re.source.replace(/\(\?:\\\/\)\?\$$/, '\\.rsc$')
), ),
prefetchDataRoute, prefetchDataRoute,
prefetchDataRouteRegex: prefetchDataRouteRegex: !prefetchDataRoute
isRouteHandler || !prefetchDataRoute ? undefined
? undefined : normalizeRouteRegex(
: normalizeRouteRegex( getNamedRouteRegex(
getNamedRouteRegex( prefetchDataRoute.replace(/\.prefetch\.rsc$/, ''),
prefetchDataRoute.replace(/\.prefetch\.rsc$/, ''), false
false ).re.source.replace(
).re.source.replace( /\(\?:\\\/\)\?\$$/,
/\(\?:\\\/\)\?\$$/, '\\.prefetch\\.rsc$'
'\\.prefetch\\.rsc$' )
) ),
),
} }
} }
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB