1. 24 Mar, 2026 10 commits
    • nextjs-bot's avatar
      v16.2.1-canary.7 · f2be347c
      nextjs-bot authored
      f2be347c
    • Benjamin Woodruff's avatar
      Turbopack: Implement TraceRawVcs and NonLocalValue correctly for Effects (#89133) · e2af4d88
      Benjamin Woodruff authored
      In subsequent PRs, I want to store a `ResolvedVc` (specifically, a `FileSystemPath`, which contains a `Vc<Box<dyn FileSystem>>`) inside of an `Effect`.
      
      To do this in a way that wouldn't break a hypothetical future tracing garbage collector, we must implement `TraceRawVcs` on `Effect`.
      
      The previous PR changed the `Effect` type from a closure to a trait in order to enable this.
      e2af4d88
    • JJ Kasper's avatar
      test: scope css data-url typing to fixture (#91877) · a7cf5eee
      JJ Kasper authored
      In the latest TypeScript version these imports now fail so updating the
      assertion to handle them
      
      x-ref:
      https://github.com/vercel/next.js/actions/runs/23508766037/job/68431989897#step:35:443
      a7cf5eee
    • Benjamin Woodruff's avatar
      Turbopack: Define `Effect` as a trait instead of a closure (#89080) · 468a40fa
      Benjamin Woodruff authored
      This switches effects (special `Collectible`s used to defer file writes) from using a closure representation to using a trait representation.
      
      This makes constructing effects a little more annoying, but it ensures that we'll be able to correctly implement `TraceRawVcs` on these in a subsequent PR.
      
      Changes to `turbo-tasks/src/effect.rs` were done by hand, an LLM was used for updating the two callsites.
      468a40fa
    • Tobias Koppers's avatar
      Add `next internal post-build` CLI command for Turbopack database compaction (#91336) · 43f90177
      Tobias Koppers authored
      ### What?
      
      Adds a \`next internal post-build\` CLI command that performs Turbopack
      persistent cache database compaction as a separate step after \`next
      build\`.
      
      ### Why?
      
      Database compaction during shutdown can be slow and blocks the build
      process. By deferring compaction to a separate post-build step, we can:
      - Keep the main \`next build\` fast by skipping compaction at shutdown
      (controlled via \`NEXT_USE_POST_BUILD=1\`)
      - Run compaction independently, e.g. as a separate CI step or in the
      background
      - Perform a full compaction (\`max_merge_segment_count: usize::MAX\`)
      that is more thorough than the runtime shutdown compaction
      
      **Intended usage in a build pipeline:**
      \`\`\`sh
      NEXT_USE_POST_BUILD=1 next build # fast build, skips compaction at
      shutdown
      next internal post-build # separate step: full compaction of the cache
      \`\`\`
      
      ### How?
      
      **Rust side:**
      - Added \`compact_database()\` to \`turbo-tasks-backend\` that opens the
      database and runs a full compaction using
      \`TurboTasksParallelScheduler\` backed by a dedicated multi-threaded
      Tokio runtime (same scheduler as the normal runtime path, enabling
      parallel work-stealing)
      - Added \`turbopack_database_compact\` NAPI binding that resolves the
      versioned DB path and calls \`compact_database()\`
      - Added \`skip_compaction\` flag to \`NapiTurboEngineOptions\` /
      \`TurboKeyValueDatabase\` to skip compaction during normal shutdown when
      post-build will handle it; asserted that \`skip_compaction=true\`
      requires \`is_short_session=true\` (enforcing the logical dependency)
      - Extracted shared \`DB_CONFIG\`, \`FAMILIES\`, and \`COMPACT_CONFIG\`
      constants and \`git_version_info()\` helper to avoid duplication between
      the runtime DB and standalone compaction paths
      
      **TypeScript side:**
      - Added \`next internal post-build\` command that loads the Next.js
      config, finds the Turbopack cache directory, and calls the native
      compaction binding
      - Added \`databaseCompact\` to the turbo bindings interface (native +
      WASM stub)
      - \`turbopack-build/impl.ts\` sets \`skipCompaction: true\` when
      \`NEXT_USE_POST_BUILD=1\`
      
      **Tests:**
      - Added \`test/production/app-dir/post-build/\` integration test that
      verifies compaction runs successfully on a persistent-cache build and
      reports nothing to do when persistent caching is disabled
      
      ---------
      Co-authored-by: 's avatarTobias Koppers <sokra@users.noreply.github.com>
      Co-authored-by: 's avatarClaude <noreply@anthropic.com>
      43f90177
    • JJ Kasper's avatar
      ci: upload adapter deploy test results (#91846) · 9920dbac
      JJ Kasper authored
      Adds a final step to our e2e deploy test job to upload results for our
      adapter for comparison.
      
      x-ref:
      https://github.com/vercel/next.js/actions/runs/23471649794/job/68298210825#step:5:40
      9920dbac
    • JJ Kasper's avatar
      Fix TS6 baseUrl deprecation for extended tsconfig (#91855) · 2e92c31f
      JJ Kasper authored
      ## Summary
      - handle `compilerOptions.baseUrl` inherited via `extends` in TS6 config
      normalization
      - rewrite `paths` using the resolved base URL and remove `baseUrl` from
      parsed compiler options
      - keep existing behavior for direct `baseUrl` while avoiding TS5101 in
      typecheck
      
      follow-up to https://github.com/vercel/next.js/pull/91847
      
      ## Validation
      - `IS_WEBPACK_TEST=1 NEXT_TEST_MODE=start NEXT_TEST_REACT_VERSION=18.3.1
      __NEXT_EXPERIMENTAL_STRICT_ROUTE_TYPES=true pnpm testheadless
      test/e2e/app-dir/next-config-ts/tsconfig-extends/next-config-ts-tsconfig-extends-esm.test.ts`
      - `IS_WEBPACK_TEST=1 NEXT_TEST_MODE=start NEXT_TEST_REACT_VERSION=18.3.1
      __NEXT_EXPERIMENTAL_STRICT_ROUTE_TYPES=true pnpm testheadless
      test/e2e/app-dir/next-config-ts/import-alias-paths-with-baseurl/next-config-ts-import-alias-paths-with-baseurl-esm.test.ts`
      2e92c31f
    • Matt Mastracci's avatar
      [turbopack] Rebuild the docker build scripts (#91799) · b163a8bf
      Matt Mastracci authored
      ## Why
      
      The native binary build system uses 3 different napi-rs Docker images
      that are opaque, can't be customized, and require runtime toolchain
      downloads. Each CI run downloads compilers and sysroots from scratch,
      wasting ~5 minutes per build. There's no way to customize the build
      environment or share toolchains across the 4 Linux targets.
      
      Some smoke tests are added to ensure that node.js can actually load the
      binaries we build - we don't actually perform much beyond that, just
      making sure it survives the dynamic linker and correctly exposes the
      node APIs.
      
      We also are able to enable `--icf=all`. This appears to (consistently)
      chop off about ~1-2% of the binary size.
      
      ## What
      
      Replaces the 3 napi-rs Docker images with a single custom
      `next-swc-builder` Dockerfile based on Ubuntu 20.04 that can
      cross-compile all 4 Linux targets (x86_64/aarch64 × gnu/musl) from
      either an x86_64 or aarch64 host. All toolchains are baked into the
      image.
      
      Key changes:
      - **`docker/native-builder.Dockerfile`**: Ubuntu 20.04 with clang/lld,
      GNU cross-sysroots via `crossbuild-essential`, musl sysroots from
      musl.cc, Node.js 20, pinned Rust nightly, and `cargo-rustflags` for flag
      resolution
      - **`scripts/docker-native-build.sh`**: Inner build script that
      constructs RUSTFLAGS via `cargo rustflags --config` (merges
      `.cargo/config.toml` with cross-compilation overrides), sets up CC/CXX
      per target, and runs the napi build
      - **`scripts/docker-native-build.js`**: Node.js local build orchestrator
      replacing the bash wrapper, with `--quick`, `--rebuild`, `--test` flags
      and smoke testing via `getTargetTriple()`
      - **`scripts/docker-image-cache.js`**: Turbo-cached Docker image
      (save/load with `--load` for cache hit handling)
      - **`.cargo/config.toml`**: Added musl `crt-static` flag, removed
      cross-compilation flags (now in build script)
      - **CI workflows**: Docker image cached via turbo remote cache,
      `build-docker-image` turbo task, simplified `build_and_deploy.yml`
      
      ## How
      
      All 4 Linux targets use clang as the C compiler + linker driver with
      `gnu-lld-cc` flavor (rust-lld does actual linking). Cross-compilation
      uses `--target` + `--sysroot`:
      - **GNU targets**: Ubuntu multiarch sysroots from
      `crossbuild-essential-{amd64,arm64}`
      - **Musl targets**: musl.cc cross-toolchain sysroots with GCC crt files
      copied into sysroot lib (works around clang 10's `--gcc-toolchain`
      limitation)
      
      RUSTFLAGS are resolved inside the container via `cargo rustflags` which
      merges `.cargo/config.toml` (base flags like `-Zunstable-options`, musl
      `crt-static`) with per-target cross flags passed as `--config` inline
      TOML.
      
      The Docker image is cached via turbo's remote cache (~885 MB tar). On
      cache hit, `docker load` restores it in seconds. On miss, the full image
      build takes ~2 minutes.
      
      ### glibc compatibility
      
      Building on Ubuntu 20.04 (glibc 2.31) ensures broad compatibility. The
      table below shows the minimum glibc version required by major Linux
      distributions ([source](https://repology.org/project/glibc/versions)):
      
      | Distribution | glibc | Compatible? |
      |---|---|---|
      | Ubuntu 20.04 (Focal) | 2.31 | ✅ baseline |
      | Ubuntu 22.04 (Jammy) | 2.35 | ✅ |
      | Ubuntu 24.04 (Noble) | 2.39 | ✅ |
      | Debian 11 (Bullseye) | 2.31 | ✅ |
      | Debian 12 (Bookworm) | 2.36 | ✅ |
      | RHEL / AlmaLinux 8 | 2.28 | ❌ EOL May 2029 (security only) |
      | RHEL / AlmaLinux 9 | 2.34 | ✅ |
      | Amazon Linux 2 | 2.26 | ❌ EOL June 2026 |
      | Amazon Linux 2023 | 2.34 | ✅ |
      | Fedora 40+ | 2.39+ | ✅ |
      | Arch Linux | 2.41+ | ✅ |
      b163a8bf
    • JJ Kasper's avatar
      Avoid deprecated TS node10 moduleResolution defaults (#91847) · aa3ba7ed
      JJ Kasper authored
      TypeScript 6 treats `moduleResolution: "node"` as deprecated (`node10`)
      and can fail builds with `TS5107`.
      
      This update keeps Next.js tsconfig defaults compatible with modern
      TypeScript by preferring `moduleResolution: "bundler"` for modern module
      modes, while preserving `"node"` for `commonjs`/`amd` configs where
      `bundler` is invalid.
      
      Also updates the related tests/snapshots to match the new defaults.
      aa3ba7ed
    • Jam Balaya's avatar
      chore(examples): remove `with-styletron` example (#81842) · 7dd1fcfc
      Jam Balaya authored
      ## Summary
      
      Remove
      [with-styletron](https://github.com/vercel/next.js/tree/canary/examples/with-styletron)
      example and its references from the repository.
      
      Documentation:
      - Remove the Styletron link from the CSS-in-JS examples list in the docs
      
      Tests:
      - Remove the Styletron entry from the
      turbopack-dev-examples-manifest.json
      
      Chores:
      - Delete the examples/with-styletron directory and its contents
      
      ## Why?
      
      [styletron](https://github.com/styletron/styletron) package hasn't been
      maintained in 2 years.
      
      ## Adding or Updating Examples
      
      - [x] The "examples guidelines" are followed from our contributing doc
      https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md
      - [x] Make sure the linting passes by running `pnpm build && pnpm lint`.
      See
      https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md
      
      cc: @samcx
      Co-authored-by: 's avatarJoseph <joseph.chamochumbi@vercel.com>
      7dd1fcfc
  2. 23 Mar, 2026 8 commits
    • nextjs-bot's avatar
      v16.2.1-canary.6 · b55dc5f0
      nextjs-bot authored
      b55dc5f0
    • Andrew Clark's avatar
      [Segment Bundling] [Scaffolding] Track which segments can be omitted from prefetch (#91438) · 6c3295f9
      Andrew Clark authored
      Some segments in a route don't benefit from static prefetching. A
      segment with runtime prefetching enabled will be fetched and computed at
      runtime instead, and a segment with `instant = false` is not
      prefetchable at all. There's no reason to pay the prefetch cost for
      these segments — neither the server (measuring sizes, generating
      responses) nor the client (fetching, caching) gains anything from
      including them.
      
      ### Pass-through segments
      
      This commit teaches the hint computation pass to identify these segments
      and mark them accordingly. During the size measurement traversal,
      disabled segments are skipped (zero size contribution) and act as
      transparent pass-throughs: parent data flows through them to the nearest
      static descendant rather than being blocked. This means a small static
      layout can still be bundled into a grandchild's response even when the
      intermediate segment is dynamic.
      
      ### No behavioral changes yet
      
      The actual server output and client fetching behavior don't change yet —
      disabled segments still produce standalone responses for now. A
      follow-up commit will use these hints to actually omit the segments from
      the output and teach the client to handle the gaps.
      
      ### Head (metadata) inlining
      
      The head (metadata/viewport) inlining logic is also updated: the head is
      only inlined into page segments (not layouts, since pages may access
      additional params like `searchParams`), and routes with runtime prefetch
      skip static head inlining entirely since the runtime response already
      includes the head.
      6c3295f9
    • Jimmy Lai's avatar
      docs: platform portability and infrastructure documentation (#91237) · eb44c314
      Jimmy Lai authored
      ## Summary
      
      Adds comprehensive documentation addressing platform partner feedback
      about Next.js portability, infrastructure requirements, and CDN caching.
      All technical claims verified against the codebase.
      
      **New pages (5):**
      - **Rendering Philosophy** — explains Next.js's component-level
      static/dynamic spectrum, framework comparisons, functional vs.
      performance fidelity definitions, CDN compatibility
      - **Deploying to Platforms** — feature support matrix
      (streaming/cache/edge requirements per feature), CDN infrastructure
      table, minimum requirements, adapter guidance
      - **How Revalidation Works** — tag system architecture (explicit + soft
      tags with `_N_T_` prefix), HTML/RSC consistency requirements,
      multi-instance coordination, graceful degradation
      - **CDN Caching** — cache variability (`Vary` headers, `_rsc` param),
      graceful degradation when headers are dropped, static prefetch caching
      (PPR-scoped), pathname-based cache keying direction
      - **PPR Platform Guide** — implementation tiers (origin-only through
      edge), resume protocol (`next-resume` header, POST + body), artifact
      storage, implementation checklist
      
      **Expanded pages (4):**
      - **Self-Hosting** — streaming infrastructure requirements,
      multi-instance cache coordination, CDN guide links, graceful shutdown
      details
      - **ISR** — multi-instance caveats, tag propagation, background
      regeneration billing, `x-nextjs-cache` monitoring
      - **Cache Handlers** — distributed tag coordination (Redis example),
      soft tags explanation, stream handling, error handling patterns
      - **Adapter API** — runtime integration context, PPR chain headers
      (`next-resume`), multi-instance cache entry propagation, fixed stale
      `x-nextjs-resume` comment
      
      ## Key corrections from code verification
      - Resume header is `next-resume`, not `x-nextjs-resume` (fixed in
      existing adapterPath docs too)
      - Resume requires POST with postponed state in body, not just a header
      - `x-nextjs-cache` has 4 values including `REVALIDATED`, only emitted
      outside minimal mode
      - Soft tags use `_N_T_` prefix with layout paths (`_N_T_/blog/layout`),
      not bare paths
      - `stale-while-revalidate` in Cache-Control is conditional on `expire`
      config
      - Static prefetch caching without state tree only works for PPR-enabled
      routes
      - Fastly product renamed from `Compute@Edge` to `Compute`
      
      ---------
      Co-authored-by: 's avatarJJ Kasper <jj@jjsweb.site>
      Co-authored-by: 's avatarTim Neutkens <tim@timneutkens.nl>
      eb44c314
    • Sebastian "Sebbie" Silbermann's avatar
    • Jiwon Choi's avatar
      docs: add catchError benefits over userspace error boundaries (#91745) · ee6a0d77
      Jiwon Choi authored
      ## Summary
      
      - Add bullet list explaining three key benefits of `unstable_catchError`
      over a plain React error boundary: built-in error recovery via
      `retry()`, framework-aware handling of `redirect()`/`notFound()`, and
      automatic error state clearing on client navigation.
      
      [slack
      thread](https://vercel.slack.com/archives/C02CDC2ALJH/p1774047269162799)
      ee6a0d77
    • nextjs-bot's avatar
    • Hendrik Liebau's avatar
    • Andrew Clark's avatar
      [Segment Bundling] [Scaffolding] Ensure inlining hint correctness (#91320) · 13809269
      Andrew Clark authored
      Inlining hints (which segments to bundle together) are computed once at
      build time by measuring gzip sizes, then persisted to
      `prefetch-hints.json`. There are several scenarios where these hints may
      not be available at render time. This commit addresses each scenario to
      ensure the client always receives correct hints and never enters a bad
      state.
      
      ### Build-time static pages (stale hints)
      
      The initial RSC payload baked into the HTML is generated before hints
      are computed, since hint computation requires at least one completed
      render to measure sizes. The server marks these trees with
      `InliningHintsStale`. The client immediately expires the route cache
      entry so that the next prefetch re-fetches the correct tree from the
      `/_tree` response. The segment data doesn't need re-fetching since it
      was already cached from the initial HTML payload.
      
      ### ISR / revalidation
      
      Hints are always available from the manifest. A missing entry is an
      internal error — it means the build pipeline failed to produce hints for
      a route that needs them.
      
      ### Fully dynamic routes at runtime
      
      No hints exist and none will ever be computed. Every segment gets
      `PrefetchDisabled`, which tells the client not to attempt prefetching.
      This avoids an infinite re-fetch loop that would occur if the client
      kept trying to fetch "correct" hints.
      
      ### Unified response format
      
      Also simplifies the segment prefetch response format: every response is
      now a `SegmentPrefetchResponse` with a top-level `buildId` and a `data`
      array, treating a single-segment response as a bundle that happens to
      have length one. This unifies the format so that bundled multi-segment
      responses (added in a follow-up) require no additional client parsing
      logic.
      13809269
  3. 22 Mar, 2026 2 commits
    • nextjs-bot's avatar
      v16.2.1-canary.5 · cbb5879f
      nextjs-bot authored
      cbb5879f
    • Jiwon Choi's avatar
      docs: use ErrorInfo type consistently in catchError docs (#91744) · 9fdd5bcd
      Jiwon Choi authored
      ## Summary
      
      - Replace inline types with `ErrorInfo` in all TSX examples in
      `catchError.mdx`
      - Merge separate `import type { ErrorInfo }` into single import
      statement
      - Remove broken `highlight` attributes from "Recovering from errors"
      code blocks
      - Stop aliasing `unstable_retry` to `retry` — use `unstable_retry`
      directly in all examples
      - Use "children" instead of "contents" in error boundary descriptions
      (`catchError.mdx`, `error.mdx`)
      9fdd5bcd
  4. 20 Mar, 2026 20 commits
    • nextjs-bot's avatar
      v16.2.1-canary.4 · 6d4a405f
      nextjs-bot authored
      6d4a405f
    • Matt Mastracci's avatar
      [turbopack] Improve regressed build speed on cross-compiled MUSL (#91477) · 75193d5f
      Matt Mastracci authored
      # What
      
      Refactor build_and_deploy.yml to make it more maintainable, add
      documentation to all of the quirky flags we use and remove any flags
      that are not doing anything useful.
      
      # Non-goals
      
      - wasm builds were left out of the matrix, but could probably be added
      in at a later date
      - cross-compilation flags should probably not live in .cargo/config.toml
      but rather in a .cargo/cross-config.toml we conditionally include, but
      this would add some complexity.
      
      # Why
      
      After enabling LTO, our MUSL target builds got significantly slower.
      This wins back a good chunk of the performance that we lost by using
      cross-compilation to MUSL on docker images that are not slow as heck,
      while also trying to clean up this workflow that has accumulated some
      cruft over the years.
      
      The timings are fairly unstable because of uncertain build machine
      variability, but I've tried to capture uncached runs where possible. I
      believe we can state that LTO has a _slight_ increase in compile time,
      but MUSL builds are faster than the pre-LTO state of things.
      
      # Changes
      
      - Refactor build_and_deploy.yml: replace per-target matrix entries with
      mmm-matrix declarative config, consolidate docker build script inline,
      pin actions to commit SHAs
      - Simplify .cargo/config.toml using cfg(true) (RFC 3695) to eliminate
      rustflag duplication across target sections
      - Remove GNU linker flags (rust-lld is now default on x86_64-linux-gnu)
      - Use rust-lld directly for musl targets, remove unused armv7 section
      - Add cargo xtask print-rustflags to replace .github/rustflags.yml
      - Release profile: thin LTO + codegen-units=64 for faster builds
      - Add --log-order stream to TURBO_ARGS for live build output
      - Remove mold linker integration from CI
      75193d5f
    • Vercel Release Bot's avatar
      Update Rspack production test manifest (#91694) · 1ee9d70e
      Vercel Release Bot authored
      This auto-generated PR updates the production integration test manifest used when testing Rspack.
      1ee9d70e
    • Hendrik Liebau's avatar
      [test] Unflake `use-node-streams-env-precedence` test (#91733) · 432b3f96
      Hendrik Liebau authored
      CI is slow sometimes
      ([x-ref](https://github.com/vercel/next.js/actions/runs/23353631446/job/67939293839)),
      so we're removing the low custom test timeout to allow more time to
      build the test fixture.
      
      We're also moving the test from `test/e2e` to `test/production` since
      it's only testing the build output, and doesn't need to be run in dev
      and deploy modes.
      432b3f96
    • Vercel Release Bot's avatar
      Update Rspack development test manifest (#91695) · 450ed6f8
      Vercel Release Bot authored
      This auto-generated PR updates the development integration test manifest used when testing Rspack.
      450ed6f8
    • Niklas Mischkulnig's avatar
    • Tobias Koppers's avatar
      turbopack-cli: add --persistent-caching flag for filesystem-backed cache (#91657) · 7984e4ab
      Tobias Koppers authored
      ### What?
      
      Adds `--persistent-caching` and `--cache-dir` CLI flags to `turbopack
      dev` and `turbopack build` in the standalone `turbopack-cli` crate.
      
      ### Why?
      
      The standalone `turbopack-cli` binary (used independently of `next`) had
      no way to opt into the filesystem-backed persistent cache that the
      `next-napi-bindings` integration already supports. Without this,
      repeated builds always start cold — every incremental run re-computes
      the full task graph from scratch.
      
      ### How?
      
      **`build.rs` (new):** A Cargo build script that uses `vergen-gitcl` to
      emit `VERGEN_GIT_DESCRIBE` and `VERGEN_GIT_DIRTY` as compile-time env
      vars. These are used to key the cache by git version, matching the same
      approach as `next-napi-bindings`. The build script embeds the dirty
      state at compile time rather than runtime to avoid a git subprocess on
      every startup.
      
      The dirty-state caching tradeoff (explained in the build script
      comment): there's a narrow edge case where the tree becomes newly dirty
      without triggering a Cargo rebuild, but in practice this is safe — if
      nothing in the crate changed, the binary is semantically equivalent to a
      clean build, so using the HEAD hash as the cache key is correct.
      
      **`arguments.rs`:** Two new flags on `CommonArguments` (shared by both
      `dev` and `build` subcommands):
      - `--persistent-caching` — opt-in flag to enable the filesystem cache
      - `--cache-dir <PATH>` — override the cache directory (defaults to
      `.turbopack/cache` in the project root)
      
      **`dev/mod.rs` and `build/mod.rs`:**
      - The `Backend` type alias changes from
      `TurboTasksBackend<NoopBackingStorage>` to
      `TurboTasksBackend<Either<TurboBackingStorage, NoopBackingStorage>>` to
      unify the type without dynamic dispatch.
      - When `--persistent-caching` is set: initializes `TurboBackingStorage`
      via `turbo_backing_storage()`, selects
      `StorageMode::ReadWriteOnShutdown` for CI/short sessions and
      `StorageMode::ReadWrite` for interactive dev, and prints a warning if
      the cache was invalidated on startup.
      - When not set: falls back to `noop_backing_storage()` — identical
      behavior to before.
      - Respects the `TURBO_ENGINE_READ_ONLY` env var to force read-only mode.
      
      ---------
      Co-authored-by: 's avatarTobias Koppers <sokra@users.noreply.github.com>
      Co-authored-by: 's avatarClaude <noreply@anthropic.com>
      7984e4ab
    • Tobias Koppers's avatar
      Add module count field to module graph tracing spans (#91697) · 7d451fe0
      Tobias Koppers authored
      ### What?
      
      Adds a `modules` field to two tracing spans that cover module graph
      construction:
      
      - `"module graph for endpoint"` span (per-page graph, in `app.rs`) —
      records the total number of modules across all `SingleModuleGraph`s
      built for that endpoint.
      - `"whole app module graph"` span (new info-level span wrapping
      `whole_app_module_graph_operation` in `project.rs`) — records the
      combined module count of the base graph and the additional-entries
      graph.
      
      Also adds a `module_count()` method to `SingleModuleGraph` (as a
      `#[turbo_tasks::function]` returning `Vc<u64>`) that exposes
      `number_of_modules`.
      
      ### Why?
      
      Module graph size directly affects build and HMR performance. Without a
      count in the trace, it is impossible to correlate span duration with
      graph size or spot regressions where the graph grows unexpectedly.
      Surfacing the count as a structured span field makes it queryable
      without requiring log parsing.
      
      ### How?
      
      - `SingleModuleGraph::module_count()` is a cheap
      `#[turbo_tasks::function]` that wraps the already-computed
      `number_of_modules: usize` field as a `Vc<u64>`.
      - Both call sites follow the deferred-field pattern already used in
      `ProjectContainer::initialize`: the span is created with `modules =
      Empty` before the `async move` block, `span.record("modules", count)` is
      called once the graphs are ready, and `span_clone` is passed to
      `.instrument()` so the field is recorded on the correct span.
      - Module counts are summed across all graphs that contribute to the
      endpoint/app.
      
      ---------
      Co-authored-by: 's avatarTobias Koppers <sokra@users.noreply.github.com>
      Co-authored-by: 's avatarClaude <noreply@anthropic.com>
      Co-authored-by: 's avatarVercel <vercel[bot]@users.noreply.github.com>
      7d451fe0
    • Tobias Koppers's avatar
      [turbopack] Remove incorrect debug_assert in try_read_task_cell (#91699) · 25646b92
      Tobias Koppers authored
      ### What?
      
      Removes the `debug_assert_not_in_top_level_task` call from
      `try_read_task_cell` in `turbopack/crates/turbo-tasks/src/manager.rs`.
      
      ### Why?
      
      The assertion was wrong. `debug_assert_not_in_top_level_task` panics
      with the message:
      
      > "Eventually consistent read cannot be performed from a top-level
      task."
      
      The restriction only applies to **eventually consistent** reads (e.g.
      task output reads), which can return stale data if called from a
      top-level task (`.run_once(...)`). Cell reads, however, are **strongly
      consistent** — they always return up-to-date data. There is no semantic
      reason to forbid reading a cell from a top-level task, and the assert
      was producing false positives in valid call sites.
      
      ### How?
      
      Delete the three lines that guard and invoke
      `debug_assert_not_in_top_level_task` inside `try_read_task_cell`. The
      function itself and its usage in `try_read_task_output` /
      `try_read_local_output` (which are genuinely eventually-consistent) are
      unchanged.
      
      ---------
      Co-authored-by: 's avatarTobias Koppers <sokra@users.noreply.github.com>
      Co-authored-by: 's avatarClaude <noreply@anthropic.com>
      25646b92
    • Niklas Mischkulnig's avatar
      Turbopack: fix webpack loader runner layer (#91727) · cbf12d18
      Niklas Mischkulnig authored
      Otherwise you get a `Dependency tracking is disabled` / infinite loop
      when trying to use both turbopack.rules.loader and turbopackLoader at
      the same time
      cbf12d18
    • JJ Kasper's avatar
      Fix adapter outputs for dynamic metadata routes (#91680) · b6ff1f60
      JJ Kasper authored
      ## Summary
      
      This fixes adapter `onBuildComplete` outputs for dynamic metadata
      routes.
      
      ## Bug
      
      `handleBuildComplete` skipped metadata routes too aggressively via
      `isStaticMetadataFile(...)`, so dynamic metadata routes (for example
      `robots.txt` / `sitemap.xml` using `connection()`) were omitted from
      `outputs.appRoutes`.
      
      ## Fix
      
      Only skip metadata routes when they are actually prerendered/static
      (present in prerender manifests). Dynamic metadata routes are now
      included in adapter `outputs.appRoutes` as expected.
      
      ## Tests
      
      Added e2e coverage in `test/e2e/app-dir/adapter-dynamic-metadata`:
      - verifies dynamic `robots.txt`, `sitemap.xml`, and `favicon.ico`
      functionality
      - verifies adapter output classification for non-deploy runs
      - skips output-shape verification in deploy mode
      - skips the suite in dev mode
      b6ff1f60
    • nextjs-bot's avatar
      v16.2.1-canary.3 · 546250ec
      nextjs-bot authored
      546250ec
    • Niklas Mischkulnig's avatar
      Turbopack: lazy require metadata and handle TLA (#91705) · 118bdaf6
      Niklas Mischkulnig authored
      A regression from #88487
      
      1. Make metadata import lazy with `() => require()`, just like for the layout segments
      2. Properly await the return value to better handle TLA modules
      
      This align with Webpack which does this:
      
      <img width="1535" height="509" alt="Bildschirmfoto 2026-03-20 um 11 58 00" src="https://github.com/user-attachments/assets/f2864c86-ccce-4884-8417-c8ae06c05f78" />
      
      
      Closes PACK-6927
      Closes #91700
      Closes https://github.com/vercel/next.js/issues/91676
      118bdaf6
    • Joseph's avatar
      docs: post release amends (#91715) · 04cc2f2e
      Joseph authored
      Fixes based on feedback post release
      
      Fixes: https://github.com/vercel/next.js/pull/91715
      04cc2f2e
    • Tobias Koppers's avatar
      turbopack: move "compact database" tracing span to backend layer (#91693) · 47230b12
      Tobias Koppers authored
      ### What?
      
      Move the `"compact database"` tracing span from `turbo-persistence`
      (`db.rs`) to the backend layer
      (`turbo-tasks-backend/src/backend/mod.rs`), make it a root span, group
      it with the sibling `"persist"` span under a shared `"background
      snapshot"` root, and emit one span per compaction session rather than
      one per iteration.
      
      ### Why?
      
      The `compact()` function is called from the background persistence job,
      which runs inside a `"persisting background job"` span (inherited via
      `.in_current_span()` at task spawn time). Previously the `"compact
      database"` span was a child of that ambient span, making it appear
      nested under `"persisting background job"` in traces — inconsistent with
      its sibling spans `"snapshot"` and `"persist"`, which are already
      top-level root spans.
      
      Moving the span to the backend call site and giving it an explicit
      parent allows us to:
      
      1. Detach it from the `"persisting background job"` ambient span.
      2. Group it with the `"persist"` span under a shared `"background
      snapshot"` root span so all snapshot + compaction work appears together
      in trace viewers.
      3. Keep `turbo-persistence` free of span-policy decisions (root vs.
      child), which belong at the call site where the ambient span context is
      known.
      
      ### How?
      
      - Introduced a non-entered `background_span`
      (`tracing::info_span!(parent: None, "background snapshot")`) as a shared
      root for both the snapshot/persist work and the compaction loop.
      - Passed `background_span.id()` as the `parent_span` argument to
      `snapshot_and_persist`, so the `"snapshot"` and `"persist"` spans become
      children of it.
      - Inside the idle compaction loop, a child `"compact database"` span is
      entered and dropped synchronously around each `compact()` call (not
      across the `tokio::select!` await point).
      - Moved the span creation outside the `MAX_IDLE_COMPACTION_PASSES` loop
      so there is one `"compact database"` span per compaction session rather
      than one per iteration.
      - Removed the `tracing::info_span!("compact database")` span from
      `turbo-persistence/src/db.rs` entirely.
      - Downgraded the `"sync new files"` span from `info` to `trace` level
      (noise reduction).
      
      The non-entered `tracing::Span` is `Send`, so it can be safely held
      across the `select!` await without triggering the `future cannot be sent
      between threads safely` compile error that an `EnteredSpan` would cause.
      
      ---------
      Co-authored-by: 's avatarTobias Koppers <sokra@users.noreply.github.com>
      Co-authored-by: 's avatarClaude <noreply@anthropic.com>
      47230b12
    • Tobias Koppers's avatar
      turbo-persistence: remove Unmergeable mmap advice (#91713) · df886d4a
      Tobias Koppers authored
      ### What?
      
      Remove the `MADV_UNMERGEABLE` (Unmergeable) mmap advice from
      `turbo-persistence`'s `advise_mmap_for_persistence` helper in
      `mmap_helper.rs`.
      
      ### Why?
      
      The WSL (Windows Subsystem for Linux) kernel does not support
      `MADV_UNMERGEABLE` and returns an error when it is applied, causing
      turbo-persistence to fail on WSL. See:
      https://x.com/von_cronen/status/2034944304712392891
      
      Additionally, `MADV_UNMERGEABLE` is already the **default** state for
      memory pages — KSM (Kernel Same-page Merging) is opt-in via
      `MADV_MERGEABLE`. Explicitly setting `MADV_UNMERGEABLE` on pages that
      were never marked mergeable is a no-op on standard kernels, so the call
      provides no benefit while breaking WSL users.
      
      The `MADV_DONTFORK` advice is retained, as it has a clear correctness
      benefit (prevents mmap regions from being inherited by child processes
      on `fork()`).
      
      ### How?
      
      Removed the `mmap.advise(memmap2::Advice::Unmergeable)` call and its
      associated doc comment from
      `turbopack/crates/turbo-persistence/src/mmap_helper.rs`.
      Co-authored-by: 's avatarTobias Koppers <sokra@users.noreply.github.com>
      Co-authored-by: 's avatarClaude <noreply@anthropic.com>
      df886d4a
    • Hendrik Liebau's avatar
      Fix server actions in standalone mode with `cacheComponents` (#91711) · 8cbc0377
      Hendrik Liebau authored
      The `staticPathKey` condition added in #91231 inadvertently applies to
      server action requests on dynamic SSG routes when `cacheComponents` is
      enabled.
      
      Server action fetch requests from the client do not send the `RSC`
      header (`rsc: 1`). They only send `Accept: text/x-component` and the
      `Next-Action` header. This means `isRSCRequest` and
      `isDynamicRSCRequest` are both `false` for action requests. The new
      `staticPathKey` condition (`isSSG && pageIsDynamic &&
      prerenderInfo?.fallbackRouteParams`) evaluates to `true` for dynamic PPR
      routes, setting `staticPathKey` even though `ssgCacheKey` is `null` for
      actions.
      
      With `staticPathKey` set, the request enters the fallback rendering
      block, which serves the cached fallback HTML shell with the action
      result appended to it, instead of responding with just the RSC action
      result.
      
      The fix excludes server action requests from the `staticPathKey`
      computation by adding `!isPossibleServerAction` to the condition,
      restoring the pre-#91231 behavior where `staticPathKey` was always
      `null` for server actions in production.
      
      fixes #91662
      closes #91677
      closes #91669
      8cbc0377
    • Tobias Koppers's avatar
      Fix layout segment optimization: move app-page imports to server-utility transition (#91701) · 6a8a31a7
      Tobias Koppers authored
      ## Summary
      
      - Add `'turbopack-transition': 'next-server-utility'` to all server-side imports in the `app-page.ts` template so they are properly placed in the server utility layer, rather than relying on `SharedMerged` chunk groups to handle them
      - Remove the now-unnecessary `next-server-utility` transition from `fillMetadataSegment` import in `app_page_loader_tree.rs`
      - Add `SharedMultiple` chunk group variant to support multiple shared entries without a merge tag
        - This avoid passing the `parent` into `SharedMerged`, which did break the layout segment optimization.
      - Refactor `app_module_graphs` to combine `client_shared_entries` + `has_layout_segments` into a single `Option` parameter, simplifying the API and removing the dead code path for non-page endpoints
      
      ## Test plan
      
      - [ ] Verify dev and production builds work with app pages that have layout segments
      - [ ] Verify route handlers still build correctly (no client runtime entries passed)
      - [ ] Run existing app-dir e2e tests
      6a8a31a7
    • Abhishek Mardiya's avatar
      docs: fix broken Activity Patterns demo link in preserving UI state guide (#91698) · 883d93c8
      Abhishek Mardiya authored
      ## What?
      
      Fixes a broken link in the Preserving UI State guide:
      https://nextjs.org/docs/app/guides/preserving-ui-state#examples
      
      The "Activity Patterns demo" link currently points to a non-working URL.
      
      ## Why?
      
      The demo link returns a 404 / invalid page, which makes the example
      section confusing for readers.
      
      ## Changes
      
      - Updated the Activity Patterns demo link to the correct URL.
      
      ## Notes
      
      No functional changes, docs only.
      
      @icyJoseph @delbaoliveira
      883d93c8
    • Hendrik Liebau's avatar
      [test] Fix `edge-async-local-storage` deploy test timeout & race condition (#91643) · 542b2b02
      Hendrik Liebau authored
      The test was calling `createNext` inside each `it.each` test body, which
      meant deployment setup time counted against the 60-second per-test
      timeout introduced in #89929. In deploy mode, `createNext` deploys to
      Vercel which can exceed 60 seconds. When the test timed out, the `next`
      local variable was never assigned (the `await createNext(...)` hadn't
      resolved), so the `afterEach` hook would throw a `TypeError` on
      `next.destroy()`. This left the module-level `nextInstance` variable
      pointing at the stale, half-initialized deploy instance. When the next
      test case started, `createNext` saw the leftover `nextInstance` and
      threw `"createNext called without destroying previous instance"`.
      
      The test now uses `nextTestSetup`, which runs `createNext` in
      `beforeAll` where it has the longer 120-second `setupTimeout`. Both API
      route variants (`/api/single` and `/api/multiple`) are real fixture
      files served from a single instance, so deployment only happens once.
      542b2b02