1. 14 Sep, 2026 20 commits
    • next-js-bot[bot]'s avatar
      v16.4.0-canary.31 · 85e574a6
      next-js-bot[bot] authored
      85e574a6
    • Luke Sandberg's avatar
      test(turbopack): strongly read test operations (#98247) · be76b0cf
      Luke Sandberg authored
      ## Summary
      
      Replace top-level consistency suppression in straightforward backend
      tests with local operation roots that are read strongly consistently.
      Inner operation functions keep each migration scoped to its test.
      
      ## Verification
      
      - `cargo test -p turbo-tasks-backend --test filter_unused_args --test
      panics --test task_statistics`
      - `cargo fmt --all -- --check`
      
      <!-- NEXT_JS_LLM -->
      
      <!-- fleet 475180cd-06a7-4669-89b5-a2029a3a18c9 -->
      
      ---------
      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>
      be76b0cf
    • Will Binns-Smith's avatar
      Add `next dev` wait for Turbopack shutdown (#98646) · 975b9cff
      Will Binns-Smith authored
      ## Summary
      
      Add `NEXT_DEV_WAIT_FOR_TURBOPACK_SHUTDOWN` to make `next dev` wait for
      Turbopack's full project shutdown before exiting. This waits for active
      TurboTasks work and cache persistence instead of relying on fixed delays
      or the parent's normal 100 ms child-exit timeout.
      
      Use the option in the warm-restart task statistics test. Link documented
      `Project` interface methods to their native binding documentation.
      
      ## Verification
      
      - `pnpm --filter=next types`
      - `npx eslint --config eslint.config.mjs
      packages/next/src/cli/next-dev.ts
      packages/next/src/server/dev/hot-reloader-turbopack.ts
      test/e2e/filesystem-cache/warm-restart-task-stats.test.ts`
      - Pre-commit lint-staged checks
      - CI tests passed
      
      <!-- NEXT_JS_LLM -->
      975b9cff
    • Joseph's avatar
      docs: document default turbopack.resolveExtensions (#98627) · 25fe6f6f
      Joseph authored
      Fixes: #98609
      
      Editor note: Ensure this lands well into
      https://github.com/vercel/next.js/pull/98407 too
      25fe6f6f
    • Tobias Koppers's avatar
      test: migrate package CSS side-effects coverage (#98635) · b421cade
      Tobias Koppers authored
      ### What?
      
      Migrates the package CSS side-effects coverage from #70087 into the
      current `css-order` end-to-end suite. The matrix covers `sideEffects`
      values of `true`, `false`, broad CSS arrays, and global-CSS-only arrays
      across App Router, Pages Router, client components, and server
      components with client children.
      
      ### Why?
      
      The older coverage never reached `canary`, and most of its Turbopack
      cases were skipped as inconsistent. Keeping the scenarios in the current
      suite verifies that package CSS ordering remains deterministic in both
      Turbopack's default chunking mode and the graph chunker.
      
      ### How?
      
      The test uses explicit synthetic package fixtures and reuses the suite's
      existing Turbopack mode matrix, including the graph string and object
      configurations. The packages are transpiled so Pages Router exercises
      bundler CSS behavior rather than externalizing CSS imports to Node.
      Invalid entrypoints, selectors, routes, and CSS module references from
      the old fixtures were corrected during migration.
      
      This does not include the webpack loader implementation change proposed
      by #70087.
      
      ### Verification
      
      - `HEADLESS=true pnpm test-dev-turbo
      test/e2e/app-dir/css-order/css-order.test.ts` (189 passed, 114 existing
      todos)
      - `HEADLESS=true pnpm test-start-turbo
      test/e2e/app-dir/css-order/css-order.test.ts` (291 passed, 12 existing
      todos)
      - `HEADLESS=true pnpm test-start-webpack
      test/e2e/app-dir/css-order/css-order.test.ts` (192 passed, 8 existing
      todos)
      
      <!-- NEXT_JS_LLM -->
      
      <!-- fleet 10f9743e-de76-437c-8fdc-76b7be42a9b9 -->
      
      ---------
      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>
      b421cade
    • Tobias Koppers's avatar
      Improve tree shaking through Next.js module wrappers (#98638) · 3dc93da2
      Tobias Koppers authored
      ## What?
      
      Extends the export-usage passthrough introduced by #98621 to the
      transparent wrappers used for dynamic entries, server components, and
      shared server utilities.
      
      The existing reference-tree-shaking production fixture now covers each
      wrapper and verifies that unused sibling exports do not remain in
      Turbopack's server chunks.
      
      ## Why?
      
      These wrappers forward another module's export surface, but previously
      marked every target export as used. That kept otherwise unreachable
      modules in production output and limited inner-graph tree shaking.
      
      ## How?
      
      The dynamic-entry and server-component wrappers now pass their own
      resolved export usage to their targets. The custom server-utility
      reference reports the same passthrough binding usage while preserving
      its shared chunking and merge behavior.
      
      A public Turbopack constructor creates passthrough export-usage values
      for references outside `turbopack-core`, consistent with the existing
      constructors for other usage modes.
      
      ## Verification
      
      - `cargo check -p next-core`
      - `pnpm build-all`
      - `pnpm test-start-turbo
      test/production/app-dir/reference-tree-shaking/reference-tree-shaking.test.ts`
      - `pnpm test-start-webpack
      test/production/app-dir/reference-tree-shaking/reference-tree-shaking.test.ts`
      
      <!-- NEXT_JS_LLM -->
      
      
      <!-- fleet df1472be-5cd1-4bd6-9fab-4efc1defa4f9 -->
      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>
      3dc93da2
    • Tobias Koppers's avatar
      Trace export usage through client component proxies (#98621) · e3ababa0
      Tobias Koppers authored
      ## Summary
      
      Turbopack previously widened export usage to every export when a Server
      Component crossed a client-component proxy. As a result, importing one
      named export from a `use client` module retained unrelated
      implementations in both browser and SSR bundles.
      
      This extends Turbopack's import annotations with a generic export-usage
      passthrough. The server transform for `use client` modules marks its
      generated namespace import as passthrough, so the ordinary binding-usage
      fixed point carries the Server Component's used export set into
      `EcmascriptClientReferenceModule`. Its client-reference edges use the
      same signal to forward that set to browser and SSR targets.
      Side-effect-only evaluation references retain their evaluation semantics
      instead of inheriting the annotation. The forwarded names remain
      namespace-observable because React Flight resolves client references by
      their original export names, so unused exports can be removed without
      changing the protocol-visible identity. An importer whose usage is `All`
      still forwards `All`.
      
      The client-component tree-shaking test now checks that unused markers
      are absent from every browser chunk and verifies the same behavior in
      Turbopack SSR chunks.
      
      ## Verification
      
      - `cargo fmt --all -- --check`
      - `cargo check -p next-core`
      - `cargo test -p turbopack-core module_graph::binding_usage_info::tests
      --lib`
      - `pnpm build-all`
      - `pnpm test-start-turbo
      test/production/app-dir/client-components-tree-shaking/index.test.ts`
      - `pnpm test-start-webpack
      test/production/app-dir/client-components-tree-shaking/index.test.ts`
      
      <!-- NEXT_JS_LLM -->
      
      
      <!-- fleet 10716dab-2d36-4687-94ae-cd7bdfeac985 -->
      
      ---------
      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>
      e3ababa0
    • Ben's avatar
      fix: detect proxy.ts correctly with compound pageExtensions (#93246) · 000390a8
      Ben authored
      ## Maintainer status
      
      - Current with `canary` as of 2026-05-18; this branch includes a clean
      merge from latest `origin/canary`.
      - Lightweight checks pass; full fork workflows are still
      `action_required` until a maintainer approves CI.
      - No unresolved review threads or failing jobs are reported after the
      refresh.
      - Review focus: shared convention-file basename extraction for proxy,
      middleware, and instrumentation under compound `pageExtensions`; TS and
      Rust paths use the same rule.
      
      ---
      
      ## Summary
      
      Fixes #85648
      Fixes #86303
      Fixes #91600
      Fixes #85646
      Related to #86122
      Fixes #92342
      Closes #92934
      
      When `pageExtensions` is set to compound extensions like `['page.ts',
      'page.tsx']`, proxy files must be named `proxy.page.ts`. However, the
      proxy detection logic used `file_stem()` (Rust/Turbopack) and
      `path.parse().name` (JS/webpack), both of which only strip the **last**
      extension — so `proxy.page.ts` becomes `proxy.page` instead of `proxy`,
      and the proxy is never detected.
      
      **Root cause:** `path.parse('proxy.page.ts').name` returns
      `'proxy.page'`, not `'proxy'`. Same issue with Rust's `file_stem()`
      which uses `rsplit_once('.')`.
      
      **Fix:** Use `file_name().split('.')[0]` (JS) /
      `file_name().split('.').next()` (Rust) to extract the first segment
      before any dot. This correctly returns `'proxy'` for both `proxy.ts` and
      `proxy.page.ts`.
      
      The same `fileBaseName` extraction is also used for `middleware` and
      `instrumentation` convention file detection, fixing compound
      pageExtensions for those as well.
      
      ### Changes
      
      - **Turbopack (Rust):** `crates/next-api/src/project.rs` (2 locations) +
      `crates/next-api/src/middleware.rs` (1 location)
      - **Webpack (JS):** `packages/next/src/build/index.ts` (build-time
      detection) +
      `packages/next/src/server/lib/router-utils/setup-dev-bundler.ts`
      (dev-time detection)
      - **E2e tests:**
      - `proxy-page-extensions/` — proxy + instrumentation with compound
      extensions
      - `middleware-page-extensions/` — middleware with compound extensions
      (separate fixture because the build refuses both `proxy.*` and
      `middleware.*` simultaneously)
      
      ### Verified locally
      
      | Mode | Bundler | Result |
      |------|---------|--------|
      | Dev | Turbopack | PASS (5/5) |
      | Dev | Webpack | PASS (5/5) |
      | Production (build+start) | Turbopack | PASS (5/5) |
      | Production (build+start) | Webpack | PASS (5/5) |
      
      Existing proxy test suites also verified (proxy-runtime-nodejs,
      proxy-with-middleware, proxy-missing-export, proxy-runtime) — no
      regressions.
      
      ## Test plan
      
      - [x] `proxy-page-extensions.test.ts` covers proxy header injection,
      page render through proxy, and `instrumentation.page.ts:register()`
      running
      - [x] `middleware-page-extensions.test.ts` covers middleware header
      injection and page render through middleware
      - [x] All 5 cases pass in dev/turbopack, dev/webpack, start/turbopack,
      start/webpack
      - [x] Existing proxy-runtime-nodejs tests pass (dev/webpack,
      dev/turbopack, production/webpack)
      - [ ] CI passes on all existing proxy tests
      
      <!-- NEXT_JS_LLM_PR -->
      
      ---------
      Co-authored-by: 's avatarNiklas Mischkulnig <4586894+mischnic@users.noreply.github.com>
      000390a8
    • 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 2 commits