1. 20 Mar, 2026 22 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
    • Hendrik Liebau's avatar
      [test] Unflake rendering indicator test & skip building indicator tests (#91650) · 9f181bd1
      Hendrik Liebau authored
      [Flakiness
      metric](https://app.datadoghq.com/ci/test/runs?query=test_level%3Atest%20%40git.repository.id%3A%22github.com%2Fvercel%2Fnext.js%22%20%40test.name%3A%28%22Build%20Activity%20Indicator%20Enabled%20-%20%28app%29%20Shows%20build%20indicator%20when%20page%20is%20built%20from%20modifying%22%20OR%20%22Build%20Activity%20Indicator%20Enabled%20-%20%28pages%29%20Shows%20build%20indicator%20when%20page%20is%20built%20from%20modifying%22%20OR%20%22Dev%20Rendering%20Indicator%20Shows%20build%20indicator%20when%20page%20is%20built%20from%20modifying%22%29%20%40test.status%3Afail&agg_m=count&agg_m_source=base&agg_t=count&fromUser=false&index=citest&start=1773322068865&end=1773926868865&paused=false)
      
      In #85083 we introduced a delay of 400 ms before showing the
      building/rendering indicator, to avoid flashing it for fast operations.
      For now, we skip the building indicator tests because our simple test
      apps usually compile much faster than that, and we haven't found a good
      way to reliably test the indicator without flakiness. We do keep the
      rendering indicator test, but increase the timeout in the pages to
      ensure the indicator is shown for long enough to be detected by the
      test.
      9f181bd1
    • Luke Sandberg's avatar
      [turbopack] Optimize compaction cpu usage (#91468) · 8e9f9514
      Luke Sandberg authored
      ## Summary
      
      Optimizes the turbo-persistence compaction and iteration paths with several targeted improvements:
      
      ### Iterator optimizations
      
      - **Flatten index block iteration** — The iterator previously used a `Vec<CurrentIndexBlock>` stack, but SST files have exactly one index level. Inline the index block fields (`index_entries`, `index_block_count`, `index_pos`) directly into `StaticSortedFileIter`, eliminating the stack allocation and `Option` overhead.
      
      - **Non-optional `CurrentKeyBlock`** — Parse the first key block during `try_into_iter()` construction so `current_key_block` is always populated, removing the `Option<CurrentKeyBlock>` wrapper and its `take()`/`Some()` ceremony in the hot loop.
      
      - **Replace `ReadBytesExt` with direct byte indexing** — In `handle_key_match`, `parse_key_block`, and `next_internal`, replace `val.read_u16::<BE>()` etc. with `u16::from_be_bytes(val[0..2].try_into().unwrap())`. This eliminates th mutable slice pointer advancement.
      
      - **Extract `read_offset_entry` helper** — Read type + offset from the key block offset table in a single `u32` load + shift, replacing two separate `ReadBytesExt` calls.
      
      
      ### Refcounting optimization
      
      - **Introduce `RcBytes`** — Thread-local byte slice type using `Rc` instead of `Arc`, eliminating atomic refcount overhead during single-threaded SST iteration. The iteration path (`StaticSortedFileIter`) now produces `RcBytes` slices backed by an `Rc<Mmap>`, so per-entry clone/drop operations are plain integer increments rather than atomic operations.
      
      
      ### Merge iterator simplification
      
      - **Optimize `MergeIter::next`** — Replaced the straightforwards `pop/push` pattern with `PeekMut`-based replace-top pattern, which means we only need to adjust the heap once per iteration instead of twice.
      
      ## Benchmark results
      
      ### Compaction (`key_8/value_4/entries_16.00Mi/commits_128`)
      
      | Benchmark | Canary | Optimized | Change |
      |-----------|--------|-----------|--------|
      | partial compaction | 1.949 s | 1.515 s | **-22%** |
      | full compaction | 2.051 s | 1.542 s | **-25%** |
      
      ### Read path (`static_sorted_file_lookup/entries_1000.00Ki`)
      
      No read regression — the branch is neutral to slightly faster:
      
      | Benchmark | Canary | Optimized | Change |
      |-----------|--------|-----------|--------|
      | hit/uncached | 6.73 µs | 6.59 µs | **-2%** |
      | hit/cached | 140.8 ns | 130.7 ns | **-7%** |
      | miss/uncached | 5.10 µs | 5.02 µs | **-2%** |
      | miss/cached | 230.1 ns | 233.1 ns | ~+1% (noise) |
      
      ## Test plan
      
      - [x] `cargo test -p turbo-persistence` — 60/60 tests passing
      - [x] Compaction benchmarks run and compared against canary baseline
      - [x] Read path (lookup) benchmarks verified no regression
      8e9f9514
  2. 19 Mar, 2026 18 commits