next.js
0556c918 - [PPF] Instant validation for `ensureStatic = "shell" | "prefetch"` (#98249)

Commit
60 days ago
[PPF] Instant validation for `ensureStatic = "shell" | "prefetch"` (#98249) Adjusts Instant Validation internals to validate the `ShellStatic` stage instead of `ShellRuntime` when `ensureStatic >= "shell"`. If that's the case, the client will do a static request (and extract the shell from it), so the app shell cannot access session data (unlike the PPF default, where we use a runtime shell). Note that in some cases, this might seem more restrictive than needed. For `ensureStatic >= "shell"`, the client will do a static prefetch that goes up to the `Static` stage which resolves more things, like static `params`, `prefetch()` ( in the `PrefetchStatic` stage) and `navigation()` (in the `NavigationStatic` stage). However: 1. The client expects to be able to rewind the static prefetch into a shell and reuse it across the whole route, so we should be validating that the shell is actually useful. 2. For `ensureStatic = "shell"`, we might still do a *runtime* prefetch (with `<Link prefetch={true}>`), which will not have `navigation()`, and validating `ShellStatic` catches that. ### Implementation notes - I've renamed `RequestStore.needsAppShell` to `RequestStore.needsRuntimeShell` (undoing a previous rename), because the `ShellStatic` stage can _also_ be an App Shell, just not a _runtime_ one. The flag controls whether or not we're delaying link data until the runtime stages, which we don't need to do if the shell is static. - If we have `ensureStatic >= "shell"` set, we _won't_ set `RequestStore.needsRuntimeShell` anymore, which means that the main render can once again be re-used for both IV and SSV. `prepareValidationInputsInPartialPrefetching` is changed accordingly. We'll also set `revealAfterStage` to `StaticShell` to match what the client would have prefetched. - We add a new mode in instant validation, `ValidationPrefetchKind.StaticAppShell`, which checks the prefetch at the `ShellStatic` stage. This is enabled if we have `ensureStatic >= "shell"`. the PPF default mode`ValidationPrefetchKind.RuntimeAppShell` uses `ShellRuntime` instead. ### Tests - IV should show an insight for unguarded `cookies()` if `ensureStatic >= "shell"` (unlike the default behavior of app shells) - IV should *still* show an insight for unguarded static `params`, `prefetch()`, and `navigation()` regardless of `ensureStatic` (same as default)
Author
Parents
Loading