avyvar's picture
Add files using upload-large-folder tool
4514571 verified
Raw
History Blame Contribute Delete
6.97 kB
diff --git a/packages/next/src/build/adapter/build-complete.ts b/packages/next/src/build/adapter/build-complete.ts
index 48757853f6..167adb54b5 100644
--- a/packages/next/src/build/adapter/build-complete.ts
+++ b/packages/next/src/build/adapter/build-complete.ts
@@ -1585,6 +1585,7 @@ export async function handleBuildComplete({
const canEmitPartialFallback =
partialFallback && fallbackRootParams?.length === 0
let htmlAllowQuery = allowQuery
+ let didFilterBlockingAllowQuery = false
// We only want to vary on the shell contents if there is a fallback
// present and able to be served.
@@ -1615,6 +1616,35 @@ export async function handleBuildComplete({
)
: []
}
+ } else if (
+ fallback === null &&
+ isAppPage &&
+ renderingMode === RenderingMode.PARTIALLY_STATIC &&
+ routesManifest.rsc.clientParamParsing &&
+ remainingPrerenderableParams !== undefined
+ ) {
+ // BLOCKING entries (no servable fallback) still cache their
+ // on-demand renders, so the same cache-key contract applies as for
+ // partial fallbacks: only params that `generateStaticParams` can
+ // still provide may partition the cache — root params (which are
+ // always provided) and the remaining prerenderable params.
+ // Including a never-prerenderable param would create a cache entry
+ // per param value and resolve the param into the cached content,
+ // so it must be stripped from the request instead, which defers it
+ // to a per-request resume.
+ const prerenderableQueryKeys = new Set<string>()
+ for (const paramName of fallbackRootParams ?? []) {
+ prerenderableQueryKeys.add(`${NEXT_QUERY_PARAM_PREFIX}${paramName}`)
+ }
+ for (const param of remainingPrerenderableParams) {
+ prerenderableQueryKeys.add(
+ `${NEXT_QUERY_PARAM_PREFIX}${param.paramName}`
+ )
+ }
+ htmlAllowQuery = allowQuery.filter((routeKey) =>
+ prerenderableQueryKeys.has(routeKey)
+ )
+ didFilterBlockingAllowQuery = true
}
const initialOutput: AdapterOutput['PRERENDER'] = {
@@ -1699,6 +1729,12 @@ export async function handleBuildComplete({
if (routesManifest.rsc.clientParamParsing) {
dataAllowQuery = htmlAllowQuery
}
+ } else if (didFilterBlockingAllowQuery) {
+ // Blocking entries have no fallback shell whose presence could
+ // make the data route vary differently from the HTML route: the
+ // on-demand data render is cached under the same
+ // prerenderable-params-only contract.
+ dataAllowQuery = htmlAllowQuery
}
if (renderingMode === RenderingMode.PARTIALLY_STATIC) {
diff --git a/packages/next/src/build/templates/app-page.ts b/packages/next/src/build/templates/app-page.ts
index 227259ded5..beed2e5216 100644
--- a/packages/next/src/build/templates/app-page.ts
+++ b/packages/next/src/build/templates/app-page.ts
@@ -585,6 +585,7 @@ export async function handler(
(prerenderInfo.fallbackRootParams?.length ?? 0) > 0
let ssgCacheKey: string | null = null
+ let usesCompletedShellCacheKey = false
if (
!isDraftMode &&
isSSG &&
@@ -597,17 +598,19 @@ export async function handler(
// partial fallbacks we instead derive the cache key from the shell
// that matched this request so `/prefix/[one]/[two]` can specialize into
// `/prefix/c/[two]` without promoting all the way to `/prefix/c/foo`.
+ // This includes entries with unresolved ROOT params: those requests are
+ // served blocking (no shell can be shared across root branches), but
+ // the entry they produce is still keyed by the completed shell — root
+ // params and any other prerenderable params resolve into the key while
+ // params that `generateStaticParams` can never provide stay as
+ // placeholders and must not partition the cache.
const fallbackPathname = prerenderMatch
? typeof prerenderInfo?.fallback === 'string'
? prerenderInfo.fallback
: prerenderMatch.source
: null
- if (
- fallbackPathname &&
- prerenderInfo?.fallbackRouteParams?.length &&
- !hasUnresolvedRootFallbackParams
- ) {
+ if (fallbackPathname && prerenderInfo?.fallbackRouteParams?.length) {
if (remainingPrerenderableParams.length > 0) {
const completedShellCacheKey = buildCompletedShellCacheKey(
fallbackPathname,
@@ -618,10 +621,10 @@ export async function handler(
// If applying the current request params doesn't make the shell any
// more complete, then this shell is already at its most complete
// form and should remain shared rather than creating a new cache entry.
- ssgCacheKey =
- completedShellCacheKey !== fallbackPathname
- ? completedShellCacheKey
- : null
+ if (completedShellCacheKey !== fallbackPathname) {
+ ssgCacheKey = completedShellCacheKey
+ usesCompletedShellCacheKey = true
+ }
}
} else {
ssgCacheKey = resolvedPathname
@@ -1494,9 +1497,22 @@ export async function handler(
effectiveFallbackRouteParams.length <
(prerenderInfo?.fallbackRouteParams?.length ?? 0)
? createOpaqueFallbackRouteParams(effectiveFallbackRouteParams)
- : isDebugFallbackShell
- ? getFallbackRouteParams(normalizedSrcPage, routeModule)
- : null
+ : // A render cached under a completed shell cache key must keep
+ // deferring the params the key leaves as placeholders (the
+ // ones `generateStaticParams` can never provide) so they
+ // resume per request instead of baking into the shared entry.
+ // This is the blocking analog of the background shell
+ // upgrade above and is likewise self-hosted only: in minimal
+ // mode the platform proxy owns this contract by stripping
+ // never-prerenderable params from the request, which defers
+ // them through the placeholder handling instead.
+ !isMinimalMode &&
+ usesCompletedShellCacheKey &&
+ remainingFallbackRouteParams.length > 0
+ ? createOpaqueFallbackRouteParams(remainingFallbackRouteParams)
+ : isDebugFallbackShell
+ ? getFallbackRouteParams(normalizedSrcPage, routeModule)
+ : null
// For staged dynamic rendering (Cached Navigations) and debug static
// shell rendering, pass the fallback params via request meta so the