next.js
e5cc93e7 - Add `serverComponentsHmrCancellation` experimental flag

Commit
9 days ago
Add `serverComponentsHmrCancellation` experimental flag This is the first change in a series that will let `next dev` cancel a Server Component HMR refresh once a newer refresh supersedes it. Here we only introduce the `experimental.serverComponentsHmrCancellation` flag and plumb it to every place later changes will read it, without adding any behavior yet, so on its own this change is an inert no-op. The flag is declared in `ExperimentalConfig`, validated in the Zod schema, and defaults to `false` in `defaultConfig`. We thread it into the runtime config via the `NextConfigRuntime` pick list and `getNextConfigRuntime`, expose it to user-bundled client code through `define-env` as `process.env.__NEXT_SERVER_COMPONENTS_HMR_CANCELLATION`, and pass it into the app render options in `base-server.ts` and the `app-page` build template. The edge SSR template hardcodes it to `false`, because edge rendering does not expose the Node response-close signal the cancellation relies on. So that the following changes are exercised as soon as their behavior lands, `config.ts` honors a `__NEXT_EXPERIMENTAL_SERVER_COMPONENTS_HMR_CANCELLATION` environment variable that forces the flag on while still respecting an explicit user config value, mirroring how `cachedNavigations` is rolled out. Both the `test-cache-components-dev` and `test-cache-components-prod` CI shards export that variable: the development shard so the feature is exercised once its behavior lands, and the production shard as a guard that this development-only feature stays inert in production even with the flag enabled. The default stays `false`; a later change flips it once the implementation is complete and drops the shard overrides.
Author
Committer
Parents
Loading