Unverified Commit 4337bc26 authored by Josh Story's avatar Josh Story Committed by GitHub

fallback shell should not error when dynamic due to params access even with…

fallback shell should not error when dynamic due to params access even with dynamic = "error" (#70534)

When producing a fallback shell params is dynamic. Normally anything
dynamic shoudl be a build error when `export const dynamic = "error"` is
used. however for fallback shells we'll never have fully static shells,
nor should we since the whole point is to produce a PPR shell that
server a wide range of paths. In the refactor for async dynamic APIs I
introduced a bug where fallback param dynamic also errored if `export
const dynamic = "error"` was used. This change corrects this behavior
and adds a corresponding test
parent cd65c520
...@@ -14,11 +14,7 @@ import { ...@@ -14,11 +14,7 @@ import {
type PrerenderStore, type PrerenderStore,
} from '../app-render/prerender-async-storage.external' } from '../app-render/prerender-async-storage.external'
import { InvariantError } from '../../shared/lib/invariant-error' import { InvariantError } from '../../shared/lib/invariant-error'
import { import { makeResolvedReactPromise, describeStringPropertyAccess } from './utils'
makeResolvedReactPromise,
describeStringPropertyAccess,
throwWithStaticGenerationBailoutErrorWithDynamicError,
} from './utils'
import { makeHangingPromise } from '../dynamic-rendering-utils' import { makeHangingPromise } from '../dynamic-rendering-utils'
export type Params = Record<string, string | Array<string> | undefined> export type Params = Record<string, string | Array<string> | undefined>
...@@ -259,12 +255,13 @@ function makeErroringExoticParams( ...@@ -259,12 +255,13 @@ function makeErroringExoticParams(
Object.defineProperty(augmentedUnderlying, prop, { Object.defineProperty(augmentedUnderlying, prop, {
get() { get() {
const expression = describeStringPropertyAccess('params', prop) const expression = describeStringPropertyAccess('params', prop)
if (staticGenerationStore.dynamicShouldError) { // In most dynamic APIs we also throw if `dynamic = "error"` however
throwWithStaticGenerationBailoutErrorWithDynamicError( // for params is only dynamic when we're generating a fallback shell
staticGenerationStore.route, // and even when `dynamic = "error"` we still support generating dynamic
expression // fallback shells
) // TODO remove this comment when dynamicIO is the default since there
} else if (prerenderStore) { // will be no `dynamic = "error"`
if (prerenderStore) {
postponeWithTracking( postponeWithTracking(
staticGenerationStore.route, staticGenerationStore.route,
expression, expression,
...@@ -282,12 +279,13 @@ function makeErroringExoticParams( ...@@ -282,12 +279,13 @@ function makeErroringExoticParams(
Object.defineProperty(promise, prop, { Object.defineProperty(promise, prop, {
get() { get() {
const expression = describeStringPropertyAccess('params', prop) const expression = describeStringPropertyAccess('params', prop)
if (staticGenerationStore.dynamicShouldError) { // In most dynamic APIs we also throw if `dynamic = "error"` however
throwWithStaticGenerationBailoutErrorWithDynamicError( // for params is only dynamic when we're generating a fallback shell
staticGenerationStore.route, // and even when `dynamic = "error"` we still support generating dynamic
expression // fallback shells
) // TODO remove this comment when dynamicIO is the default since there
} else if (prerenderStore) { // will be no `dynamic = "error"`
if (prerenderStore) {
postponeWithTracking( postponeWithTracking(
staticGenerationStore.route, staticGenerationStore.route,
expression, expression,
......
export const dynamic = 'error'
export default function Layout({ children }) {
return (
<>
<div data-layout={Math.random().toString(16).slice(2)} />
{children}
</>
)
}
import { setTimeout } from 'timers/promises'
export default async function Page({ params }) {
await setTimeout(1000)
const { slug } = params
return (
<div>
<div data-slug={slug}>{slug}</div>
This page should be static
</div>
)
}
...@@ -476,6 +476,18 @@ describe('ppr-full', () => { ...@@ -476,6 +476,18 @@ describe('ppr-full', () => {
expect(revalidatedDynamicID).not.toBe(fallbackID) expect(revalidatedDynamicID).not.toBe(fallbackID)
}) })
}) })
/**
* This test is really here to just to force the the suite to have the expected route
* as part of the build. If this failed we'd get a build error and all the tests would fail
*/
it('will allow dynamic fallback shells even when static is enforced', async () => {
const random = Math.random().toString(16).slice(2)
const pathname = `/fallback/dynamic/params/revalidate-${random}`
let $ = await next.render$(pathname)
expect($('[data-slug]').text()).toBe(`revalidate-${random}`)
})
}) })
it('should allow client layouts without postponing fallback if params are not accessed', async () => { it('should allow client layouts without postponing fallback if params are not accessed', async () => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment