File size: 6,965 Bytes
4514571 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 | 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
|