File size: 17,108 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 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 | diff --git a/test/e2e/app-dir/partial-fallback-root-blocking/next.config.js b/test/e2e/app-dir/partial-fallback-root-blocking/next.config.js
index e64bae22..5e50f0b7 100644
--- a/test/e2e/app-dir/partial-fallback-root-blocking/next.config.js
+++ b/test/e2e/app-dir/partial-fallback-root-blocking/next.config.js
@@ -3,6 +3,7 @@
*/
const nextConfig = {
cacheComponents: true,
+ partialPrefetching: true,
}
module.exports = nextConfig
diff --git a/test/e2e/app-dir/partial-fallback-root-blocking/partial-fallback-root-blocking.test.ts b/test/e2e/app-dir/partial-fallback-root-blocking/partial-fallback-root-blocking.test.ts
index 76293240..bfe46a4a 100644
--- a/test/e2e/app-dir/partial-fallback-root-blocking/partial-fallback-root-blocking.test.ts
+++ b/test/e2e/app-dir/partial-fallback-root-blocking/partial-fallback-root-blocking.test.ts
@@ -42,22 +42,29 @@ describe('partial-fallback-root-blocking', () => {
// TODO: Re-enable once infra supports multiple layers of fallbacks
if (!isNextDeploy) {
- it('should not reuse a shared shell cache entry for unknown root branches', async () => {
+ it('should serve unknown root branches with the root param resolved and other params deferred', async () => {
const firstResult = await fetchSplitHTML('/fr/two')
expect(firstResult.response.status).toBe(200)
expect(firstResult.static$('#lang-fallback').length).toBe(0)
expect(firstResult.static$('#lang').text()).toBe('fr')
- expect(firstResult.static$('#slug').text()).toBe('two')
- expect(firstResult.dynamicPart).toBe('')
+
+ expect(firstResult.static$('#slug-fallback').text()).toBe(
+ 'loading slug...'
+ )
+ expect(firstResult.static$('#slug').length).toBe(0)
+ expect(firstResult.dynamicPart).toContain('<div id="slug">two</div>')
const secondResult = await fetchSplitHTML('/fr/other')
expect(secondResult.response.status).toBe(200)
expect(secondResult.static$('#lang-fallback').length).toBe(0)
expect(secondResult.static$('#lang').text()).toBe('fr')
- expect(secondResult.static$('#slug').text()).toBe('other')
- expect(secondResult.dynamicPart).toBe('')
+ expect(secondResult.static$('#slug-fallback').text()).toBe(
+ 'loading slug...'
+ )
+ expect(secondResult.static$('#slug').length).toBe(0)
+ expect(secondResult.dynamicPart).toContain('<div id="slug">other</div>')
})
}
diff --git a/test/production/app-dir/adapter-partial-fallback-blocking/adapter-partial-fallback-blocking.test.ts b/test/production/app-dir/adapter-partial-fallback-blocking/adapter-partial-fallback-blocking.test.ts
new file mode 100644
index 00000000..acdfa239
--- /dev/null
+++ b/test/production/app-dir/adapter-partial-fallback-blocking/adapter-partial-fallback-blocking.test.ts
@@ -0,0 +1,132 @@
+import { nextTestSetup } from 'e2e-utils'
+import type { NextAdapter } from 'next'
+
+describe('adapter-partial-fallback-blocking', () => {
+ const { next } = nextTestSetup({
+ files: __dirname,
+ })
+
+ function expectAllowedParams(allowQuery: string[], expected: string[]) {
+ // Adapter query allowlists are sets. Their serialized order is not part
+ // of the build output contract.
+ expect(new Set(allowQuery)).toEqual(new Set(expected))
+ }
+
+ it('should exclude never-prerenderable params from allowQuery for blocking routes with empty shells', async () => {
+ const { outputs }: Parameters<NextAdapter['onBuildComplete']>[0] =
+ await next.readJSON('build-complete.json')
+
+ const genericEmptyShellPrerender = outputs.prerenders.find(
+ (output) => output.pathname === '/empty-shell/[one]/[two]'
+ )
+ const genericEmptyShellDataPrerender = outputs.prerenders.find(
+ (output) => output.pathname === '/empty-shell/[one]/[two].rsc'
+ )
+ const genericEmptyShellSegmentPrerenders = outputs.prerenders.filter(
+ (output) =>
+ output.pathname.startsWith('/empty-shell/[one]/[two].segments/')
+ )
+ const generatedEmptyShellPrerender = outputs.prerenders.find(
+ (output) => output.pathname === '/empty-shell/a/[two]'
+ )
+
+ expect(genericEmptyShellPrerender).toBeDefined()
+ expect(genericEmptyShellDataPrerender).toBeDefined()
+ expect(genericEmptyShellSegmentPrerenders.length).toBeGreaterThan(0)
+ expect(generatedEmptyShellPrerender).toBeDefined()
+
+ expectAllowedParams(genericEmptyShellPrerender.config.allowQuery, [
+ 'nxtPone',
+ ])
+ expectAllowedParams(genericEmptyShellDataPrerender.config.allowQuery, [
+ 'nxtPone',
+ ])
+ for (const output of genericEmptyShellSegmentPrerenders) {
+ expectAllowedParams(output.config.allowQuery, ['nxtPone'])
+ }
+
+ expect(generatedEmptyShellPrerender.config.partialFallback).toBeUndefined()
+ expectAllowedParams(generatedEmptyShellPrerender.config.allowQuery, [])
+ })
+
+ it('should exclude never-prerenderable params from allowQuery for entries with a resolved root param', async () => {
+ const { outputs }: Parameters<NextAdapter['onBuildComplete']>[0] =
+ await next.readJSON('build-complete.json')
+
+ const emptyShellPrerender = outputs.prerenders.find(
+ (output) =>
+ output.pathname === '/with-root-param/en/empty-shell/[category]/[id]'
+ )
+ const emptyShellDataPrerender = outputs.prerenders.find(
+ (output) =>
+ output.pathname ===
+ '/with-root-param/en/empty-shell/[category]/[id].rsc'
+ )
+ const nonEmptyShellPrerender = outputs.prerenders.find(
+ (output) =>
+ output.pathname ===
+ '/with-root-param/en/non-empty-shell/[category]/[id]'
+ )
+ const emptyShellLeafPrerender = outputs.prerenders.find(
+ (output) =>
+ output.pathname === '/with-root-param/en/empty-shell/shoes/[id]'
+ )
+
+ expect(emptyShellPrerender).toBeDefined()
+ expect(emptyShellDataPrerender).toBeDefined()
+ expect(nonEmptyShellPrerender).toBeDefined()
+ expect(emptyShellLeafPrerender).toBeDefined()
+
+ expectAllowedParams(emptyShellPrerender.config.allowQuery, [
+ 'nxtPcategory',
+ ])
+ expectAllowedParams(emptyShellDataPrerender.config.allowQuery, [
+ 'nxtPcategory',
+ ])
+
+ expectAllowedParams(nonEmptyShellPrerender.config.allowQuery, [
+ 'nxtPcategory',
+ ])
+ expect(nonEmptyShellPrerender.config.partialFallback).toBe(true)
+
+ expectAllowedParams(emptyShellLeafPrerender.config.allowQuery, [])
+ })
+
+ it('should exclude never-prerenderable params from allowQuery for entries with an unresolved root param', async () => {
+ const { outputs }: Parameters<NextAdapter['onBuildComplete']>[0] =
+ await next.readJSON('build-complete.json')
+
+ const emptyShellBasePrerender = outputs.prerenders.find(
+ (output) =>
+ output.pathname ===
+ '/with-root-param/[lang]/empty-shell/[category]/[id]'
+ )
+ const emptyShellBaseDataPrerender = outputs.prerenders.find(
+ (output) =>
+ output.pathname ===
+ '/with-root-param/[lang]/empty-shell/[category]/[id].rsc'
+ )
+ const nonEmptyShellBasePrerender = outputs.prerenders.find(
+ (output) =>
+ output.pathname ===
+ '/with-root-param/[lang]/non-empty-shell/[category]/[id]'
+ )
+
+ expect(emptyShellBasePrerender).toBeDefined()
+ expect(emptyShellBaseDataPrerender).toBeDefined()
+ expect(nonEmptyShellBasePrerender).toBeDefined()
+
+ expectAllowedParams(emptyShellBasePrerender.config.allowQuery, [
+ 'nxtPlang',
+ 'nxtPcategory',
+ ])
+ expectAllowedParams(emptyShellBaseDataPrerender.config.allowQuery, [
+ 'nxtPlang',
+ 'nxtPcategory',
+ ])
+ expectAllowedParams(nonEmptyShellBasePrerender.config.allowQuery, [
+ 'nxtPlang',
+ 'nxtPcategory',
+ ])
+ })
+})
diff --git a/test/production/app-dir/adapter-partial-fallback-blocking/app/(standard)/empty-shell/[one]/[two]/page.tsx b/test/production/app-dir/adapter-partial-fallback-blocking/app/(standard)/empty-shell/[one]/[two]/page.tsx
new file mode 100644
index 00000000..65d28a99
--- /dev/null
+++ b/test/production/app-dir/adapter-partial-fallback-blocking/app/(standard)/empty-shell/[one]/[two]/page.tsx
@@ -0,0 +1,27 @@
+// This route intentionally produces EMPTY build-time shells: the params are
+// read outside of any Suspense boundary (and there is no loading.tsx), so the
+// postpone propagates to the root. `instant = false` opts the route out of
+// requiring an instant (non-empty) shell.
+//
+// The empty shells downgrade the generic route to a blocking route, but `two`
+// is still never provided by `generateStaticParams`: an on-demand render may
+// only complete `one`, so only `one` may participate in the cache key.
+export function generateStaticParams() {
+ return [{ one: 'a' }]
+}
+
+export const instant = false
+
+export default async function Page({
+ params,
+}: {
+ params: Promise<{ one: string; two: string }>
+}) {
+ const { one, two } = await params
+
+ return (
+ <div>
+ {one}:{two}
+ </div>
+ )
+}
diff --git a/test/production/app-dir/adapter-partial-fallback-blocking/app/(standard)/layout.tsx b/test/production/app-dir/adapter-partial-fallback-blocking/app/(standard)/layout.tsx
new file mode 100644
index 00000000..e7a42507
--- /dev/null
+++ b/test/production/app-dir/adapter-partial-fallback-blocking/app/(standard)/layout.tsx
@@ -0,0 +1,11 @@
+import { ReactNode } from 'react'
+
+// Root layout for the (standard) branch: all params in this branch are
+// below the root layout, so none of them are root params.
+export default function Root({ children }: { children: ReactNode }) {
+ return (
+ <html>
+ <body>{children}</body>
+ </html>
+ )
+}
diff --git a/test/production/app-dir/adapter-partial-fallback-blocking/app/with-root-param/[lang]/empty-shell/[category]/[id]/page.tsx b/test/production/app-dir/adapter-partial-fallback-blocking/app/with-root-param/[lang]/empty-shell/[category]/[id]/page.tsx
new file mode 100644
index 00000000..d2b6d1b1
--- /dev/null
+++ b/test/production/app-dir/adapter-partial-fallback-blocking/app/with-root-param/[lang]/empty-shell/[category]/[id]/page.tsx
@@ -0,0 +1,38 @@
+// Empty-shell variant under a root param: the params are read outside of
+// any Suspense boundary, so the postpone propagates to the root and every
+// build-time shell is empty. `instant = false` opts the route out of
+// requiring an instant (non-empty) shell.
+//
+// `generateStaticParams` provides `lang` in every entry (required for root
+// params) and partially covers `category`; `id` is never provided, so `id`
+// must never be resolved into a cached shell and must never be part of a
+// cache key — including for requests whose `lang` value was not enumerated
+// (e.g. /fr/...), which match the base route entry where `lang` is an
+// unresolved root param.
+export async function generateStaticParams() {
+ return [{ lang: 'en' }, { lang: 'en', category: 'shoes' }]
+}
+
+export const instant = false
+
+export default async function Page({
+ params,
+}: {
+ params: Promise<{ lang: string; category: string; id: string }>
+}) {
+ const { lang, category, id } = await params
+
+ // Per-render marker (prerenderable): must be re-rendered per request and
+ // never repeat across fetches — a repeated value proves a stored render
+ // is being replayed from the cache.
+ const renderedAt = performance.now()
+
+ return (
+ <div>
+ <div id="lang">{lang}</div>
+ <div id="category">{category}</div>
+ <div id="id">{id}</div>
+ <div id="rendered-at">{renderedAt}</div>
+ </div>
+ )
+}
diff --git a/test/production/app-dir/adapter-partial-fallback-blocking/app/with-root-param/[lang]/layout.tsx b/test/production/app-dir/adapter-partial-fallback-blocking/app/with-root-param/[lang]/layout.tsx
new file mode 100644
index 00000000..bc155c67
--- /dev/null
+++ b/test/production/app-dir/adapter-partial-fallback-blocking/app/with-root-param/[lang]/layout.tsx
@@ -0,0 +1,19 @@
+// The ROOT layout lives inside [lang], making `lang` a ROOT param: the
+// document itself (the html tag) varies by lang with no Suspense boundary.
+// Root params must be provided by every generateStaticParams result — the
+// build enforces this — so `lang` is always a prerenderable param.
+export default async function RootLayout({
+ children,
+ params,
+}: {
+ children: React.ReactNode
+ params: Promise<{ lang: string }>
+}) {
+ const { lang } = await params
+
+ return (
+ <html lang={lang}>
+ <body>{children}</body>
+ </html>
+ )
+}
diff --git a/test/production/app-dir/adapter-partial-fallback-blocking/app/with-root-param/[lang]/non-empty-shell/[category]/[id]/page.tsx b/test/production/app-dir/adapter-partial-fallback-blocking/app/with-root-param/[lang]/non-empty-shell/[category]/[id]/page.tsx
new file mode 100644
index 00000000..ba731670
--- /dev/null
+++ b/test/production/app-dir/adapter-partial-fallback-blocking/app/with-root-param/[lang]/non-empty-shell/[category]/[id]/page.tsx
@@ -0,0 +1,49 @@
+import { Suspense } from 'react'
+
+// Non-empty-shell variant under a root param: static page content plus
+// Suspense boundaries around the non-root param reads, so shells contain
+// static content and no empty-shell downgrade happens.
+//
+// `generateStaticParams` provides `lang` in every entry (required for root
+// params) and partially covers `category`; `id` is never provided and must
+// never resolve into a cached shell nor participate in a cache key.
+export async function generateStaticParams() {
+ return [{ lang: 'en' }, { lang: 'en', category: 'shoes' }]
+}
+
+async function Id({ params }: { params: Promise<{ id: string }> }) {
+ const { id } = await params
+
+ // Per-render marker (prerenderable), read after `await params` so it
+ // belongs to the deferred region: it must be re-rendered (resumed) per
+ // request and never repeat across fetches.
+ const renderedAt = performance.now()
+
+ return (
+ <>
+ <div id="id">{id}</div>
+ <div id="rendered-at">{renderedAt}</div>
+ </>
+ )
+}
+
+export default function Page({
+ params,
+}: {
+ params: Promise<{ lang: string; category: string; id: string }>
+}) {
+ return (
+ <div>
+ <div id="static">static page content</div>
+ <Suspense
+ fallback={
+ <div id="id-fallback" data-fallback>
+ loading id...
+ </div>
+ }
+ >
+ <Id params={params} />
+ </Suspense>
+ </div>
+ )
+}
diff --git a/test/production/app-dir/adapter-partial-fallback-blocking/app/with-root-param/[lang]/non-empty-shell/[category]/layout.tsx b/test/production/app-dir/adapter-partial-fallback-blocking/app/with-root-param/[lang]/non-empty-shell/[category]/layout.tsx
new file mode 100644
index 00000000..a0da238a
--- /dev/null
+++ b/test/production/app-dir/adapter-partial-fallback-blocking/app/with-root-param/[lang]/non-empty-shell/[category]/layout.tsx
@@ -0,0 +1,40 @@
+import { Suspense, type ReactNode } from 'react'
+
+// `category` is read in its own Suspense boundary: shells where it is
+// concrete render it statically, and generic shells show
+// `#category-fallback`. This makes the served shell's specialization
+// observable from the static part of the response. (`lang` is a root param
+// and is part of the document itself, rendered by the root layout.)
+async function LayoutImpl({
+ children,
+ params,
+}: {
+ children: ReactNode
+ params: Promise<{ category: string }>
+}) {
+ const { category } = await params
+
+ return (
+ <div>
+ <div id="category">{category}</div>
+ {children}
+ </div>
+ )
+}
+
+export default function Layout(props: {
+ children: ReactNode
+ params: Promise<{ category: string }>
+}) {
+ return (
+ <Suspense
+ fallback={
+ <div id="category-fallback" data-fallback>
+ loading category...
+ </div>
+ }
+ >
+ <LayoutImpl {...props} />
+ </Suspense>
+ )
+}
diff --git a/test/production/app-dir/adapter-partial-fallback-blocking/my-adapter.mjs b/test/production/app-dir/adapter-partial-fallback-blocking/my-adapter.mjs
new file mode 100644
index 00000000..548129ec
--- /dev/null
+++ b/test/production/app-dir/adapter-partial-fallback-blocking/my-adapter.mjs
@@ -0,0 +1,9 @@
+import fs from 'fs/promises'
+
+/** @type {import('next').NextAdapter } */
+export default {
+ name: 'adapter-partial-fallback-blocking',
+ async onBuildComplete(ctx) {
+ await fs.writeFile('build-complete.json', JSON.stringify(ctx, null, 2))
+ },
+}
diff --git a/test/production/app-dir/adapter-partial-fallback-blocking/next.config.js b/test/production/app-dir/adapter-partial-fallback-blocking/next.config.js
new file mode 100644
index 00000000..39584cc1
--- /dev/null
+++ b/test/production/app-dir/adapter-partial-fallback-blocking/next.config.js
@@ -0,0 +1,10 @@
+/**
+ * @type {import('next').NextConfig}
+ */
+const nextConfig = {
+ cacheComponents: true,
+ partialPrefetching: true,
+ adapterPath: require.resolve('./my-adapter.mjs'),
+}
+
+module.exports = nextConfig
|