next.js
12f85450 - Add experimental flag to expose testing API in production builds (#89499)

Commit
90 days ago
Add experimental flag to expose testing API in production builds (#89499) ## Summary Adds `experimental.exposeTestingApiInProductionBuild` to make the Instant Navigation Testing API available in production builds. This is a stopgap until a dedicated "profiling build" mode exists—similar to React's profiling builds that include extra instrumentation without the dev-mode overhead. The testing API lets e2e tests assert on prefetched UI before dynamic data streams in. Previously it was dev-only, but production builds have different timing characteristics (prefetches complete faster, code paths differ), so testing against production builds is valuable. ## Approach Introduces a single bundler environment variable `process.env.__NEXT_EXPOSE_TESTING_API` that's true when either: - Running in dev mode, OR - The experimental flag is enabled This replaces scattered `NODE_ENV !== 'production'` checks throughout the testing API code paths, making the gating logic consistent and centralized in the build configuration. Also renames `dev-navigation-lock.ts` to `navigation-testing-lock.ts` and updates header/cookie names from "dev-only" to "instant-navigation-testing" to reflect that the API is no longer dev-exclusive. ## Test plan - Updated existing e2e tests to run in both dev and production modes - Tests pass with `NEXT_TEST_MODE=start` (production build)
Author
Parents
Loading