1. 17 Sep, 2026 22 commits
    • next-js-bot[bot]'s avatar
      v16.4.0-canary.35 · 8a54c08e
      next-js-bot[bot] authored
      8a54c08e
    • Jiwon Choi's avatar
      Nudge the agents for future defaults adoption (#98721) · 3cf1f741
      Jiwon Choi authored
      Stacked on #98643.
      
      This PR adds `experimental.agenticAutoUpgrade = 'future'` config which
      enables nudging the agents to notify the user when there's unadopted
      future default(s). The nudge will include guiding to upgrade via `next
      upgrade --ai` (run "future" by detecting config).
      
      The method of nudging leverages the agents behavior where they tend to
      listen to messages from fatal errors that blocks the process compared to
      general error/warning logs. Whenever the agents run `next dev` or `next
      build`, Next.js will detect the condition and nudge the agent using this
      method.
      
      Afterwards it's up to the user whether to proceed the upgrade or not,
      it's 100% up to the user how to run it e.g. subagent, background agent,
      etc. and the process should not enforce any that affects user's
      workflow.
      
      Enabling `experimental.agenticAutoUpgrade = 'future'` also enables
      security check and latest version check.
      3cf1f741
    • Jiwon Choi's avatar
      Add future defaults upgrade coverage for `next upgrade --ai` (#98643) · d3d30cf8
      Jiwon Choi authored
      Stacked on #98640.
      
      This PR adds `next upgrade --ai="future"` flag, which is targeted to
      help users leverage agents to upgrade their app to adopt the future
      defaults when available. Just like latest version upgrade, it covers
      running codemods and a migration checklist for major-to-major upgrades
      to support breaking changes more reliably.
      
      This PR currently covers Cache Components only for the future default.
      d3d30cf8
    • Jiwon Choi's avatar
      Nudge the agents for latest version upgrade (#98640) · 457dfaa5
      Jiwon Choi authored
      Stacked on #98633.
      
      This PR adds `experimental.agenticAutoUpgrade = 'latest'` config which
      enables nudging the agents to notify the user when there's new
      major/minor Next.js version available to upgrade. The nudge will include
      guiding to upgrade via `next upgrade --ai` (run "latest" by detecting
      config).
      
      The method of nudging leverages the agents behavior where they tend to
      listen to messages from fatal errors that blocks the process compared to
      general error/warning logs. Whenever the agents run `next dev` or `next
      build`, Next.js will detect the condition and nudge the agent using this
      method.
      
      Afterwards it's up to the user whether to proceed the upgrade or not,
      it's 100% up to the user how to run it e.g. subagent, background agent,
      etc. and the process should not enforce any that affects user's
      workflow.
      
      Enabling `experimental.agenticAutoUpgrade = 'latest'` also enables
      security check.
      457dfaa5
    • Jiwon Choi's avatar
      Add "latest" upgrade coverage for `next upgrade --ai` (#98633) · 97496b20
      Jiwon Choi authored
      Stacked on #98637.
      
      This PR adds `next upgrade --ai="latest"` flag, which is targeted to
      help users leverage agents to upgrade their app to the latest major
      version when available. Just like security upgrade, it covers running
      codemods and a migration checklist for major-to-major upgrades to
      support breaking changes more reliably.
      97496b20
    • Jiwon Choi's avatar
      Nudge the agents for security vulnerable version upgrade (#98637) · 9bb13254
      Jiwon Choi authored
      Stacked on #98562.
      
      > [!TIP]
      > Recommended to review commit by commit.
      
      This PR adds `experimental.agenticAutoUpgrade = 'security'` config which
      enables nudging the agents to notify the user when the app's Next.js
      version has any security advisories. The nudge will include guiding to
      upgrade via `next upgrade --ai` (run "security" by detecting config).
      
      The method of nudging leverages the agents behavior where they tend to
      listen to messages from fatal errors that blocks the process compared to
      general error/warning logs. Whenever the agents run `next dev` or `next
      build`, Next.js will detect the condition and nudge the agent using this
      method.
      
      Afterwards it's up to the user whether to proceed the upgrade or not,
      it's 100% up to the user how to run it e.g. subagent, background agent,
      etc. and the process should not enforce any that affects user's
      workflow.
      9bb13254
    • Jiwon Choi's avatar
      Add `next upgrade --ai` and security vulnerability coverage (#98562) · 5d9ab72c
      Jiwon Choi authored
      > [!TIP]
      > Recommended to review commit by commit.
      
      This PR adds `next upgrade --experimental-ai="security"` flag (alias
      `--ai`), which is targeted to help users leverage agents to upgrade
      their app to the safe major version when their app's Next.js version has
      any security advisories.
      
      Once the command is ran from the user, Next.js will detect the installed
      agent harness in user's device, currently limited to Codex and Claude,
      and will proceed with starting an agent session once approved. If it is
      called within an agent session, the work will continue off within that
      agent.
      
      `next upgrade --ai` simply does two things:
      
      - prepare the relevant context to temporary dir
      - print hand off prompt, guiding to read those context
      
      The context will guide the agent to run relevant codemods and migration
      checklist to proceed. This PR is a base core of the workflow, and will
      have wrappers of entry point around this. Also, will add "latest" and
      "future" as follow up, which will cover the app to be always latest, and
      adopt the future defaults like Cache Components.
      
      This PR also sets up the evals infra and adds evals.
      5d9ab72c
    • Benjamin Woodruff ‮'s avatar
      agents: Add a `--comments-only` flag to `pr-status` script, trim down context… · 1ae49102
      Benjamin Woodruff authored
      agents: Add a `--comments-only` flag to `pr-status` script, trim down context bloat in AGENTS.md (#98781)
      
      - The `pr-status` can be very slow if you have a lot of test failures on
      a PR. If the user asks a targeted question about PR review comments,
      just fetch that information, it's much faster.
      - Context bloat: Rely on the agent to pull in the `pr-status-triage`
      skill if they need it, don't bloat the AGENTS.md, except to mention the
      skill.
      1ae49102
    • Tobias Koppers's avatar
      Keep guards across restore owner handoff (#98700) · a34c3030
      Tobias Koppers authored
      ### What?
      
      Prevent eviction or GC from clearing a task while the thread that
      restored it hands the task back to its caller.
      
      This is the first open layer in stack #98709. The construction-time GC
      pin it builds on has already landed through #98688.
      
      ### Why?
      
      A restore clears the category's `restoring` bit while still holding the
      task lock. The old code then dropped that lock so it could notify
      waiters without making them immediately contend on the same shard, and
      finally re-acquired the task guard for its caller.
      
      That creates a small but real gap: once the restoring bit is clear and
      the lock is dropped, the task is considered evictable. Concurrent
      eviction can remove the category before the restoring thread re-acquires
      it. The restore then returns a task that no longer contains the data it
      just loaded, leading to stale task references, missing task types, or
      incorrect values.
      
      The same interleaving exists for both single-task restoration and paired
      task access.
      
      ### How?
      
      Keep the existing task guard through `restored.notify(...)` and return
      that same guard directly. Pair access likewise retains both guards
      through notification.
      
      Notification only wakes listeners; it does not acquire task locks or
      wait for listeners to run, so retaining the guard cannot deadlock. Woken
      waiters may briefly contend until the restoring call returns, but there
      is no longer any unguarded interval in which eviction or GC can clear
      the newly restored category.
      
      This layer introduces no new state or pin accounting. The complementary
      waiter-side handoff is isolated in #98728.
      
      ### Verification
      
      - `cargo test -p turbo-tasks-backend --lib` (102 passed)
      - `cargo test -p turbo-tasks-backend --test eviction --test
      gc_resurrection --test gc_collection --test gc_interrupt --test
      gc_stress` (19 passed)
      - `cargo fmt -- --check`
      - `cargo clippy -p turbo-tasks-backend --tests -- -D warnings`
      
      Built on the construction pin merged in #98688. Followed by #98728.
      
      <!-- NEXT_JS_LLM -->
      
      
      <!-- fleet 6aa6acec-6286-4b03-86f4-13f4c7e2b2fa -->
      Co-authored-by: 's avatarvercel-fleet-prod[bot] <318278635+vercel-fleet-prod[bot]@users.noreply.github.com>
      Co-authored-by: 's avatarTobias Koppers <1365881+sokra@users.noreply.github.com>
      a34c3030
    • Jimmy Miller's avatar
      [turbopack] Track webpack loader build dependency files (#98777) · 7c366e61
      Jimmy Miller authored
      Track exact existing files and warn when loaders register unsupported
      build dependency inputs.
      
      I'm going to take this bit by bit so it is nice and reviewable. Does add
      some noise. But the final fully supported thing was just too large. So I
      will keep removing error cases on each commit.
      7c366e61
    • Tobias Koppers's avatar
      Replace lzzzz with lz4_flex (#98799) · e648495f
      Tobias Koppers authored
      ## What?
      
      Replace the direct `lzzzz` dependency used by Turbopack persistence with
      `lz4_flex` 0.14. The migration covers persisted blocks, the SST
      inspection utility, and optional compressed-size diagnostics in the task
      backend.
      
      ## Why?
      
      This removes the direct C/liblz4-backed codec dependency from these
      paths in favor of a Rust implementation. Persistence caches are scoped
      to the Next.js and Turbopack version, so this does not require a
      compatibility path for caches written by earlier versions.
      
      ## How?
      
      Persistence continues to use raw LZ4 blocks and the existing compression
      selection and checksum layout.
      
      A large thread-local `CompressTable` is reused across blocks. Starting
      with the large table costs about 8 KiB more per compression thread than
      the small table, but improves compression speed and produces LZ4 streams
      that are faster for `lz4_flex` to decode.
      
      The compressor retains the existing caller-owned buffer API. It clears
      and reserves the output vector, lets `lz4_flex` write directly into the
      uninitialized backing allocation, and exposes only the initialized byte
      count returned by the compressor. This avoids both per-call output
      allocations and pre-zeroing the maximum output size. Zstandard behavior
      is unchanged.
      
      ### Benchmark vs `lzzzz`
      
      The final PR configuration was benchmarked against `lzzzz` 2.0.0 using
      the repository-pinned Rust nightly. The benchmark used source-code
      blocks sampled from this repository, pinned each process to one physical
      CPU, measured thread CPU time, and alternated codec order within every
      paired round. The table reports the median across four physical cores
      and 20 paired rounds per process (480 paired rounds total).
      
      Each decoder read the output produced by its own encoder, matching how a
      same-version persistence cache is written and later read.
      
      | Source corpus | Block size | Compression | Decompression | Compressed
      size |
      | --- | ---: | ---: | ---: | ---: |
      | Mixed | 12 KiB | **7.1% faster** | 9.9% slower | 0.08% larger |
      | Rust | 12 KiB | **5.5% faster** | 10.4% slower | 0.09% larger |
      | TypeScript | 12 KiB | **7.4% faster** | 7.4% slower | 0.23% larger |
      | Mixed | 16 KiB | **5.9% faster** | 8.8% slower | 0.17% smaller |
      | Rust | 16 KiB | **4.6% faster** | 10.0% slower | 0.12% smaller |
      | TypeScript | 16 KiB | **6.7% faster** | 6.1% slower | 0.02% smaller |
      
      For these 12–16 KiB source blocks, `lz4_flex` compression was **4.6–7.4%
      faster**, decompression was **6.1–10.4% slower**, and compressed size
      changed by **-0.17% to +0.23%**.
      
      The benchmark was stable enough to support those codec-level ranges:
      wall time divided by thread CPU time was 1.000073 at the median and
      1.001883 at p99. The median difference between the two codec orders was
      0.38 percentage points for compression and 1.45 points for
      decompression.
      
      A separate decoder-only comparison fed identical `lzzzz`-encoded source
      blocks to both decoders; there, `lz4_flex` was 17–21% slower. The
      smaller regression in the table above comes from the large Flex
      compression table producing a different valid LZ4 token stream. The PR
      already uses `lz4_flex`'s supported unsafe pointer implementation with
      validation; a local experiment that removed validation recovered only
      5–6% and remained slower than liblz4, so this PR does not weaken decoder
      safety.
      
      These are codec microbenchmarks, not an end-to-end Turbopack speedup
      claim.
      
      ## Verification
      
      - `cargo fmt --all -- --check`
      - `cargo clippy -p turbo-persistence --all-targets -- -D warnings`
      - `cargo test -p turbo-persistence -- --test-threads=1` (110 passed)
      - `cargo check -p turbo-tasks-backend --features
      print_cache_item_size_with_compressed`
      - Pinned-nightly paired codec benchmark: 24 processes / 480 paired
      rounds
      
      <!-- NEXT_JS_LLM -->
      
      <!-- fleet 8f69f876-cb41-4fa2-ab60-dc8ccea88055 -->
      
      ---------
      Co-authored-by: 's avatarvercel-fleet-prod[bot] <318278635+vercel-fleet-prod[bot]@users.noreply.github.com>
      Co-authored-by: 's avatarBenjamin Woodruff ‮ <180404+bgw@users.noreply.github.com>
      Co-authored-by: 's avatarTobias Koppers <1365881+sokra@users.noreply.github.com>
      e648495f
    • Hendrik Liebau's avatar
      Fix metadata propagation for deduplicated nested caches (#98808) · d0df62e8
      Hendrik Liebau authored
      #94694 delayed shared metadata until handler writes settled to protect
      cross-request retries. Same-request consumers also awaited this promise,
      so an outer cache could save its result before inheriting the inner
      cache's root-param dependencies, tags, and lifetime.
      
      Metadata now becomes available when collection finishes. Cross-request
      key verification and pending-invocation cleanup still wait for handler
      writes to settle.
      
      The regression tests hold an inner write pending while both outer caches
      complete. They check metadata at write time and verify that a later
      request with different root params cannot reuse the earlier result. The
      fixtures disable startup preloading to isolate these tests from a
      separate custom-handler registration race that we'll address in a
      follow-up.
      d0df62e8
    • Niklas Mischkulnig's avatar
      Bump to swc v79 (#98809) · d5b615eb
      Niklas Mischkulnig authored
      There were a lot of parser and minifier fixes:
      https://github.com/swc-project/swc/compare/swc_core@v78.0.0...swc_core@v79.0.0
      d5b615eb
    • Janka Uryga's avatar
      [PPF] Fix unnecessary runtime prefetch with prefetch={true} (#98651) · 99083281
      Janka Uryga authored
      In, we #98278 attempted to fix runtime follow-ups for shells (if a
      static prefetch produced an insuffient shell).
      
      However, it introduced a regression in this scenario, where neither
      shells or prefetches use runtime data, so both of these links should use
      static prefetches:
      ```tsx
      <Link href="/static-param/one" prefetch={true} />
      {/* Revealed later */}
      <Link href="/static-param/two" prefetch={true} />
      ```
      
      We'd correctly do a static prefetch for the first link. However, the
      second link would see a `RuntimeShell`-tier shell from the first link,
      and this check inside `isShellEntryEligibleForStaticAttempt` would fail
      (because `RuntimeShell` was now greater than `PPR`):
      
      https://github.com/vercel/next.js/blob/3c9d1ca77f7de845315dc166a57fc9f090c638b4/packages/next/src/client/components/segment-cache/scheduler.ts#L1261
      as a result, `isShellEntryEligibleForStaticAttempt` would return
      `false`, and we would deopt to a runtime prefetch for the second link
      instead.
      
      Importantly, a page with `ensureStatic = "prefetch"`(which will be
      implemented in #98191) will currently be handled exactly like a page
      that did not use runtime data at build -- the client doesn't know that a
      page is meant to never use runtime requests at all, it's entirely based
      on the existing static hints/`needsRuntimeRequest` promise mechanism. So
      even if `/static/[slug]` sets `ensureStatic = "prefetch"`, we'd also do
      an unnecessary runtime prefetch for it even though we really shouldn't.
      Violating the `ensureStatic` contract seems worse than a missing runtime
      shell follow-up , because those can currently only happen if the shell
      starts using runtime data after a revalidation, and that's probably not
      a common scenario. So i'm partially reverting that change until we
      figure out how to handle this in a way that handles both cases correctly
      (i've attempted doing that, but it seems nontrivial)
      
      ### Testing
      
      We're now missing the runtime shell follow-up again, so tests related to
      that in `prefetch-app-shell-revalidation.test.ts` are marked as failing
      (but still assert on current behavior -- the follow-up failures can be
      reproduced by setting `REPRODUCE_MISSING_RUNTIME_SHELL_FOLLOW_UP=1`).
      Note that the runtime *prefetch* follow ups there work as expected --
      those worked correctly even before #98278.
      
      I've also added some pretty comprehensive tests in
      `prefetch-static-shell.test.ts`. We now test the scenario that
      regressed, which we weren't doing before. We also test scenarios where
      we reveal multiple links, but some of them use runtime data in the
      prefetch, and some don't. There's some failures there related to the
      fact that we don't track runtime data accesses in shells and prefetches
      separately (revealed by `REPRODUCE_UNNECESSARY_RUNTIME_SHELL=1`), which
      will be addressed by #98129. I want to land that before doing anything
      else on this topic to avoid dealing with failures that are going to be
      fixed soon anyway. There's also one case
      (`REPRODUCE_UNNECESSARY_RUNTIME_PREFETCH=1`) which will not be fixed by
      it, and will need separate consideration.
      99083281
    • Josh Story's avatar
      Keep metadata rendering stable across streaming modes (#97440) · 7d42c9dc
      Josh Story authored
      ## Motivation
      
      Streaming and blocking metadata previously used different rendering
      paths. Metadata placement should depend on when Next.js starts consuming
      the response, rather than requiring the metadata component itself to
      render outside Suspense.
      
      ## What this does
      
      Selected metadata now always renders through the same hidden Suspense
      boundary. For blocking responses, an always-present `MetadataBlocker`
      waits for the same cached resolution before Next.js pulls the response,
      ensuring metadata remains in the document head.
      
      `MetadataOutlet` remains a single promise. It renders inside Suspense
      for streaming responses and outside Suspense for blocking responses so
      navigation and regular errors retain their existing behavior.
      
      HTML-limited bot requests continue to bypass PPR shells. A prerendered
      shell has already closed its head before dynamic metadata resolves, so
      resuming that shell cannot provide blocking metadata in the raw head.
      
      ## Review notes
      
      - Metadata resolution still starts from a rendered component so the
      active `workUnitStore` and React cache scope are available.
      - Fizz may begin rendering before metadata settles; blocking is enforced
      before Next.js starts pulling the response.
      - The hidden wrapper keeps top-level suspenseful metadata out of the
      document preamble. Metadata tags hoist out, so the wrapper remains
      empty.
      - The Cache Components blocking and hydration coverage runs with
      parallel metadata both disabled and enabled.
      
      ## Verification
      
      - `pnpm build-all`
      - `pnpm test-start-turbo
      test/e2e/app-dir/metadata-streaming-cache-components/metadata-streaming-cache-components-custom-bots.test.ts`
      - `pnpm test-start-webpack
      test/e2e/app-dir/metadata-streaming-cache-components/metadata-streaming-cache-components-custom-bots.test.ts`
      
      <!-- NEXT_JS_LLM -->
      7d42c9dc
    • Hendrik Liebau's avatar
      [test] Expand root-param navigation regression coverage (#98731) · cb469ded
      Hendrik Liebau authored
      This extends the coverage for #98674 to root-param reads inside nested
      public caches and static-stage reuse during Cached Navigations.
      
      The tests verify that an initial document's extracted static stage is
      not reused across locales. A same-locale control verifies that reuse
      still works when only a fallback parameter changes.
      
      The cross-locale test checks the pending navigation state because the
      final dynamic response can otherwise hide incorrect static-stage reuse.
      cb469ded
    • Joseph's avatar
      docs: rewrite the bots and crawlers section in the caching guide (#98782) · fbe0d562
      Joseph authored
      ## Summary
      
      The Bots and crawlers section in the caching guide said that all bots
      and crawlers skip the static shell because "they need a complete
      document". Only HTML-limited bots do, and the reason is metadata: with
      Partial Prerendering, `generateMetadata` can resolve dynamically and
      stream in after the shell, which puts the tags in the body rather than
      the `<head>`. Bots that need them in the `<head>` get a dynamic render
      instead.
      
      The second paragraph now states the consequence directly: if the
      build-time prerender read something unreachable at request time, the
      render throws and those bots get a 500. Which user agents this covers,
      and the `htmlLimitedBots` option for changing the list, stay owned by
      the Streaming guide, which the section links to.
      
      🤖 Generated with [Claude Code](https://claude.com/claude-code)
      fbe0d562
    • Niklas Mischkulnig's avatar
      Fix isStableBuild() treating commit preview tarballs as stable (#98811) · 7395b29c
      Niklas Mischkulnig authored
      ## Summary
      
      Commit preview tarballs carry versions like
      `16.4.0-preview-84cee7e6-20260917` (no `canary` substring), so
      `isStableBuild()` treated them as stable and canary-only defaults
      (`turbopackSharedRuntime`, `turbopackMangleExportNames`) were disabled
      on what are canary-quality builds. Versions containing `-preview-` now
      count as unstable; numbered npm previews like `16.3.0-preview.10` stay
      stable.
      
      ## Verification
      
      - Added `canary-only-config-error.test.ts` covering the version matrix
      (fails on the tarball case without the fix)
      - `npx jest packages/next/src/server/config.test.ts` (existing consumer)
      passes
      
      <!-- NEXT_JS_LLM -->
      
      <!-- fleet ae573e35-b551-453d-af1c-548ffb598944 -->
      Co-authored-by: 's avatarvercel-fleet-prod[bot] <318278635+vercel-fleet-prod[bot]@users.noreply.github.com>
      7395b29c
    • Luke Sandberg's avatar
      perf(turbo-persistence): shard meta files by family (#97703) · 22fffea9
      Luke Sandberg authored
      ## Summary
      
      - Store live meta files in primary per-family shards so queries avoid
      unrelated-family metadata
      - Consolidate live metadata during compaction, retire subsumed meta
      files in the same commit, and retain merged used-key-hash AMQFs.
      - Add debug assertions for shard ownership/order and compaction
      precedence invariants.
      
      ## Performance
      
      Paired `LARGE_DB=1` Criterion binaries were run interleaved on the same
      machine to reduce host drift.
      
      | Scenario | Canary | PR | Result |
      | --- | ---: | ---: | --- |
      | Four-family cached `get` miss (100 metas/family) | 2.40–2.55 µs |
      2.11–2.21 µs | **~10–12% faster** |
      | Existing single-family cached `get` miss | 1.93–2.12 µs | 2.00–2.04 µs
      | Neutral within run-to-run noise (~+0.5% on means) |
      | Existing full compaction (4 Mi entries, 8 commits) | ~624 ms | ~624 ms
      | Neutral in the stable paired run; repeated samples stayed within
      normal noise |
      
      Read hits should see a small improvement but it isn't measurable, misses
      are the major benefit.
      
      ## Verification
      
      - `cargo test -p turbo-persistence`
      - `cargo test -p turbo-persistence --features stats`
      - `cargo clippy -p turbo-persistence --all-targets --features stats --
      -D warnings`
      - `LARGE_DB=1` interleaved Criterion A/B runs
      
      <!-- NEXT_JS_LLM -->
      
      ---------
      Co-authored-by: 's avatarvercel-fleet-prod[bot] <318278635+vercel-fleet-prod[bot]@users.noreply.github.com>
      Co-authored-by: 's avatarLuke Sandberg <210140+lukesandberg@users.noreply.github.com>
      22fffea9
    • Luke Sandberg's avatar
      turbo-persistence: assorted read-path cleanups (#97797) · 0f69132c
      Luke Sandberg authored
      ### What?
      
      Three small, localized optimizations to the read path. No behaviour or
      format changes.
      
      **Avoid contended atomic refcounts on the mmap** 
      - before we would inc/dec the mmap for the index block, the key bloc and
      then optionally the inline value of the key block
      - Now we front-load the index block 'parsing', borrow the key block
      (when it doesn't need decompression), and return inline values from key
      blocks by _value_ instead of reference
         
      
      **Hoist block cache access out of loops.** 
      - This is most impactful on misses, where we were touching the OnceLocks
      for every MetaFile
      
      **Make scanned data dense.** 
      - Reorganize `MetaEntry` to separate the hash ranges from the rest of
      the data
      - This improves the cache effectiveness of our hot 'entry scanning'
      loops since the stride is now 16 bytes instead of 144.
      
      ### Performance
      
      Interleaved A/B of this branch against its base (`LARGE_DB=1`, same
      machine, alternating runs, quiet host). Criterion medians:
      
      | benchmark | base | this branch | delta | rounds won |
      | --- | ---: | ---: | ---: | --- |
      | `get` miss, 20 commits uncompacted | 600 ns | 568 ns | **−5.4%** | 7/8
      |
      | `get` hit, 20 commits uncompacted | 1.415 µs | 1.398 µs | −1.2% | 4/4
      |
      | `get` hit, compacted | 996 ns | 979 ns | −1.7% | 2/4 |
      | `get` miss, compacted | 125.0 ns | 124.5 ns | −0.4% | 2/4 |
      
      Note: as single threaded benchmarks we are not really detecting any
      benefits from the refcount work, under concurrent reads we should expect
      an impact
      0f69132c
    • Luke Sandberg's avatar
      turbo-persistence: give key block searches a dense region of their own (#97705) · 875663cb
      Luke Sandberg authored
      ### What?
      
      Rearranges the bytes inside a key block so that the bytes a lookup's
      binary search compares are contiguous, instead of interleaved with key
      and value payload the search never reads.
      
      
      | block kind | before | after |
      | --- | --- | --- |
      | fixed, `HashThenKey` | `[hash\|key\|val]*n` | `[hash]*n` then
      `[key\|val]*n` |
      | fixed, `KeyOnly` | `[key\|val]*n` | `[key]*n` then `[val]*n` |
      | variable, `HashThenKey` | `[type\|pos]*4B` then `[hash\|key\|val]…` |
      `[hash\|type\|pos]*12B` then `[key\|val]…` |
      
      
      ### Why?
      
      The binary search routines are a random access pattern through the
      hash/key ranges, we only need to look at value payloads when we find a
      plausible match. So by organizing all the 'random access data' in denser
      memory range we optimize cache/page fault behavior.
      
      
      `get` perf impacts are small but real.
      
      | shape | in-block search before → after | as % of a ~1070 ns `get()` |
      | --- | --- | --- |
      | key=8, value=4 inline | 166 → 146 ns | 1.9% |
      | key=4, small value ref | 144 → 119 ns | 2.4% |
      
      The reason the impacts are small is mostly because the 'working sets' of
      the benchmarks are not large enough and the page size of macos is quite
      large.
      875663cb
    • Luke Sandberg's avatar
      Introduce config options for Turbopack GC (#98378) · bf13ab8a
      Luke Sandberg authored
      ### What?
      
      Replaces the Turbopack GC environment variables with an
      `experimental.turbopackGc`
      config option
      
      ```js
      // next.config.js
      experimental: {
        turbopackGc: true,                                      // on, defaults
        turbopackGc: { minProgressMs: 100, rootTtlMs: 432e6 },  // on, tuned
      }
      ```
      
      This replaces the env vars which were unused and not the ergonomic
      bf13ab8a
  2. 16 Sep, 2026 14 commits
    • next-js-bot[bot]'s avatar
      v16.4.0-canary.34 · a30ad8fa
      next-js-bot[bot] authored
      a30ad8fa
    • Luke Sandberg's avatar
      Store code generation AST paths in a shared trie (#98581) · 74e159fb
      Luke Sandberg authored
      ### What?
      
      Store the AST paths that code generation uses to locate nodes in a
      per-module trie, referenced by a 4-byte id, instead of a
      `Vec<AstParentKind>` per path.
      
      ### Why?
      
      Ast paths can share long prefixes leading to quadratic behavior (in
      pathological cases), even in non pathological cases there can be
      redundancy.
      
      Peak memory on a repro of 180 files, each with a 1200-term chain:
      
      | | peak | compile |
      |---|---|---|
      | before | 24.0 GB | 19.1 / 17.4 / 16.5s |
      | after | 4.0 GB | 13.7 / 14.2 / 14.8s |
      
      And on an ordinary app (`vercel-site`, 5,669 files; 5 cold runs +
      warmup):
      
      | | baseline | this branch |
      |---|---|---|
      | user time | 321.00 s ±0.8% | 321.30 s ±0.8% |
      | MaxRSS | 14,984 MB ±0.4% | 14,755 MB ±0.4% |
      
      ### How?
      
      The trie is built lazily, interning only the paths code generation asks
      for, so it stays sparse. A builder holds the child index during analysis
      and is frozen into an immutable trie stored beside the code gens.
      
      `ApplyVisitors` previously sorted the full paths and binary searched
      them at every level; it now descends the trie alongside the AST walk.
      Consumers that manipulated paths structurally walk it instead —
      `EsmBinding` steps to a parent rather than popping, and `removal.rs` and
      `code_gen::path_to` trim from the end without allocating.
      
      Interning was profiled separately. Sorting paths first, embedding the
      child map in each node, resuming interning from the previous path, and
      moving `Effect`'s paths into a second trie were all measured and
      rejected: each was slower, needed more memory, or was inside the noise.
      Interning is not a hot path.
      
      Ideally we would also intern the paths stored in the temporary `Effect`
      enum, but this is a pure time/memory tradeoff. We can massively reduce
      pressure on the arena in exchange for a 10% perf regression. Not worth
      it.
      
      
      <!-- NEXT_JS_LLM -->
      
      ---------
      Co-authored-by: 's avatarClaude Opus 5 (1M context) <noreply@anthropic.com>
      74e159fb
    • Benjamin Woodruff ‮'s avatar
      Turbopack: Remove wasmer from lockfile by deleting dead feature option from our wasm crate (#98761) · 02f3bebc
      Benjamin Woodruff authored
      Apparently we don't support swc plugins when using the wasm binary, and
      this feature flag is never used. It was causing wasmtime to show up in
      our lockfile.
      
      Actual impact on compilation time is likely zero, as we never enabled
      this feature.
      02f3bebc
    • Luke Sandberg's avatar
      Prefer using join over try_join when you don't want a vec (#98547) · 16c8ea5d
      Luke Sandberg authored
      Adopt `join` over `try_join` in a number of places to avoid temporary
      Vec allocations
      
      `try_join` always copies a `Vec<Result<T>>` to a `Result<Vec<T>>` which
      is sometimes convenient but at least sometimes wasteful if you are
      immediately transforming into another collection type.
      
      Adopt it to turn `primary_modules` into a `SmallVec` since in the vast
      majority of cases there is only one module and so we can save a bunch of
      allocations of tiny arrays
      
      ---------
      Co-authored-by: 's avatarClaude Opus 5 (1M context) <noreply@anthropic.com>
      16c8ea5d
    • Alex Langenfeld's avatar
      Preserve committed app route response status during fallback (#98649) · 93bb22ad
      Alex Langenfeld authored
      ### What?
      
      A follow up to https://github.com/vercel/next.js/pull/94979, now we
      check if response headers have already been sent before trying to send a
      `500` response when falling back.
      
      ### Why?
      
      To get streaming respnses that already sent status `200` headers from
      reporting as `500`s in telemetry.
      
      ### How?
      
      Skip the fallback `500` status response if headers have already been
      sent.
      
      ---------
      Signed-off-by: 's avatarAlex Langenfeld <alex.langenfeld@vercel.com>
      93bb22ad
    • Joseph's avatar
    • Niklas Mischkulnig's avatar
      fix(next-custom-transforms): never place generated imports before directives (#98717) · bdbf63ae
      Niklas Mischkulnig authored
      ## Summary
      
      **What?** Fixes the error reported for a module that has a top-level
      `"use client"` directive and an inline `"use server"` function
      directive, e.g. `<form action={async () => { "use server" }} />` in a
      client page.
      
      **Why?** Under Turbopack this reported a bogus error — `The "use client"
      directive must be placed before other expressions` — even though the
      directive was already at the top of the file. The actual mistake (an
      inline server action inside a Client Component) was never surfaced.
      
      **How?** On Turbopack's RSC layer the server actions transform runs
      *before* the React Server Components assert. When it hoists an inline
      action it prepended its generated imports (`registerServerReference`,
      action encryption, cache runtime) at index 0 of the module — *above* the
      `"use client"` directive, which the transform does not consume. The RSC
      assert then saw an import before the directive and reported it as
      misplaced.
      Co-authored-by: 's avatarvercel-fleet-prod[bot] <318278635+vercel-fleet-prod[bot]@users.noreply.github.com>
      bdbf63ae
    • Jimmy Miller's avatar
      Pin tasks during construction (#98688) · 6cfca45f
      Jimmy Miller authored
      I got a failure in CI for the stress test that pointed to this as the
      cause. During construction, since the task has no references to it, it
      can be collected. Setting the transient ref prevents this bad case from
      happening.
      
      @lukesandberg I'm going to work on the gc at each suspend point in a
      follow up PR.
      6cfca45f
    • Arya's avatar
      fix(use-cache): track root params read in "use cache" as vary params (#98674) · f1a7e1db
      Arya authored
      ### What?
      
      A `"use cache"` segment that reads a root param via `next/root-params`
      is reused after a client-side navigation that changes that param. With
      `cacheComponents`, a production build and `<Link prefetch={false}>`:
      open `/en`, click `de`. URL, `usePathname()` and layout say `de`; the
      page segment still says `en`.
      
      ### Why?
      
      Inside a `"use cache"` scope, `getRootParam` only records the name in
      `readRootParamNames`, which keys the server cache entry. Nothing
      forwards it to the response's root vary params, so the client re-keys
      the segment as `Fallback` and reuses it for every locale. `await params`
      masks the bug because serializing the cache key touches the tracked
      params object.
      
      ### How?
      
      `propagateCacheEntryMetadata` adds `readRootParamNames` to the outer
      store's root vary accumulator when one exists. The client already unions
      root vary params into every segment.
      
      Not covered: `"use cache: private"` root-param reads are only tracked in
      dev, so the same reuse can still happen there in production.
      
      Review order: `use-cache-wrapper.ts` is the whole change (one block
      after the propagation switch, plus the doc note above
      `maybePropagateCacheEntryMetadata`). The fixture adds a `[locale]` route
      under the existing `vary-params` app.
      
      Test: `vary-params.test.ts`, "does not reuse a "use cache" segment
      across root param values", fails with `Received: "Locale: en"` before
      the fix. Reporter's repro renders `de` after navigation on the patched
      package.
      
      Fixes #98493
      
      cc @unstubbable @lubieowoce (use cache vary params)
      
      <!-- NEXT_JS_LLM -->
      f1a7e1db
    • Hendrik Liebau's avatar
      [test] Fix Webpack deployment failures in PostCSS tests (#98710) · c92542c9
      Hendrik Liebau authored
      #98527 enabled deployment coverage for a Turbopack-only fixture, but
      `skipStart` did not prevent deployment during `setup()`. The suite now
      uses `@force-gate turbopack` to skip setup for other bundlers while
      preserving Turbopack deployment coverage.
      
      This fixes the failure in
      https://github.com/vercel/next.js/actions/runs/35037213782/job/104625995824.
      c92542c9
    • Tim Neutkens's avatar
      Revert "Fix App Router locale path matching with Pages i18n" (#98715) · 52788bdf
      Tim Neutkens authored
      Reverts vercel/next.js#98095
      
      A stale merge of #98095 caused failures on canary:
      https://github.com/vercel/next.js/actions/runs/35075051322Co-authored-by: 's avatarHendrik Liebau <mail@hendrik-liebau.de>
      52788bdf
    • next-js-bot[bot]'s avatar
      v16.4.0-canary.33 · c7094123
      next-js-bot[bot] authored
      c7094123
    • Tim Neutkens's avatar
      Fix App Router locale path matching with Pages i18n (#98095) · 1d5dd672
      Tim Neutkens authored
      ## Summary
      
      Fix hybrid App Router and Pages Router projects using Pages i18n so
      explicit or rewritten locale segments remain available to App Router
      route matching, while Pages routes continue using locale-normalized
      paths.
      
      The built-in filesystem matcher now carries each route owner through
      `RouteKind`, avoids duplicate App routes being treated as Pages routes
      in production, and preserves literal App path parameters through the
      router server, direct route-module invocation, and static export paths.
      The same ownership information is maintained by the development bundler.
      
      Adds regression coverage for domain locales, proxy rewrites, exact and
      dynamic App pages, catch-all parameters, route handlers, inferred
      default locales, and Pages routes. Adapter-generated routing metadata is
      intentionally handled in the follow-up layers #97366 and #97500.
      
      Closes #86048
      
      ## Verification
      
      - `pnpm build-all`
      - `NEXT_TEST_PREFER_OFFLINE=1 pnpm test-start-webpack
      test/e2e/app-dir/i18n-app-pages-domain-routing/i18n-app-pages-domain-routing.test.ts`
      (9 passed)
      - Prettier and ESLint checks on all changed files
      
      <!-- NEXT_JS_LLM -->
      1d5dd672
    • next-js-bot[bot]'s avatar
  3. 15 Sep, 2026 4 commits
    • next-js-bot[bot]'s avatar
      v16.4.0-canary.32 · 90515901
      next-js-bot[bot] authored
      90515901
    • Tobias Koppers's avatar
      fix(turbopack): trace cyclic modules to explicit entries (#98661) · 2a3bf9ae
      Tobias Koppers authored
      ### What?
      
      Makes Turbopack import tracing recognize the module graph's explicit
      entries as roots, including when an entry participates in an import
      cycle. Adds focused graph-level coverage and a Next.js production
      fixture that exercises issue formatting through a cyclic graph.
      
      If a malformed graph still has no path to any explicit entry, tracing
      now returns a minimal trace and emits a bug-severity issue instead of
      panicking.
      
      ### Why?
      
      The import tracer inferred roots from nodes with no incoming edges. A
      valid cycle that points back to an entry gives every node an incoming
      edge, so the tracer could not find a root and panicked while formatting
      another diagnostic. The graph already records its entries explicitly,
      making them the authoritative and cycle-safe definition of a root.
      
      The same topology-based assumption affected entry membership checks, so
      those now use the explicit entry list as well.
      
      ### How?
      
      - Resolve import-trace paths against node indices derived from
      `GraphEntries`.
      - Preserve a defensive fallback for malformed graphs and classify that
      invariant violation as an implementation bug.
      - Cover cyclic entry paths, malformed rootless graphs, absent paths, and
      the product-level issue-formatting path.
      
      Fixes #98205
      
      <!-- NEXT_JS_LLM -->
      
      
      <!-- fleet 25b26044-3397-4642-a77f-c565b7577046 -->
      
      ---------
      Co-authored-by: 's avatarvercel-fleet-prod[bot] <318278635+vercel-fleet-prod[bot]@users.noreply.github.com>
      Co-authored-by: 's avatarTobias Koppers <1365881+sokra@users.noreply.github.com>
      2a3bf9ae
    • Tobias Koppers's avatar
      Use default pnpm package import method (#98703) · f1285cec
      Tobias Koppers authored
      ### What?
      
      Use pnpm's default package import method in the two hoisted
      isolated-test configurations added by #98425.
      
      ### Why?
      
      `package-import-method` controls how regular package files are
      materialized from pnpm's store: by reflink, hardlink, or copy. Those
      choices do not affect `realpath`, so forcing copies is unrelated to the
      Node.js symlink-resolution workaround and unnecessarily disables pnpm's
      more efficient defaults.
      
      ### How?
      
      Keep `node-linker=hoisted`, which is the setting responsible for
      producing npm-style real package directories, while removing the
      independent copy policy. The Node-version gate, local-tarball
      validation, release-age policy, and fixture behavior remain unchanged.
      
      ### Verification
      
      - Hoisted-only scratch install produced real package directories, no
      package symlinks outside `.bin`, and a metadata-only `.pnpm`
      - Production Turbopack: non-hoisted SWC helper and warm-restart task
      stats passed (2/2)
      - `pnpm build`
      - `pnpm types`
      - Prettier, ESLint, and `git diff --check`
      
      Follow-up to #98425 and
      https://github.com/vercel/next.js/pull/98425#discussion_r4020168942.
      
      <!-- NEXT_JS_LLM -->
      
      
      <!-- fleet 81cd457d-6956-4cf9-b6f6-9ebf9d95f285 -->
      Co-authored-by: 's avatarvercel-fleet-prod[bot] <318278635+vercel-fleet-prod[bot]@users.noreply.github.com>
      Co-authored-by: 's avatarTobias Koppers <1365881+sokra@users.noreply.github.com>
      f1285cec
    • Tobias Koppers's avatar
      Fix constant inlining in shorthand properties (#98662) · 69d11874
      Tobias Koppers authored
      ### What?
      
      Fixes constant replacement in object shorthand properties and adds
      focused Turbopack execution coverage for the existing analyzer-aware
      cross-module constants path.
      
      ### Why?
      
      This is a pre-existing bug in `ConstantValueCodeGen`, which is shared by
      the current analyzer-aware/opt-in constants implementation and the newer
      codegen-only export-inlining work. When an imported constant is used as
      `{ VALUE }`, the AST path ends at `Prop::Shorthand`; the old
      expression-only visitor could replace the enclosing object literal,
      collapsing `{ FIRST, SECOND }` to a single primitive.
      
      This fix is intentionally independent of the export-inlining feature
      stack so existing `turbopackCrossModuleConstants` users receive and
      review the correction separately.
      
      ### How?
      
      When the code-generation path ends at a shorthand property, it now
      mirrors `EsmBinding`: the shorthand is expanded to a key/value property,
      preserving the original key and generating the compile-time constant
      only for the value. Other expression paths are unchanged, and generated
      values retain the standard compile-time marker.
      
      The execution fixture uses only analyzer-aware constants. Without the
      fix it returns `"second"` instead of `{ FIRST: "first", SECOND: "second"
      }`; with the fix it verifies the runtime object, both generated keys,
      and both marked inlined values.
      
      ### Verification
      
      - `NODE_PATH=/vercel/sandbox/test-deps/node_modules cargo test -p
      turbopack-tests --test execution cross_module_constants_shorthand --
      --nocapture`
      - `cargo test -p turbopack-tests --test snapshot cross_module --
      --nocapture`
      - `cargo check -p turbopack-ecmascript -p turbopack-tests --tests`
      - `cargo fmt --all -- --check`
      
      <!-- NEXT_JS_LLM -->
      
      
      <!-- fleet 29433e1c-e26e-435a-b516-45108f629d79 -->
      Co-authored-by: 's avatarvercel-fleet-prod[bot] <318278635+vercel-fleet-prod[bot]@users.noreply.github.com>
      Co-authored-by: 's avatarTobias Koppers <1365881+sokra@users.noreply.github.com>
      69d11874