1. 14 Sep, 2026 12 commits
    • next-js-bot[bot]'s avatar
      v16.4.0-canary.30 · 12748456
      next-js-bot[bot] authored
      12748456
    • Jiwon Choi's avatar
      Expose App Router runtime errors over HMR (#98438) · 4d925698
      Jiwon Choi authored
      Ported from #98040 by @marcoshernanz.
      
      > [!TIP]
      > Best reviewed commit by commit.
      
      ### Why?
      
      External development tools need browser runtime-error state, not just
      build errors, to display application failures. Reporting remains opt-in
      so applications that do not need it avoid client serialization, HMR
      transport, server formatting, buffering, and rebroadcast overhead.
      
      ### How?
      
      Add `experimental.exposeRuntimeErrorsToHMR` for App Router development
      with Webpack and Turbopack. Internal integrations can also enable the
      same behavior without changing `next.config` by setting
      `__NEXT_EXPOSE_RUNTIME_ERRORS_TO_HMR` to any non-empty value. When
      enabled, the HMR WebSocket emits `runtimeErrors` snapshots containing:
      
      - The current pathname and browser client/document identifiers.
      - Error types, names, messages, and source-mapped stacks.
      - Fatality and optional catching-boundary details (`default-global`,
      `custom-global`, or `custom`).
      
      Snapshots update as errors and navigation change. New or reconnected
      observers receive the current state, and disconnecting a browser clears
      its reported errors. An empty snapshot means there are no currently
      reported errors; it does not guarantee application recovery.
      
      Reporting is disabled by default. Pages Router, MCP `get_errors`, and
      production behavior are unchanged.
      
      <!-- NEXT_JS_LLM -->
      Co-authored-by: 's avatarMarcos Hernanz <96699542+marcoshernanz@users.noreply.github.com>
      4d925698
    • Tobias Koppers's avatar
      test: avoid OpenTelemetry collector socket reuse (#98632) · 3c9d1ca7
      Tobias Koppers authored
      ### What?
      
      Prevent the OpenTelemetry instrumentation e2e collector from losing span
      exports when an exporter reuses an idle localhost connection. Add
      focused coverage for the collector's connection behavior.
      
      ### Why?
      
      Keeping the collector listener alive for each application's full
      lifetime removed the earlier close-and-rebind gap, but did not eliminate
      every socket failure. Node's HTTP server could still time out an idle
      keep-alive socket retained by the exporter's Undici pool. A later export
      could race that closure, lose spans with `UND_ERR_SOCKET` or
      `ECONNRESET`, and leave otherwise unrelated trace assertions with
      incomplete trees.
      
      The canary.28 failure was investigated separately and is not this
      mechanism: it occurred in the release-enabled Rspack matrix when a
      custom server exited during startup. This change is limited to the
      residual non-Rspack collector race and does not alter Rspack coverage or
      release snapshots.
      
      ### How?
      
      Successful collector exports explicitly close their HTTP connection.
      Each export therefore uses a fresh local connection instead of retaining
      a socket that the server may reclaim while idle. The regression test
      asserts this response contract directly, avoiding timing-dependent
      coverage of the race.
      
      ### Verification
      
      - Node 20.9.0, webpack dev, React 18.3.1: 5 consecutive focused runs, 55
      tests passed per run
      - Node 20.9.0, webpack start, React 18.3.1: 99 passed, 13 existing skips
      - `pnpm test-types`
      - Prettier and ESLint on changed files
      
      <!-- NEXT_JS_LLM -->
      
      
      <!-- fleet e4b8ed15-4a06-4727-a634-fddcc27c11fc -->
      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>
      3c9d1ca7
    • Ross Sullivan's avatar
    • Jiwon Choi's avatar
      Document codemod errors and intentional migration exceptions (#98565) · 996f957c
      Jiwon Choi authored
      Stacked on #98560.
      
      ### Why?
      
      Users need to distinguish unfinished codemod repairs from intentional
      feature-adoption opt-outs.
      
      ### How?
      
      Document `@next-codemod-error` and temporary `UnsafeUnwrapped*` casts in
      the codemod guide, with examples and a link to the Async Request APIs
      migration guide. Explain when an inapplicable suggestion can be marked
      `@next-codemod-ignore` with a reason.
      
      Show the ignore comment emitted for Cache Components opt-outs and
      explain that it does not block compilation.
      996f957c
    • Jiwon Choi's avatar
      Unify TODO markers for codemods and skip adoption-only codemods for upgrade (#98560) · b0ba92cb
      Jiwon Choi authored
      ### Why?
      
      Async Request API codemods can leave temporary casts that still require
      application-specific repairs. Those locations need explicit markers,
      while optional feature adoption needs to be distinguishable from
      required version migrations.
      
      ### How?
      
      Add `@next-codemod-error` comments to temporary `UnsafeUnwrapped*`
      casts, with instructions for completing the repair. Preserve documented
      ignores and avoid duplicating casts or markers when the transform runs
      again. Mark generated Cache Components opt-outs with
      `@next-codemod-ignore`, a removal condition and a link to the adoption
      guide.
      
      Add `upgrade --skip-adoption` to skip the Cache Components `instant =
      false` transform and partial-prefetch adoption cleanup. Required
      migrations and normal dependency and bundler selection keep their
      existing behavior. Both adoption transforms can still be run explicitly.
      b0ba92cb
    • Tobias Koppers's avatar
      Optimize strict module factory chunks (#98421) · 39f5d797
      Tobias Koppers authored
      ### What?
      
      Reduce Turbopack ECMAScript chunk size by emitting strict module
      factories in a shared strict-mode scope instead of repeating `"use
      strict"` in every factory.
      
      The chunk format now chooses among the existing flat representation, a
      mixed representation with flat non-strict factories plus a nested strict
      array, and an all-strict representation that wraps the complete chunk in
      a strict IIFE. Each factory is generated through the existing single
      code path; the production minimizer removes its redundant directive when
      the factory is created inside a strict wrapper. Browser and Node.js
      emitters share the mode selection and serialization implementation,
      while the runtime remains compatible with the existing flat format.
      
      ### Why?
      
      ECMAScript modules are always strict, so large chunks currently repeat
      the same directive across many factories. Moving strictness to the scope
      where those factories are created removes redundant bytes without
      copying arrays or changing strict/sloppy execution semantics.
      
      For `bench/basic-app`, this reduces total raw JavaScript by 16,831 bytes
      (0.161%). Partitioning factories changes compression behavior, resulting
      in a 1,286-byte (0.051%) gzip increase across all JavaScript; format
      selection therefore remains based on emitted raw bytes.
      
      ### How?
      
      - Determine each chunk item's strictness from the already-collected
      chunk metadata.
      - Generate every factory once with its normal directive, then rely on
      the minimizer to remove redundant directives inside strict wrappers.
      - Compare the expected minified directive bytes removed with the exact
      wrapper bytes added and keep small chunks in the existing flat format.
      - Keep non-strict factories flat in mixed chunks and append strict
      factories as an array produced by a strict IIFE.
      - Wrap the complete registration/export in a strict IIFE when every
      factory is strict, keeping those factories flat and avoiding a nested
      array entirely.
      - Use the shorter arrow IIFE when the target supports it, with a
      function IIFE fallback for older targets.
      - Preserve source-map sections, scope-hoisted module IDs, factory
      naming, and ordering within each partition.
      - Add focused strict, sloppy, mixed, all-strict, old-target, and
      below-threshold coverage and update affected Turbopack snapshots.
      
      ### Verification
      
      - `cargo nextest run -p turbopack-tests -E 'test(snapshot)'`
      - `cargo clippy -p turbopack-ecmascript -p turbopack-browser -p
      turbopack-nodejs`
      - `pnpm build-all`
      - `pnpm --dir turbopack/crates/turbopack-ecmascript-runtime/js
      check:nodejs`
      - `bench/basic-app` production Turbopack build, repeated to confirm
      deterministic size totals
      
      <!-- NEXT_JS_LLM -->
      
      
      <!-- fleet 528ffe69-eb27-466b-a132-842272a782cf -->
      
      ---------
      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>
      39f5d797
    • Tobias Koppers's avatar
      Sort batched chunk items globally by path (#98433) · df1502c7
      Tobias Koppers authored
      ### What?
      
      Globally order all emitted Turbopack ECMAScript chunk items by module
      path, including items nested inside batches. Browser and Node.js chunk
      emitters now consume the same flattened, ordered result.
      
      ### Why?
      
      The previous ordering compared only the first module in each item or
      batch group. Remaining modules in a batch stayed together even when
      their paths belonged elsewhere in the global order, reducing locality
      between similar modules and slightly worsening gzip compression.
      
      For `bench/basic-app`, production JavaScript chunk gzip sizes changed as
      follows while raw bytes and chunk counts stayed unchanged:
      
      | Output | Before | After | Change |
      |---|---:|---:|---:|
      | Browser chunks | 1,619,643 B | 1,619,314 B | -329 B (-0.020%) |
      | Server chunks | 792,379 B | 792,186 B | -193 B (-0.024%) |
      | Combined | 2,412,022 B | 2,411,500 B | -522 B (-0.022%) |
      
      ### How?
      
      The shared ECMAScript chunk-content accessor now flattens resolved item
      and batch groups and sorts every module by `(path, module id)`. Keeping
      this ordering in the shared layer gives browser and Node.js output
      identical deterministic behavior and removes duplicated emitter-side
      sorting.
      
      ### Verification
      
      - `cargo fmt --all -- --check`
      - `cargo check -p turbopack-browser -p turbopack-nodejs`
      - `cargo test -p turbopack-browser -p turbopack-nodejs`
      - `pnpm build-all`
      - Clean baseline and candidate production builds of `bench/basic-app`
      
      <!-- NEXT_JS_LLM -->
      
      
      <!-- fleet d30d9e3f-6885-4665-ae08-b37fa6151b95 -->
      
      ---------
      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>
      df1502c7
    • next-js-bot[bot]'s avatar
      v16.4.0-canary.29 · 156050f1
      next-js-bot[bot] authored
      156050f1
    • Niklas Mischkulnig's avatar
      Durable use cache: fix runtime env var mutation (#98558) · 164d9c19
      Niklas Mischkulnig authored
      ### Problem
      1. Next computes the warmup cache key while `SOME_ENV_VAR` is unset.
      2. Rendering ends up setting `SOME_ENV_VAR`.
      3. Final prerender expects the cache entry to exist, but the env var
      changed, so the key changed and it's a miss.
      4. Unexpected miss and bailout.
      
      This lead to
      ```
      Error: Route "foo": Unexpected cache miss after cache warming phase during prerendering. This is
      likely caused by non-deterministic arguments that differ between the cache warming phase and the
      final prerender phase (e.g. unstable array order). Ensure that arguments passed to cached functions
      are deterministic.
      
      Error: Route "foo": Next.js encountered uncached or runtime data during
      prerendering.
      ```
      
      ### Solution
      
      ~~Instead, snapshot the env vars once at module evaluation time of the
      `use cache` function. This ensures that the cache key doesn't change
      over time. This is also how it worked thus far (with deployment id as
      the cache key): changing the env var over the lifetime of the process
      didn't lead to a reexecution of the `use cache` function~~
      
      RDC already stores cache entries generated in the previous phase (be it
      during `next build` multi-phase rendering, or from prerender->resuming
      at runtime). Root params are already excluded from the cache keys when
      storing in RDC. Also exclude the env var hash bit, to conform to this
      system of preventing tearing (at the cost of potential staleness).
      164d9c19
    • Niklas Mischkulnig's avatar
      refactor(turbopack): drop the generic on `new_atom`, and stop it copying an owned string (#98520) · 729ff712
      Niklas Mischkulnig authored
      ### What?
      
      Follow-up to the review comments on #98497.
      
      `new_atom` loses its generic parameter and takes a `Cow<'_, str>`, which
      as a side effect stops it
      copying a string it was handed ownership of. `FileSystemPath`'s
      `get_relative_request_to` stops
      hand-rolling a conversion the standard `From` impl already does, and the
      two tests added for it in
      `path.rs` are replaced by one that covers what that layer actually adds.
      
      ### Why?
      
      @bgw noted that `get_relative_request_to` was matching on the `Cow` it
      gets back only to call
      `.into()` in both arms, and wondered whether `impl From<Cow<'_, str>>
      for RcStr` was missing a fast
      path for the owned case.
      
      It was not missing one, and it never needed one — but an owned string
      *was* being copied, for a
      different reason. `new_atom` was generic over `T: AsRef<str> +
      Into<String>` and opened with
      `let text = text.as_ref();`, which shadows the owned value. From that
      point on only a `&str` was in
      scope, so building the `Box<str>` allocated a fresh buffer and copied
      into it, dropping the `String`
      that a `Cow::Owned` had just handed over.
      
      So this is not a fast path being added. It is an accidental
      pessimisation being removed: the generic
      plus the `as_ref()` were exactly what stopped the standard conversion
      from doing the right thing on
      its own. Whether that copy ever mattered in practice is a separate
      question, and one this does not
      attempt to answer.
      
      The other two comments were about the tests: they re-ran the case table
      that already lives in
      `turbo-unix-path`, which is where the path computation itself is
      implemented and tested — "60 LOC to
      test a 3 LOC branch".
      
      ### How?
      
      `new_atom` takes a `Cow<'_, str>`. All five of its callers already
      passed one, so nothing else
      changes, and ownership now survives to where the `Box<str>` is built —
      `Box<str>`'s own
      `From<Cow<'_, str>>` moves an owned buffer in and copies only a borrowed
      one. The inline-atom path is
      untouched, since it reads through a `&str` either way and does not
      allocate.
      
      Contents-based assertions cannot distinguish a moved buffer from a
      copied one, so the test compares
      the data pointer before and after the conversion. It uses a string
      longer than `MAX_INLINE_LEN`,
      because an inline atom stores its bytes in the tagged value by design
      and could never preserve a
      pointer, and it asserts the atom really is dynamic so it cannot pass
      vacuously if that boundary ever
      moves. It fails on `canary` today.
      
      `get_relative_request_to` collapses to a single `.into()`. Its sibling
      `get_relative_path_to` keeps
      its match on purpose: one arm uses `std::ptr::eq` to hand back a clone
      of the `RcStr` the path
      already holds, which the blanket conversion cannot do. That arm predates
      #98497 and is an
      optimisation rather than the redundancy that was flagged.
      
      For the tests, `turbo-unix-path` remains the place where the relative
      path computation is covered,
      untouched. What is left here is only what this layer adds on top: that
      each method reaches for the
      form it names, and that neither returns a path across filesystems.
      Keeping the first of those is a
      judgement call — a method delegating to the wrong free function is
      precisely the bug #98497 existed
      to fix, and it is invisible to the lower-level table — so it is asserted
      with one descendant pair
      rather than a table. Happy to drop it entirely if you would rather.
      
      To check that the smaller test still earns its place,
      `get_relative_request_to` was temporarily
      pointed at the plain-path function; the test fails as it should.
      
      <!-- NEXT_JS_LLM -->
      
      <!-- fleet 3acc7e63-52a8-4472-89cd-b1bbb8ad59fa -->
      
      ---------
      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>
      729ff712
    • Tobias Koppers's avatar
      Serialize turbo-tasks trybuild tests (#98415) · c2e4f05f
      Tobias Koppers authored
      ### What?
      
      Run all `turbo-tasks-macros-tests` trybuild fixture groups through one
      test process and one generated Cargo project lifecycle.
      
      ### Why?
      
      Trybuild uses one generated Cargo project per package. Cargo-nextest
      previously launched the five test groups as separate processes, allowing
      them to overwrite that project's manifest while another group was
      compiling. On canary this surfaced as diagnostics from the wrong
      fixture, missing `trybuild00N` bin targets, and compile-fail cases
      incorrectly succeeding.
      
      The tracked stderr snapshots are correct; the instability is in
      concurrent harness execution rather than compiler output or the SWC
      version.
      
      ### How?
      
      A single `TestCases` instance now queues every existing pass and
      compile-fail glob. This preserves per-fixture diagnostics and coverage
      while preventing cross-process manifest collisions. A comment documents
      the shared-project invariant so the groups are not split into concurrent
      tests again.
      
      ### Verification
      
      - `cargo nextest run -p turbo-tasks-macros-tests --cargo-profile
      release-with-assertions --no-fail-fast`
      - `cargo fmt --all -- --check`
      - `git diff --check`
      
      <!-- NEXT_JS_LLM -->
      
      
      <!-- fleet ae1d9ec9-156e-4b53-80c0-f24bf0b22f13 -->
      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>
      c2e4f05f
  2. 12 Sep, 2026 2 commits
    • next-js-bot[bot]'s avatar
      v16.4.0-canary.28 · 748cc4a6
      next-js-bot[bot] authored
      748cc4a6
    • Tobias Koppers's avatar
      test: stabilize OpenTelemetry collector lifecycle (#98427) · 10f370c1
      Tobias Koppers authored
      ## What?
      
      Stabilize the OpenTelemetry instrumentation e2e suite by keeping its
      local span collector available for each application's full lifetime.
      Reset collected span state between tests without closing the collector,
      and cover continuity across a test boundary.
      
      ## Why?
      
      The suite kept Next.js and custom-server exporters alive across tests
      while closing and rebinding their collector port after every test.
      Exports during that gap failed with closed/reset/refused socket errors
      before trace assertions timed out or observed incomplete trees. Aligning
      the collector lifetime with the exporter removes that race instead of
      masking it with retries, longer timeouts, or weaker assertions.
      
      ## How?
      
      - Start the collector before starting each managed application.
      - Keep the listener bound until application teardown, while clearing
      only buffered spans in `beforeEach`.
      - Replace per-test collector reconnects across the affected suites and
      remove the disabled-fetch suite's fixed teardown delay.
      - Assert that one collector remains connected, resets its state, and
      receives a fresh trace across sequential tests.
      
      ## Verification
      
      - Webpack dev / React 18.3.1: 5 consecutive focused runs, 54 tests
      passed per run
      - Webpack start / React 18.3.1: 5 consecutive focused runs, 97 passed
      and 13 existing skips per run
      - `pnpm test-types`
      - Prettier and ESLint on the changed files
      
      <!-- NEXT_JS_LLM -->
      
      <!-- fleet c7f6c6e4-56b2-4648-bc2d-88b2f256bb7a -->
      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>
      10f370c1
  3. 11 Sep, 2026 16 commits
    • Will Binns-Smith's avatar
      Make TurbopackResult payloads disjoint (#98575) · d5276f04
      Will Binns-Smith authored
      ### What?
      
      Refactors the JavaScript-facing `TurbopackResult<T>` into a stable
      wrapper whose payload lives under `value` and whose issues remain
      top-level. Native API consumers, entrypoint conversion,
      development-server paths, HMR handling, and direct API tests now follow
      the disjoint shape.
      
      Two event subscriptions that had inaccurate wrapper declarations now
      expose their existing plain runtime payloads explicitly: update-info
      events remain `UpdateMessage`, and compilation events remain
      `CompilationEvent`. Nullable native entrypoint payloads are also
      declared accurately and normalized at the JavaScript API boundary.
      
      ### Why?
      
      The previous intersection-based representation merged payload fields
      with result metadata. That allowed fields such as `issues` to overwrite
      one another and caused non-object payloads to be discarded, making the
      result shape depend on `T`. A dedicated payload property avoids those
      collisions and preserves every payload type, including `null`.
      
      Keeping plain event streams distinct from result wrappers also ensures
      `TurbopackResult<T>` consistently means the native API actually provides
      wrapper metadata.
      
      ### How?
      
      The N-API serializer now always creates a fresh wrapper rather than
      mutating an object payload. The shared TypeScript type models that
      wrapper directly and requires an explicit payload type. Conversion
      layers replace only the nested payload while explicitly preserving
      wrapper issues. Call sites continue to process wrapper issues while
      reading domain data through `value`.
      
      The update-info and compilation-event declarations were aligned with
      their native callback types instead of introducing new runtime wrappers
      for streams that do not collect issues. Rust `Option<NapiEntrypoints>`
      payloads are declared as nullable, then normalized to the existing
      empty-entrypoints representation after a null-safe route check.
      
      ### Verification
      
      - `pnpm build-all`
      - `pnpm --filter=next types`
      - `pnpm swc-build-native`
      - `cargo check -p next-napi-bindings`
      - `cargo fmt --all -- --check`
      - ESLint and Prettier on changed files
      - `pnpm test-dev-experimental-turbo
      test/development/app-aspath/app-aspath.test.ts`
      - `pnpm test-dev-turbo test/development/basic/next-rs-api.test.ts` — 26
      passed, 1 skipped, 15 snapshots; Jest reported lingering open handles
      after the green summary
      - `pnpm test-dev-turbo
      test/development/app-dir/concurrent-install/concurrent-install.test.ts`
      - `pnpm test-dev-experimental-turbo
      test/development/app-dir/concurrent-install/concurrent-install.test.ts`
      
      <!-- NEXT_JS_LLM -->
      
      <!-- fleet 74688340-f99a-462e-8f75-88d12c88000a -->
      
      ---------
      Co-authored-by: 's avatarvercel-fleet-prod[bot] <318278635+vercel-fleet-prod[bot]@users.noreply.github.com>
      Co-authored-by: 's avatarWill Binns-Smith <755844+wbinnssmith@users.noreply.github.com>
      d5276f04
    • next-js-bot[bot]'s avatar
      v16.4.0-canary.27 · d4c9abe0
      next-js-bot[bot] authored
      d4c9abe0
    • Niklas Mischkulnig's avatar
      Durable use cache: optimize env var existence checks (#98504) · f41441a0
      Niklas Mischkulnig authored
      We now separately track code that accesses non-inlined env vars at
      runtime in two categories
      - (existing) actual reads, the full value is accessed
      - (new) only unset/falsy/truthy is read at runtime
      
      For the second case, we only need to invalidate use-cache functions when
      the given env var transitioned betwen unset/falsy/truthy. But
      transitioning between two different truthy values doesn't caused
      invalidation.
      f41441a0
    • Jimmy Miller's avatar
      Adds this.mode for webpack loaders (#98532) · 30d6d8f4
      Jimmy Miller authored
      Pretty straightforward. But a number of loaders depend on it including
      
      - postcss-loader
      - sass-loader
      - stylus-loader
      - vue-loader
      - nunjucks-loader
      - thread-loader
      30d6d8f4
    • next-js-bot[bot]'s avatar
    • Steven's avatar
      feat(next/image): Add experimental imgOptMozjpeg config (#98571) · deed8684
      Steven authored
      In a previous PR, `mozjpeg` was set to true which might be the reason
      output jpeg spikes cpu.
      
      - https://github.com/vercel/next.js/pull/65846
      
      I made a benchmark and found that disabling MozJPEG saved 72% CPU, with
      average outputs 31% larger.
      
      - https://github.com/lovell/sharp/issues/4603
      
      So this PR adds a new experimental flag to enable (or rather disable)
      mozjpeg and try with real workloads. This is useful becaues in many
      cases, cpu is more costly than bandwidth since most CDNs provide [near
      unlimited bandwidth](https://vercel.com/blog/introducing-flat-rate-cdn).
      deed8684
    • Jimmy Miller's avatar
      [turbopack] Lazily compile dynamic imports in development (client side) (#97203) · d155ba9e
      Jimmy Miller authored
      ## Summary
      
      Defer compiling client-side dynamic import targets in Turbopack
      development until the browser requests their manifest chunk. This avoids
      compiling untouched dynamic imports while preserving server-side
      imports, CSS loading, Server Actions, source maps, and Fast Refresh
      behavior.
      
      
      One caveat on this is next/dynamic still does some eagerness. I looked a
      bit at changing things. But it breaks some of the guarantees there and
      decided to leave it off the table.
      
      ---------
      Co-authored-by: 's avatarNiklas Mischkulnig <4586894+mischnic@users.noreply.github.com>
      d155ba9e
    • Joseph's avatar
      fix(devtools): handle pointercancel when dragging the indicator (#98506) · c5741d52
      Joseph authored
      Fixes #98468
      
      ## Claude explanation of the fix
      
      `useDrag` listened for `pointermove` and `pointerup`, but never
      `pointercancel`.
      
      When a user agent cancels a gesture — a browser or system gesture takes
      over, a second finger arrives — it fires `pointercancel` and no
      `pointerup`, implicitly releasing pointer capture as it does. So
      `cancel()` never ran: the state machine stayed `{ state: 'drag' }` and
      `cleanup.current` was never invoked, leaving the
      `pointermove`/`pointerup` listeners on `window`.
      
      The next `pointerup` anywhere on the page then hit those orphaned
      listeners, reached `cancel()` with the state still `'drag'`, and called
      `releasePointerCapture()` on a pointer that no longer existed — the
      reported `NotFoundError`. Each cancelled drag also leaked another
      listener pair.
      
      This registers `pointercancel` alongside `pointerup` and removes it in
      the same cleanup, so the machine unwinds when a gesture is cancelled;
      and it releases pointer capture only when `hasPointerCapture()` says it
      is still held, which is preferable to `try/catch` swallowing genuine
      faults too.
      
      Note `touch-action: none` (#97723) removed the common touch trigger, but
      not the defect: on canary a forced `touchCancel` still throws.
      
      
      https://github.com/user-attachments/assets/45a9524d-9ffa-40b6-b59a-5af9d947f8c7
      
      ## Fixed version
      
      
      https://github.com/user-attachments/assets/b5ada68c-7442-42ef-a256-bacc512fbeca
      
      ## Browser checks
      
      - [x] Chrome, as describe by the bug report
      - [x] FF works fine pre and post fix (with and without the pointer
      simulation)
      - [x] iOS safari simulator, before the fix, I can't see an error, but,
      the drag gets frozen, with this fix it works correctly
      
      
      https://github.com/user-attachments/assets/bcfdc786-bada-4462-b530-299523fdca6d
      
      🤖 Generated with [Claude Code](https://claude.com/claude-code)
      
      ---------
      Co-authored-by: 's avatarClaude Opus 5 (1M context) <noreply@anthropic.com>
      c5741d52
    • Sebastian "Sebbie" Silbermann's avatar
      [ci] Show full logs under GitHub Actions debug logging (#98501) · 2d417dae
      Sebastian "Sebbie" Silbermann authored
      Logs of passed tests are hidden by default in CI.
      There's an argument to be made to always show them in CI. For now we
      just wire up GitHub's built-in "re-run with debug logging enabled" to
      show logs of passed tests.
      
      <img width="1358" height="936" alt="CleanShot 2026-09-10 at 19 00 18@2x"
      src="https://github.com/user-attachments/assets/70fb9c56-c681-4394-958b-7fa9aea19970"
      />
      Co-authored-by: 's avatarClaude Code (kimi-k3[1m]) <noreply@anthropic.com>
      2d417dae
    • James Argarin's avatar
    • Sebastian "Sebbie" Silbermann's avatar
      [test] Fix `proxy-request-with-middleware` deploy test (#98553) · 64596d1f
      Sebastian "Sebbie" Silbermann authored
      The fixture's API route proxies the incoming request to
      `http://<host>/api/post`. On Vercel, that plain-HTTP hop hits the edge's
      http→https upgrade and the handler pipes the resulting 308 back to the
      test client, which then has to replay the POST body across the redirect.
      Node.js' fetch implementation cannot replay bodies across 307/308
      redirects and fails the request with
      `UND_ERR_REQ_CONTENT_LENGTH_MISMATCH`, which broke this test in deploy
      mode after the test harness switched from `node-fetch` to global `fetch`
      in #98195.
      
      This change proxies over `https` when `VERCEL_URL` is set so no
      client-visible redirect occurs, while local dev and start modes are
      unaffected since they keep using plain HTTP.
      
      Fixes
      
      ```
      TypeError: fetch failed
      
            29 |         'x-custom-header': 'some value',
            30 |       }
          > 31 |       const res = await fetchViaHTTP(next.url, `api`, '', {
               |                   ^
            32 |         method: method.toUpperCase(),
            33 |         headers,
            34 |         body: method.toLowerCase() !== 'get' ? body : undefined,
      
            at Object.<anonymous> (e2e/proxy-request-with-middleware/test/index.test.ts:31:19)
      
          Cause:
          RequestContentLengthMismatchError: Request body length does not match content-length header
      ```
      --
      https://github.com/vercel/next.js/actions/runs/34543344283/job/103105861941#step:35:555
      64596d1f
    • Sebastian "Sebbie" Silbermann's avatar
      [ci] Remove the broken Test examples workflow and its test suite (#98517) · 033bc32c
      Sebastian "Sebbie" Silbermann authored
      Removes the `Test examples` workflow and its orphaned test suite. The
      workflow fails every scheduled run: its pinned Playwright docker image
      (v1.35.1) is incompatible with the Playwright version the repo now
      requires (v1.61.0), so the browser cannot launch. It also no longer runs
      what it was created for: since the `run-tests.js` glob root moved from
      `test/` to the repository root, the `--type examples` string-prefix
      filter `examples/` matches test files inside example apps instead of
      `test/examples/examples.test.ts`, leaving that suite without any runner.
      
      This deletes `.github/workflows/test_examples.yml`, the `test/examples/`
      suite, and the `--type examples` filter in `run-tests.js`. The
      `examples/` prefix stays in the default-run exclusion list so test files
      inside example apps (which run with each example's own jest/vitest
      setup) are still not picked up by bare `run-tests.js` invocations.
      Co-authored-by: 's avatarClaude Code <noreply@anthropic.com>
      033bc32c
    • Hendrik Liebau's avatar
      Align fallback parameter staging with shell validation (#98512) · 1a295a63
      Hendrik Liebau authored
      `next dev` reported missing Suspense boundaries in layouts that the
      build accepted. For `/[top]/items/[bottom]`, `generateStaticParams`
      returned `[{ top: 't1' }]`, and the page wrapped its `bottom` access in
      Suspense. A request for `/t2/items/b2` still reported the layout's
      access to `top` as an error. Development treated both parameters as
      unresolved because the requested `top` value was not generated, although
      the required static shell only needed to defer `bottom`.
      
      Production Cached Navigations used the same overly broad parameter set
      and omitted eligible static content from repeat visits. Resumes also
      reconstructed that set from the original build manifest, even after an
      on-demand prerender had produced a more complete shell.
      
      This replaces the alternative proposed in #98460. That proposal fixes
      the development error by selecting a separate fallback parameter set for
      validation while keeping response staging unchanged. The two sets are
      not intended to differ for the same shell target. Correcting only
      validation would preserve the incorrect staging decision and leave
      production Cached Navigations without the eligible static content.
      
      Staging and static-shell validation now use one `stagedFallbackParams`
      set for each selected shell target. Required partial shells retain their
      unresolved parameters, even when a later request can complete them.
      Prerenders record their parameter set in postponed state, and resumes
      use that recorded set rather than reconstructing it from the generic
      source.
      
      Dynamic RSC requests now read and revalidate the completed-shell cache
      key, so they find partial artifacts that the fully resolved pathname
      lookup missed. Request metadata and `RequestStore` both expose the set
      as `stagedFallbackParams`. Action-only fallback detection checks actual
      unresolved parameters instead of treating deferred values as missing.
      1a295a63
    • Hendrik Liebau's avatar
      Prevent synchronous IO from entering Cached Navigations (#98511) · 79daac38
      Hendrik Liebau authored
      Cached Navigations incorrectly reused uncached timestamps as static page
      content. A repeat visit showed the previous request's `Date.now()`
      result while the new response was still pending. This affected both
      dynamic RSC responses and the RSC payload embedded in the initial HTML.
      
      The production renderer left synchronous IO untracked because it assumed
      the build had already checked it. A private cache exposed the gap: the
      static prerender suspended at the cache call and never reached the
      `Date.now()` after it. A production request resolved the private cache
      during the static stage and included the uncached timestamp in the
      reusable response.
      
      Production staged renders now end the static stage when synchronous
      request-time IO occurs. They mark the interrupted static and shell
      prefixes as empty, while the rest of the response renders normally. The
      client skips those prefixes instead of waiting for a Flight root that
      the interrupted stage may not have emitted.
      
      The regression tests cover dynamic RSC navigation, initial HTML
      hydration, and full prefetching with a paramless private-cache fixture.
      79daac38
    • Sebastian "Sebbie" Silbermann's avatar
      [ci] Fix scheduled Rspack test job (#98508) · 4e906f16
      Sebastian "Sebbie" Silbermann authored
      This workflow is responsible for periodically updating the manifest. The
      workflow broke in https://github.com/vercel/next.js/pull/97590 since the
      [called workflow requires `pull_request:
      write`](https://github.com/vercel/next.js/blob/626ab223bae3f9b29b3ec8cbd18a58d86b871ec1/.github/workflows/integration_tests_reusable.yml#L172)
      to open the update PR.
      
      Fixes
      ```
      [Invalid workflow file: .github/workflows/rspack-nextjs-build-integration-tests.yml#L10](https://github.com/vercel/next.js/actions/runs/34439645923/workflow)
      The workflow is not valid. .github/workflows/rspack-nextjs-build-integration-tests.yml (Line: 10, Col: 3): Error calling workflow 'vercel/next.js/.github/workflows/integration_tests_reusable.yml@334052ffbb383395b74cac6a90e0b15c7317957b'. The nested job 'collect_nextjs_development_integration_stat' is requesting 'pull-requests: write', but is only allowed 'pull-requests: none'.
      ```
      -- https://github.com/vercel/next.js/actions/runs/34439645923
      4e906f16
    • Sebastian "Sebbie" Silbermann's avatar
      [ci] Remove Turbopack test manifest pipeline (#98507) · 87edae59
      Sebastian "Sebbie" Silbermann authored
      The manifest is no longer considered for skipping test since
      https://github.com/vercel/next.js/pull/81170. It also didn't update
      anymore automatically so I removed updating areweturboyet.com which was
      broken for a while now anyway when we switched away from static tokens.
      87edae59
  4. 10 Sep, 2026 10 commits
    • next-js-bot[bot]'s avatar
      v16.4.0-canary.26 · ccef3db5
      next-js-bot[bot] authored
      ccef3db5
    • Jimmy Miller's avatar
      Add in warning for workers around the fsevents bug (#98447) · 637b8cfa
      Jimmy Miller authored
      We removed this because we fixed the original crashes. This crash does
      not happen out of the box. But it isn't hard to trigger with plugins.
      And we'd rather not have people experience this without being explicit.
      637b8cfa
    • Aurora Scharff's avatar
      skill: add Partial Prefetching optimizer (#96471) · 393de1eb
      Aurora Scharff authored
      ## Summary
      
      - add a Partial Prefetching optimizer Skill for selected source Links
      and destinations
      - keep prefetch stages and Link policy in the public [Optimizing
      prefetching
      guide](https://nextjs.org/docs/app/guides/optimizing-prefetching), and
      rely on the same static-shell documentation as the Cache Components
      optimizer for cache placement, Suspense, loading UI, and authorization
      - keep the Skill focused on the product decision, production `instant()`
      loop, differential verification, and mutation freshness when an
      optimization adds a cache around mutable data
      - reference the canonical
      [`unstable_prefetch()`](https://nextjs.org/docs/app/api-reference/functions/prefetch)
      and
      [`unstable_navigation()`](https://nextjs.org/docs/app/api-reference/functions/navigation)
      docs instead of explaining the APIs again in the Skill
      - link cache-writing optimizations to the canonical
      [Revalidating](https://nextjs.org/docs/app/getting-started/caching-and-revalidating#revalidating)
      documentation and verify a populated-cache mutation in the Skill and
      eval
      - bundle a self-contained production rig aligned with the related
      adoption and optimizer Skills, tuned to record each source-link and
      prefetch-stage contract
      - add an eval that compares baseline, the bundled guide, and the local
      Skill against the same prefetched-UI and cache-freshness goal
      - document the optimizer in the AI agents guide
      
      This follows the same guide/Skill split as #97737. Partial Prefetching
      adoption preserves existing behavior; this optimizer is the later
      decision about what is worth preparing before a click and what should
      wait for navigation.
      
      Related: #97712, #97737, #97759, #98122, #98175
      
      ## Eval
      
      One run per treatment with Claude Opus 4.8 and Claude Sonnet 4.5, using
      a fixed Claude Haiku 4.5 judge. The bundled-guide and Skill treatments
      use a local Next.js tarball containing the new guide and API references.
      
      | Model | Treatment | Criteria | Score change | Overall | Duration |
      Tokens processed | Total run cost | Cost change |
      | --- | --- | ---: | ---: | ---: | ---: | ---: | ---: | ---: |
      | Opus 4.8 | Baseline | 10/10 (100%) | — | Pass | 18m 42s | 3.39M |
      $3.46 | — |
      | Opus 4.8 | Bundled guide | 9/10 (90%) | -10 pp | Fail | 13m 37s |
      3.02M | $2.84 | -18.0% |
      | Opus 4.8 | Local Skill | 10/10 (100%) | +10 pp | Pass | 17m 22s |
      2.80M | $2.54 | -10.6% |
      | Sonnet 4.5 | Baseline | 2/10 (20%) | — | Fail | 15m 55s | 1.97M |
      $1.06 | — |
      | Sonnet 4.5 | Bundled guide | 5/10 (50%) | +30 pp | Fail | 15m 49s |
      2.17M | $1.11 | +4.5% |
      | Sonnet 4.5 | Local Skill | 8/10 (80%) | +30 pp | Fail | 15m 31s |
      1.41M | $0.77 | -30.4% |
      
      Token totals count each unique model message once and include uncached
      input, cache creation, cache reads, and output. Cache reads account for
      most of the total in every treatment. Total run cost applies the current
      AI Gateway base rates to each token category: Opus 4.8 costs $5/M input,
      $6.25/M cache writes, $0.50/M cache reads, and $25/M output; Sonnet 4.5
      costs $3/M input, $3.75/M cache writes, $0.30/M cache reads, and $15/M
      output. The six agent runs cost $11.78 in total.
      
      Compared with baseline, the Opus Skill run maintained a 100% criteria
      pass rate while reducing cost by 26.7%. The Sonnet Skill run improved
      the criteria pass rate from 20% to 80%, a 60 percentage-point increase,
      while reducing cost by 27.3%.
      
      The stronger model could solve the fixture without the Skill, although
      it independently searched the bundled Next.js documentation and took
      slightly longer than the Skill treatment. The Opus guide-only run
      implemented the correct behavior but missed the required
      RED-before-GREEN proof.
      
      The Sonnet treatments show a clearer progression. Baseline did not
      implement the required caching, navigation stage, `instant()` contract,
      or cache invalidation. The bundled guide added the cached summary and
      production test, but missed the navigation stage, deferred-state
      assertions, tag invalidation, and RED-before-GREEN proof. The Skill
      treatment completed the `instant()` RED-to-GREEN loop and final
      production behavior, but left `connection()` in the related-sessions
      read and used path revalidation instead of tagging the cached read. It
      therefore passed 8 of 10 criteria but failed the overall eval.
      
      All six measured runs completed through grading. Chromium and its system
      dependencies are provisioned before the agent starts, so missing browser
      libraries did not determine these results.
      
      ## Verification
      
      - `pnpm --filter=next build`
      - `pnpm prettier --check` for the changed guide, prompt, Skill, and eval
      fixture
      - `pnpm exec tsc -p
      evals/evals/agent-051-optimize-partial-prefetching/tsconfig.json
      --noEmit`
      - `node --check run-evals.js`
      - `git diff --check`
      - packed a local Next.js tarball and confirmed it contains the optimizer
      guide plus the `navigation()` and `prefetch()` references
      - verified the `navigation()` contract in the minimal reproduction and
      NextBeats on Next.js 16.4.0-canary.22
      - merged the latest `canary`, preserving both generic fixture setup and
      Playwright provisioning
      
      <!-- NEXT_JS_LLM -->
      393de1eb
    • Will Binns-Smith's avatar
      bundle-analyzer: add table view to single-build analyzer (#93523) · 6fbba169
      Will Binns-Smith authored
      Extends the view toggle (introduced in the previous PR for compare mode)
      to single-build mode as well. The table view lists all sources for the
      selected route with sizes and env badges. Internally it reuses
      `DiffTable` in `mode="single"` by diffing the build against itself,
      which produces an all-`identical` summary — this keeps a single
      source-listing implementation regardless of mode.
      
      <!-- NEXT_JS_LLM_PR -->
      Co-authored-by: 's avatarvercel-fleet-prod[bot] <318278635+vercel-fleet-prod[bot]@users.noreply.github.com>
      Co-authored-by: 's avatarWill Binns-Smith <755844+wbinnssmith@users.noreply.github.com>
      6fbba169
    • Will Binns-Smith's avatar
      bundle-analyzer: add table view to compare mode (#93522) · 0bdea678
      Will Binns-Smith authored
      Adds a table view to compare mode, switchable from the treemap via a
      toggle in the top bar. The `DiffTable` lists every source file with its
      A/B sizes, delta, and env badges, and supports text search. Removed
      sources (which can't appear in the treemap since they don't exist in the
      current build) are only visible here.
      
      The view toggle defaults to Table when entering compare mode and resets
      to Treemap when leaving it.
      
      <!-- NEXT_JS_LLM_PR -->
      Co-authored-by: 's avatarvercel-fleet-prod[bot] <318278635+vercel-fleet-prod[bot]@users.noreply.github.com>
      Co-authored-by: 's avatarWill Binns-Smith <755844+wbinnssmith@users.noreply.github.com>
      0bdea678
    • Will Binns-Smith's avatar
      bundle-analyzer: add compare view with treemap diff (#93521) · 2f3f74b1
      Will Binns-Smith authored
      Adds a compare mode to the bundle analyzer. When the user picks a
      historical snapshot from the new baseline picker in the top bar, the UI
      switches into compare mode: routes are diff'd by name and size, and the
      per-route view shows a `DiffTreemap` that colors each source tile by its
      change status (added/removed/grew/shrank/unchanged).
      
      The compare sidebar shows the import chain for the selected tile on
      either the baseline ("A") or current ("B") side. Route totals are
      fetched in parallel so the route picker can sort by largest impact and
      classify routes as `changed`/`identical` rather than just name-presence.
      
      <!-- NEXT_JS_LLM_PR -->
      
      ---------
      Co-authored-by: 's avatarvercel-fleet-prod[bot] <318278635+vercel-fleet-prod[bot]@users.noreply.github.com>
      Co-authored-by: 's avatarWill Binns-Smith <755844+wbinnssmith@users.noreply.github.com>
      2f3f74b1
    • Sebastian "Sebbie" Silbermann's avatar
      [testmode] Stop using deprecated `url.parse` (#98194) · da6e8b65
      Sebastian "Sebbie" Silbermann authored
      `unstable_getResponseFromNextConfig` parsed the request URL with the
      deprecated `url.parse()` (DEP0169)
      
      This change constructs the same pathname/query/protocol/host shape from
      the WHATWG `URL` API instead, keeping `protocol` and `host` null for
      relative URLs so the existing rewrite base fallback keeps working. Query
      parsing goes through the existing `searchParamsToUrlQuery` helper, which
      decodes `+` as a space where the legacy parser left it untouched; we
      accept that edge-case difference in this testing utility.
      da6e8b65
    • Kazma Endo's avatar
    • Hendrik Liebau's avatar
      Fix duplicate background revalidation for `'use cache'` (#98446) · ac55fd99
      Hendrik Liebau authored
      An early `cacheHandler.set()` call previously made subsequent same-key
      `get()` calls wait for generation and persistence. This prevented
      another background revalidation, but those requests waited instead of
      receiving the existing stale data.
      
      The work in #94694 added private-cache persistence in dev. Its helper
      refactor made cross-request invocations wait for cache writes before
      retrying root-param-specific lookups. It also moved the coarse-key
      `set()` call after entry collection. That unintentionally allowed
      subsequent requests to receive stale data and start another background
      revalidation while one was already running.
      
      This change tracks background work separately for each lookup key within
      a runtime instance. Subsequent requests can receive the existing stale
      entry without waiting for generation or starting duplicate work. The
      task remains registered until collection and its cache writes settle.
      Each lookup records existing work before calling `get()`, so a slow
      lookup does not start another revalidation after the task it observed
      has completed.
      
      The handler still receives `set()` after collection, including
      asynchronous rendering of the cached result. Subsequent `get()` calls
      can still block while the handler persists the entry. We accept that
      remaining wait to preserve the cache-handler contract without bypassing
      handler reads.
      
      **Alternatives Considered**
      
      - Restore early `set()` calls and rely on the handler's pending-set
      promises. This would prevent duplicate regeneration, but would also make
      subsequent requests wait for generation again instead of receiving stale
      data.
      
      - Extend the existing cross-request sharing mechanism through background
      revalidation. We prototyped retaining stale and regenerated results, but
      that required additional stream ownership, invalidation checks, and
      root-param matching. The separate background-task map avoids those
      changes and leaves cold and foreground generation unchanged.
      
      Fixes #98326
      ac55fd99
    • Benjamin Woodruff ‮'s avatar
      Turbopack: Deduplicate project options documentation (#98465) · c1156571
      Benjamin Woodruff authored
      By documenting both the partial and non-partial versions of these
      objects, we were documenting everything multiple times.
      
      Just reference the non-partial object from the partial object's
      documentation.
      c1156571