- 17 Aug, 2025 2 commits
-
-
nextjs-bot authored
-
Tobias Koppers authored
### What? - show timing event for database compaction - show timing event for persistent caching in dev too
-
- 16 Aug, 2025 6 commits
-
-
nextjs-bot authored
-
Jiwon Choi authored
-
Tobias Koppers authored
### What? Fixes a bug that breaks the pool after scaling down Closes PACK-5249
-
nextjs-bot authored
-
JJ Kasper authored
This exposes additional metadata in the server reference manifest, it is not directly used at this time though.
-
Jiwon Choi authored
fix: use `turbopack.root` value for `outputFileTracingRoot` to have consistent tracing root (#82653) Regressed from https://github.com/vercel/next.js/pull/82164 Previously, `outputFileTracingRoot` was always set via `findRoot()` if the option was not explicitly given. However, https://github.com/vercel/next.js/pull/82164 changed the behavior to run `findRoot()` only if neither `outputFileTracingRoot` nor `turbopack.root` was given. Modified to: - When BOTH options are given, ensure they match, or else WARN and use `outputFileTracingRoot`. - When EITHER option is given, map the other value as the other. - When NONE is given, call `findDir()` and use its value. - After the processes above, if the root dir value is not assigned, throw an error as a Next.js bug. Fixes https://github.com/vercel/next.js/issues/82626
-
- 15 Aug, 2025 17 commits
-
-
nextjs-bot authored
-
Benjamin Woodruff authored
The goal of this module is to avoid logging no-op build events. Turbopack uses a bottom-up execution model which leads to a lot of really short no-op "building" events that we try to filter out. If `onBuilding` isn't called before `onBuilt`, then `deferredReportHmrStartId` will be `undefined` here, causing us to report the end of a build. Since `onBuilding` wasn't called yet, the start time will be `undefined`, giving us a duration of `NaN`. We were using `deferredReportHmrStartId` to try to determine when we'd already reported the start of a build, but it wasn't quite right. Instead, use a separate, more explicit, variable for that. --- https://vercel.slack.com/archives/C046HAU4H7F/p1749456305992089?thread_ts=1749455727.004169&cid=C046HAU4H7F > we fire the BUILDING event from the server, before a client is present, then the client attaches, and eventually BUILT is sent and we trigger the NaN ms log Thanks for the root-causing help, @icyJoseph --- Tested by loading `pnpm next dev --turbopack examples/basic-css/` and modifying the source code to trigger HMRs. 
-
Alexander Kachkaev authored
Follows https://github.com/vercel/next.js/pull/81907, removes an outdated disclaimer from the docs: https://nextjs.org/docs/app/api-reference/file-conventions/middleware#runtime <img width="1346" height="852" alt="Screenshot 2025-07-30 at 00 19 01" src="https://github.com/user-attachments/assets/ebaf9d5e-4f70-4422-bda6-9801fcd52707" /> Keeping #81907 unmerged until 15.5 release would make sense, but since it’s already in, this one can go in too. Merging it after cutting 15.5.0 would also be fine. <!-- Thanks for opening a PR! Your contribution is much appreciated. To make sure your PR is handled as smoothly as possible we request that you follow the checklist sections below. Choose the right checklist for the change(s) that you're making: ## For Contributors ### Improving Documentation - Run `pnpm prettier-fix` to fix formatting issues before opening the PR. - Read the Docs Contribution Guide to ensure your contribution follows the docs guidelines: https://nextjs.org/docs/community/contribution-guide ### Adding or Updating Examples - The "examples guidelines" are followed from our contributing doc https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md - Make sure the linting passes by running `pnpm build && pnpm lint`. See https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md ### Fixing a bug - Related issues linked using `fixes #number` - Tests added. See: https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs - Errors have a helpful link attached, see https://github.com/vercel/next.js/blob/canary/contributing.md ### Adding a feature - Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. (A discussion must be opened, see https://github.com/vercel/next.js/discussions/new?category=ideas) - Related issues/discussions are linked using `fixes #number` - e2e tests added (https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs) - Documentation added - Telemetry added. In case of a feature if it's used or not. - Errors have a helpful link attached, see https://github.com/vercel/next.js/blob/canary/contributing.md ## For Maintainers - Minimal description (aim for explaining to someone not on the team to understand the PR) - When linking to a Slack thread, you might want to share details of the conclusion - Link both the Linear (Fixes NEXT-xxx) and the GitHub issues - Add review comments if necessary to explain to the reviewer the logic behind a change ### What? ### Why? ### How? Closes NEXT- Fixes # -->
-
Suneil Nyamathi authored
repro info here: https://github.com/snyamathi/nextjs-mem-leak ## Background > The Fetch Standard allows users to skip consuming the response body by relying on garbage collection to release connection resources. Undici added support for this in https://github.com/nodejs/undici/pull/3199 and later for the body of cloned responses in https://github.com/nodejs/undici/pull/3458 which first landed in [Undici version 6.19.8](https://github.com/nodejs/undici/commits/v6.19.8) in August 2024. In September 2024, this issue https://github.com/vercel/next.js/discussions/69635 was raised for the error, `TypeError: Response.clone: Body has already been consumed` In NextJS's [dedupe-fetch](https://github.com/vercel/next.js/blame/ab59e37a66f1a70b1172af9149d8aa3ba1509330/packages/next/src/server/lib/dedupe-fetch.ts#L92) the cloned response is returned to userland, while the original response is stored in a react cache ```js // match was pulled from react cache, a clone is returned to the user return match.then((response: Response) => response.clone()); ``` ## Undici Bug I'm omitting some details in the code snippet below (see full changes at https://github.com/nodejs/undici/pull/3458/files), but the Undici change to `use FinalizationRegistry for cloned response body` seems to have mixed up the response pointer and stream bodies when registering with the finalization registry, resulting in the wrong stream being cancelled. The original response, (the `match` above) stored in the react cache is cloned, and then **its** stream is registered with the finalization registry when the cloned response `newRequest` is reclaimed. **I believe this is the true underlying cause of the errors:** `Body has already been consumed` ```js function cloneBody(instance, body) { const [out1, out2] = body.stream.tee(); // Erroneously registering newRequest + old body with finalization registry streamRegistry.register(instance, new WeakRef(out1)); // Original request + out1 is used in Next's dedupe-request cache body.stream = out1; // Clone request + out2 is returned to userland return { stream: out2, }; } // When newRequest is reclaimed, the original request.body is cancelled by mistake! newRequest.body = cloneBody(newRequest, request.body); // This is what the registry looks like streamRegistry = new FinalizationRegistry((weakRef) => { const stream = weakRef.deref(); if (stream && !stream.locked && !isDisturbed(stream) && !isErrored(stream)) { stream.cancel("Response object has been garbage collected").catch(noop); } }); ``` https://github.com/snyamathi/nextjs-mem-leak/blob/main/index.mjs has a simple reproduction of this issue which shows that when the clone is reclaimed, the original stream is cancelled, leading to issues ## Memory Leak This lead to https://github.com/vercel/next.js/pull/73274 which fixed the problem by adding a custom `cloneResponse` function. https://github.com/vercel/next.js/blob/7ef0a2b2767b4159f8db8e1884bac98370528a25/packages/next/src/server/lib/clone-response.ts However, this in turn has lead to a memory leak because now there is no one to garbage collect the tee'd stream. https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream/tee > To cancel the stream you then need to cancel both resulting branches. Teeing a stream will generally lock it for the duration, preventing other readers from locking it. Undici was incorrectly cancelling the stream (leading to a bug), and Next is simply not cancelling the stream (leading to a memory leak). This can be observed with a Docker setup which shows a current version of NextJS, the last version prior to the custom `cloneResponse` function, as well as the effects of the proposed fix here. <img width="2400" height="1200" alt="plot" src="https://github.com/user-attachments/assets/a1df0afd-cc8a-4a89-8c92-381ee71fff59" /> I have a reproduction available here https://github.com/snyamathi/nextjs-mem-leak/tree/main - you'll notice the memory for NextJS climb until it runs out of memory and crashes, whereas the version prior to this change (`15.0.4-canary`) is unaffected. Similarly, if we forego the dedupe cache by passing in a signal (https://github.com/vercel/next.js/blob/102f233a170e9df0b30c24a58c3953dc678ec330/packages/next/src/server/lib/dedupe-fetch.ts#L45) there is no memory leak either. The PR changes here are applied as a patch and also fix the memory leak :) ```bash docker compose pull docker compose build docker compose up -d docker container stats ``` ``` CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS 1b2f217c4d03 mem-next-og-1 28.50% 124MiB / 1GiB 12.11% 993MB / 7.45MB 0B / 0B 23 7e76622a4a3e mem-next-15.4.1-1 49.03% 1021MiB / 1GiB 99.69% 993MB / 7.5MB 0B / 0B 23 1bacb1a9b1cc mem-next-15.0.4-canary.39-1 21.22% 115.6MiB / 1GiB 11.29% 991MB / 7.44MB 0B / 0B 23 df2a8ba5800e mem-siege-1 5.59% 12.56MiB / 31.2GiB 0.04% 9.73MB / 10.5MB 0B / 0B 102 46fab210c911 mem-next-patched-1 2.46% 91.34MiB / 1GiB 8.92% 2.38MB / 1.97MB 0B / 0B 23 365987089d03 mem-upstream-1 15.16% 137.2MiB / 31.2GiB 0.43% 16.8MB / 2.97GB 0B / 0B 23 ``` Each container outputs the request number and current memory usage which are then plotted in order to observe the memory leak due to the custom `cloneResponse`. Because the fix associates the correct response and stream, the previous regression does not happen again. We can confirm this by making requests to the page for each of the docker containers. The container using the version prior to the custom `cloneResponse` will error out, while the rest will not ``` $ curl -s localhost:3002 | htmlq --text '#error' Response.clone: Body has already been consumed. ``` cc @wyattjoh @gnoff ## Reproduction https://github.com/snyamathi/nextjs-mem-leak/tree/main contains a number of reproductions - https://github.com/snyamathi/nextjs-mem-leak/blob/main/index.mjs shows a pure javascript reproduction of the original undici bug - https://github.com/snyamathi/nextjs-mem-leak/blob/main/page.js shows how that bug manifested itself in Next for the `Body has already been consumed` error - https://github.com/snyamathi/nextjs-mem-leak/blob/main/route.js shows the memory leak due to the custom `cloneResponse` function The rest of the files are supporting infrastructure to start docker containers of various versions and various patches showing how versions prior to the `cloneResponse` do not have the same memory leak, and how the patch (PR'd here) fixes the issue without regressing on the Undici issue.
-
nextjs-bot authored
-
Vercel Release Bot authored
This auto-generated PR updates the development integration test manifest used when testing Rspack.
-
Vercel Release Bot authored
This auto-generated PR updates the production integration test manifest used when testing Rspack.
-
Tobias Koppers authored
### What? Depending on compilation mode of the react compiler, check the source code if matches a certain regex This also adds `content` as condition for webpack loaders Closes PACK-5252
-
Adem authored
Co-authored-by:Joseph <joseph.chamochumbi@vercel.com>
-
Wyatt Johnson authored
### What? Replace LRU cache implementation with an optimized doubly-linked list algorithm and move from server-only to shared library location. ### Why? The previous Map-based LRU cache had suboptimal eviction performance for route matching operations under high load. Route matching is a critical performance path in Next.js that benefits significantly from true O(1) cache operations. ### How? - Implement doubly-linked list with sentinel nodes for true O(1) get/set/delete operations - Add comprehensive test coverage including size-based eviction scenarios - Update import paths across 14 files throughout the codebase - Add defensive null checking for edge cases discovered during static analysis - Replace deprecated `keys()` iteration with modern `Symbol.iterator` pattern
-
Tobias Koppers authored
### What? Following the guideline that all CPU work should happen on a normal task.
-
Niklas Mischkulnig authored
Forgot to do this in #82652
-
Niklas Mischkulnig authored
#82641 was merged a bit soon
-
Wyatt Johnson authored
-
Joseph authored
When building w/ webpack to calculate duration, we use `process.hrtime` which is a tuple of integers [seconds, nanoseconds] - which means that for sub second compiler runs, we end up showing total 0ms, or 1000ms (I think) - https://nodejs.org/api/process.html#processhrtimetime With this PR we combine the seconds and nanoseconds into a float. ### Before: ```console ▲ Next.js 15.4.6 - Environments: .env.production Creating an optimized production build ... ✓ Compiled successfully in 0ms Skipping validation of types ``` ### After ```console ▲ Next.js 15.4.6 - Environments: .env.production Creating an optimized production build ... ✓ Compiled successfully in 813ms Skipping validation of types ```
-
Jiwon Choi authored
I added docs at https://github.com/vercel/next.js/pull/70958, but never landed on `canary` ~~due to a git rebase skill issue~~. --------- Co-authored-by:
Joseph <joseph.chamochumbi@vercel.com> Co-authored-by:
vercel[bot] <35613825+vercel[bot]@users.noreply.github.com>
-
Ben Gubler authored
Remove tests of the implementation details. Add more tests for route handler types. Re: feedback from @eps1lon
-
- 14 Aug, 2025 15 commits
-
-
JJ Kasper authored
This continues the `build-complete` handling for the adapters config adding additional prerender logic including PPR fields and expanding test coverage ensuring correct outputs.
-
Ben Gubler authored
## Add typed RouteContext for App Router route handlers This PR adds type support for route handlers in the App Router by introducing a new `RouteContext` interface. This allows for strongly-typed access to route parameters in API routes. ### Features: - Adds a new global `RouteContext<AppRouteHandlerRoute>` interface with typed `params` property - Adds test cases for various route parameter patterns - Updates type tests to verify correct type checking for route handlers This enhancement improves the developer experience by providing type safety when accessing route parameters in API route handlers, similar to the existing type support for pages and layouts.
-
nextjs-bot authored
-
Ben Gubler authored
<!-- Thanks for opening a PR! Your contribution is much appreciated. To make sure your PR is handled as smoothly as possible we request that you follow the checklist sections below. Choose the right checklist for the change(s) that you're making: ## For Contributors ### Improving Documentation - Run `pnpm prettier-fix` to fix formatting issues before opening the PR. - Read the Docs Contribution Guide to ensure your contribution follows the docs guidelines: https://nextjs.org/docs/community/contribution-guide ### Adding or Updating Examples - The "examples guidelines" are followed from our contributing doc https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md - Make sure the linting passes by running `pnpm build && pnpm lint`. See https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md ### Fixing a bug - Related issues linked using `fixes #number` - Tests added. See: https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs - Errors have a helpful link attached, see https://github.com/vercel/next.js/blob/canary/contributing.md ### Adding a feature - Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. (A discussion must be opened, see https://github.com/vercel/next.js/discussions/new?category=ideas) - Related issues/discussions are linked using `fixes #number` - e2e tests added (https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs) - Documentation added - Telemetry added. In case of a feature if it's used or not. - Errors have a helpful link attached, see https://github.com/vercel/next.js/blob/canary/contributing.md ## For Maintainers - Minimal description (aim for explaining to someone not on the team to understand the PR) - When linking to a Slack thread, you might want to share details of the conclusion - Link both the Linear (Fixes NEXT-xxx) and the GitHub issues - Add review comments if necessary to explain to the reviewer the logic behind a change ### What? ### Why? ### How? Closes NEXT- Fixes # -->
-
Niklas Mischkulnig authored
<!-- Thanks for opening a PR! Your contribution is much appreciated. To make sure your PR is handled as smoothly as possible we request that you follow the checklist sections below. Choose the right checklist for the change(s) that you're making: ## For Contributors ### Improving Documentation - Run `pnpm prettier-fix` to fix formatting issues before opening the PR. - Read the Docs Contribution Guide to ensure your contribution follows the docs guidelines: https://nextjs.org/docs/community/contribution-guide ### Adding or Updating Examples - The "examples guidelines" are followed from our contributing doc https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md - Make sure the linting passes by running `pnpm build && pnpm lint`. See https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md ### Fixing a bug - Related issues linked using `fixes #number` - Tests added. See: https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs - Errors have a helpful link attached, see https://github.com/vercel/next.js/blob/canary/contributing.md ### Adding a feature - Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. (A discussion must be opened, see https://github.com/vercel/next.js/discussions/new?category=ideas) - Related issues/discussions are linked using `fixes #number` - e2e tests added (https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs) - Documentation added - Telemetry added. In case of a feature if it's used or not. - Errors have a helpful link attached, see https://github.com/vercel/next.js/blob/canary/contributing.md ## For Maintainers - Minimal description (aim for explaining to someone not on the team to understand the PR) - When linking to a Slack thread, you might want to share details of the conclusion - Link both the Linear (Fixes NEXT-xxx) and the GitHub issues - Add review comments if necessary to explain to the reviewer the logic behind a change ### What? ### Why? ### How? Closes NEXT- Fixes # -->
-
Luke Sandberg authored
Change our `global` rewrite to use a non-shadowable property on `__turbopack_context__` The previous rewrite to `globalThis` would break if there was a local declaration of `let globalThis` which could either trigger a TDZ error or simply evaluate to the wrong value. Closes PACK-5256 Fixes #82632
-
Niklas Mischkulnig authored
Reverts https://github.com/vercel/next.js/pull/82256 because there appears to be a race condition (even in the unit tests) https://vercel.slack.com/archives/C04KC8A53T7/p1755180908771559
-
nextjs-bot authored
-
Sebastian "Sebbie" Silbermann authored
-
Hendrik Liebau authored
When revalidating a tag or path with a server action, we do want to log any fetches that are made during the subsequent rerendering, when [fetch logging](https://nextjs.org/docs/app/api-reference/config/next-config-js/logging#fetching) is enabled. This got accidentally broken in #64746, where we wrote: > [...] this ensures we don't keep tracking fetch metrics after the request has ended as we only report on request end That's incorrect though, because we report fetch metrics when the _response_ is closed, and not the request: https://github.com/vercel/next.js/blob/0bd7423844e218b19537880a7fa4314749fdf57d/packages/next/src/server/dev/next-dev-server.ts#L530-L546 This is crucial for server actions, when the request is likely already closed while we're rerendering and streaming the response to the client. fixes #80444 closes NAR-307
-
Tobias Koppers authored
### What? add a `spawn` method in turbo_tasks that allows to spawn a async tokio task with the right task locals, spans, etc.
-
Steven authored
Add a warning to Next.js 15.5 to prepare for Next.js 16 when `images.localPatterns` is undefined and the user attempted to optimize a `src` image with a query string, such as ```jsx <Image src="/api/user?id=1" width="50" height="50" /> ```
-
Tobias Koppers authored
### What? Do not run a compaction when opening the DB. We are already busy when starting up, so no need to add more work to that.
-
Niklas Mischkulnig authored
The source content was somethings incorrect with scope hoisting on Turbopack: <img width="2018" height="721" alt="image" src="https://github.com/user-attachments/assets/e2e1bf1c-2a84-4acb-8388-a809670b4902" /> Fix is in https://github.com/swc-project/swc-sourcemap/pull/7
-
nextjs-bot authored
-