Commit Graph

1409 Commits

Author SHA1 Message Date
Tobias Koppers e8a72cc170 [Turbopack] allow to configure last successful parse cache state (#75851)
### What?

Add an option for using the parser AST state and only enable it in development mode.
2025-02-11 09:55:55 +01:00
Hendrik Liebau a181122afc Dedupe cached data from "use cache" functions in RSC payload (#75786) 2025-02-08 09:40:36 +01:00
Niklas Mischkulnig 1dad3a6759 Turbopack: make ModulePart a TaskInput (#75364)
No significant perf impact
2025-02-06 20:22:06 +01:00
Tobias Koppers 2da625932c [Turbopack] use new backend in next-build-test (#75724)
### What?

* use new backend in next-build-test
* apply effects in next-build-test
* fix Dockerfile
2025-02-06 15:13:05 +01:00
Tobias Koppers 1366054856 Revert "chore(next-swc-napi): Remove unused(?) rlib target" (#75745)
Reverts vercel/next.js#75707

canary builds timed out
2025-02-06 14:08:14 +01:00
Benjamin Woodruff 1eb708adcc chore(next-swc-napi): Remove unused(?) rlib target (#75707)
napi-rs only uses the cdylib version: https://github.com/napi-rs/napi-rs/blob/688a266f132f947b8002e892b78decd660d8a6ec/crates/napi/README.md#building

This might(?) slightly improve compile times for certain invocations of `cargo`.
2025-02-05 21:58:59 +01:00
Tobias Koppers eb789ecf71 [Turbopack] disable dependency tracking for next build (#75704)
### What?

fix a previous PR that disables dependency tracking when not needed.
2025-02-05 20:29:50 +01:00
Donny/강동윤 b6f8743ecd Update swc_core to v13.0.4 (#75684)
### What?

ChangeLog:
https://github.com/swc-project/swc/compare/swc_core%40v12.0.0...swc_core%40v13.0.4

### Why?


 - To keep in sync
 - To drop `rustc-hash` v1
 - To apply https://github.com/swc-project/swc/pull/9978

---------

Co-authored-by: Niklas Mischkulnig <4586894+mischnic@users.noreply.github.com>
2025-02-05 14:54:04 +01:00
Niklas Mischkulnig a50782c7d2 Turbopack: make IssueSource a TaskInput (#75542)
Meaning fewer cells and fewer tasks

No measureable perf difference
2025-02-05 11:10:55 +01:00
Donny/강동윤 0783eb807d perf: Remove needless Arc (#75601)
### What?

Remove one allocation per `transform()` and `minify()`.

### Why?

We don't need to allocate `Compiler` in an `Arc`, because we don't share it.
2025-02-05 04:25:29 +00:00
Donny/강동윤 23e8640258 perf: Make page static info use Atom instead of String (#75596)
### What?

Use `swc_atoms::Atom` instead of `String` in `next-swc`. 

### Why?

`Atom` does not allocate if another instance has the same value, meaning that `clone()` is a single atomic operation. But `String` allocates regardless of any other occurrence.
2025-02-05 01:29:26 +00:00
Donny/강동윤 05b9184ed0 perf: Make page exports stripper use Atom instead of String (#75595)
### What?

Use `swc_atoms::Atom` instead of `String` in `next-swc`. 

### Why?

`Atom` does not allocate if another instance has the same value, meaning that `clone()` is a single atomic operation. But `String` allocates regardless of any other occurrence.
2025-02-05 00:28:58 +00:00
Donny/강동윤 49b93c6dfb perf: Make server action pass use Atom instead of String (#75594)
### What?

Use `swc_atoms::Atom` instead of `String` in `next-swc`. 

### Why?

`Atom` does not allocate if another instance has the same value, meaning that `clone()` is a single atomic operation. But `String` allocates regardless of any other occurrence.
2025-02-05 08:32:18 +09:00
Donny/강동윤 361d4cf025 perf: Make RSC pass use Atom instead of String (#75593)
### What?

Use `swc_atoms::Atom` instead of `String` in `next-swc`. 

### Why?

`Atom` does not allocate if another instance has the same value, meaning that `clone()` is a single atomic operation. But `String` allocates regardless of any other occurrence.
2025-02-05 08:31:53 +09:00
Donny/강동윤 c1d9a048d1 perf: Make barrel optimizer use Atom instead of String (#75592)
### What?

Use `swc_atoms::Atom` instead of `String` in `next-swc`. 

### Why?

`Atom` does not allocate if another instance has the same value, meaning that `clone()` is a single atomic operation. But `String` allocates regardless of any other occurrence.
2025-02-05 08:31:27 +09:00
Niklas Mischkulnig 5f73def06c Turbopack: generate less JS before minification (#75358)
Use the final `__turbopack_context_.X` directly, which saves use the long destructuring.
The original versions (`__turbopack_load__`, `__turbopack_import__`) are still available as the user-facing API (implemented via free var replacements).

src-rolldown-1000 before:
```
input_len	6.776151mb
output_len	1.318701mb
```

src-rolldown-1000 after:
```
input_len	2.879056mb
output_len	1.147727mb
```

```
canary (0f7251fc78):
without sourcemaps:
15,3
506.01s user 104.05s system 780% cpu 1:18.21 total
500.73s user 105.54s system 767% cpu 1:18.98 total

with sourcemaps:
23,3gb
542.87s user 119.60s system 752% cpu 1:28.06 total
537.84s user 117.53s system 799% cpu 1:22.02 total
```
```
after (e09b2a5517):
without sourcemaps:
14,65gb
503.89s user 102.31s system 770% cpu 1:18.63 total
493.39s user 100.04s system 768% cpu 1:17.18 total
494.93s user 101.16s system 769% cpu 1:17.44 total

with sourcemaps:
22,7
529.38s user 115.85s system 785% cpu 1:22.09 total
522.39s user 115.70s system 781% cpu 1:21.66 total
```
2025-02-04 19:44:40 +01:00
Niklas Mischkulnig 64f34a0eae Turbopack: OutputAsset::path() (#75659) 2025-02-04 18:33:57 +01:00
Donny/강동윤 c6e369429c perf: Make next_ssg use Atom instead of String (#75591)
### What?

### Why?


`swc_atoms::Atom` is better for repeatedly used strings.
2025-02-04 22:57:41 +09:00
Benjamin Woodruff 251e6bd927 perf(turbopack): Migrate as many data structures to FxHash as possible (#75546)
Migrate as many things as possible that I could find with:

```
rg '\b(Index|Hash)(Map|Set)<'
```

# Benchmarks

I tried building next-site, differences are likely within noise threshold.

## Before this change

```
$ hyperfine --warmup 1 --runs 5 --prepare 'rm -rf .next' 'TURBOPACK=1 TURBOPACK_BUILD=1 TURBO_ENGINE_READ_ONLY=1 pnpm next build --experimental-build-mode=compile'

Benchmark 1: TURBOPACK=1 TURBOPACK_BUILD=1 TURBO_ENGINE_READ_ONLY=1 pnpm next build --experimental-build-mode=compile
  Time (mean ± σ):     27.254 s ±  0.268 s    [User: 125.055 s, System: 16.090 s]
  Range (min … max):   26.810 s … 27.529 s    5 runs
```

## After this change

```
$ hyperfine --warmup 1 --runs 5 --prepare 'rm -rf .next' 'TURBOPACK=1 TURBOPACK_BUILD=1 TURBO_ENGINE_READ_ONLY=1 pnpm next build --experimental-build-mode=compile'

Benchmark 1: TURBOPACK=1 TURBOPACK_BUILD=1 TURBO_ENGINE_READ_ONLY=1 pnpm next build --experimental-build-mode=compile
  Time (mean ± σ):     26.711 s ±  0.461 s    [User: 123.910 s, System: 15.667 s]
  Range (min … max):   26.346 s … 27.463 s    5 runs
```
2025-02-03 22:09:02 -08:00
Benjamin Woodruff 7dcc35c8c3 perf(next-custom-transforms): Replace non-Sync Rc<DashMap<_, _>> usage with Rc<RefCell<FxHashMap<_, _>>> (#75534)
This is a follow-up to https://github.com/vercel/next.js/pull/75007

`DashMap` is needed for situations where you have many threads (or tokio tasks) modifying the same data at the same time. It introduces a lot of memory and CPU overhead to create individually lockable `RwLock` shards. This type of data structure implements `Sync`, indicating that it can be shared between threads.

`Rc` is not `Sync` (`Arc` is `Sync`), so wrapping `DashMap` in `Rc` doesn't make a lot of sense: You're paying a pretty high overhead for the ability to share data between threads, and wrapping it in something that does not support sharing data between threads.

This visitor code is entirely single-threaded, so just use `Rc<RefCell<FxHashMap>>` instead. `RefCell` is a very cheap single-threaded version of a `Mutex`. `FxHashMap` is just a `HashMap` with the faster `FxHash` algorithm used.
2025-02-03 19:23:00 -08:00
Benjamin Woodruff fd27e588bd perf(turbopack): Update rustc-hash from 1.1.0 to 2.1.0 (#75531)
> Replace hash with faster and better finalized hash. This replaces the previous "fxhash" algorithm originating in Firefox with a custom hasher designed and implemented by Orson Peters (orlp). It was measured to have slightly better performance for rustc, has better theoretical properties and also includes a significantly better string hasher.

https://github.com/rust-lang/rustc-hash/blob/master/CHANGELOG.md

# Benchmarks

Any perf difference either way is too small to be easily measured. Benchmarks here technically show a tiny regression, but that's well within the run-to-run variance I've observed.

## rustc-hash 1.1.0

```
$ hyperfine --warmup 1 --runs 5 --prepare 'rm -rf .next' 'TURBOPACK=1 TURBOPACK_BUILD=1 TURBO_ENGINE_READ_ONLY=1 pnpm next build --experimental-build-mode=compile'

Benchmark 1: TURBOPACK=1 TURBOPACK_BUILD=1 TURBO_ENGINE_READ_ONLY=1 pnpm next build --experimental-build-mode=compile
  Time (mean ± σ):     26.736 s ±  0.294 s    [User: 122.811 s, System: 15.908 s]
  Range (min … max):   26.340 s … 27.165 s    5 runs
```

## rustc-hash 2.1.0

```
$ hyperfine --warmup 1 --runs 5 --prepare 'rm -rf .next' 'TURBOPACK=1 TURBOPACK_BUILD=1 TURBO_ENGINE_READ_ONLY=1 pnpm next build --experimental-build-mode=compile'

Benchmark 1: TURBOPACK=1 TURBOPACK_BUILD=1 TURBO_ENGINE_READ_ONLY=1 pnpm next build --experimental-build-mode=compile
  Time (mean ± σ):     27.206 s ±  0.540 s    [User: 126.145 s, System: 15.958 s]
  Range (min … max):   26.543 s … 27.894 s    5 runs
```
2025-02-03 19:00:00 -08:00
Donny/강동윤 5de97804c9 perf: Make next/dynamic handler use Atom instead of String (#75589)
### What?

### Why?


`swc_atoms::Atom` is better for repeatedly used strings.
2025-02-04 09:14:38 +09:00
Benjamin Woodruff 01386058f5 chore(turbopack): Remove unmaintained fxhash crate, use rustc-hash instead (#75530)
The fxhash crate hasn't been updated in 7 years, the rust-hash crate is actively maintained.

We were using an awkward mix of both, unify on just using rustc-hash.
2025-02-03 14:59:58 -08:00
Donny/강동윤 9d2d39378d perf: Make cjs_optimizer use Atom instead of String (#75588)
### What?

### Why?

`swc_atoms::Atom` is better for repeatedly used strings.
2025-02-04 07:31:29 +09:00
Benjamin Woodruff aa9ded6aea refactor(turbo-tasks): Codemod/migrate all ResolvedVc casting callsites to use the new synchronous APIs (#75547)
This is a follow-up to https://github.com/vercel/next.js/pull/75055.

After #75055, the async methods are just facades around the synchronous versions, to avoid breaking the API.

I made this PR using:

```
sg run -p 'ResolvedVc::try_sidecast::<$$$TY>($$$ARGS).await?' -r 'ResolvedVc::try_sidecast_sync::<$$$TY>($$$ARGS)' -U
sg run -p 'ResolvedVc::try_sidecast($$$ARGS).await?' -r 'ResolvedVc::try_sidecast_sync($$$ARGS)' -U
sg run -p 'ResolvedVc::try_downcast::<$$$TY>($$$ARGS).await?' -r 'ResolvedVc::try_downcast_sync::<$$$TY>($$$ARGS)' -U
sg run -p 'ResolvedVc::try_downcast($$$ARGS).await?' -r 'ResolvedVc::try_downcast_sync($$$ARGS)' -U
sg run -p 'ResolvedVc::try_downcast_type::<$$$TY>($$$ARGS).await?' -r 'ResolvedVc::try_downcast_type_sync::<$$$TY>($$$ARGS)' -U
sg run -p 'ResolvedVc::try_downcast_type($$$ARGS).await?' -r 'ResolvedVc::try_downcast_type_sync($$$ARGS)' -U
```

Delete the implementation of the non-sync methods, and then:

```
sg run -p 'ResolvedVc::try_sidecast_sync' -r 'ResolvedVc::try_sidecast' -U
sg run -p 'ResolvedVc::try_downcast_sync' -r 'ResolvedVc::try_downcast' -U
sg run -p 'ResolvedVc::try_downcast_type_sync' -r 'ResolvedVc::try_downcast_type' -U
```

Then rename the methods implementations in `resolved.rs` to match.
2025-02-03 14:25:12 -08:00
Donny/강동윤 fd8b0543e3 perf: Make next-page-static-info use Atom instead of String (#75587)
### What?

Use `swc_atoms::Atom` instead of `String` in `next-swc`. 

### Why?

`Atom` does not allocate if another instance has the same value, meaning that `clone()` is a single atomic operation. But `String` allocates regardless of any other occurrence.
2025-02-04 06:29:43 +09:00
Benjamin Woodruff 7a0eb3c26f refactor(turbo-tasks): Port task statistics to the new backend (#75303)
This was available on the old memory backend, this ports it to the new backend, which is important now that it's the default.

Plus, the code's cleaner now that the trait resolution hack I had was cleaned up in #75214!
2025-02-03 08:20:03 -08:00
Tim Neutkens 6f03bb297b Turbopack: Disable react_refresh code in production (#75535)
## What?

Ensures we don't inject React refresh helpers in production:

```
'object' == typeof globalThis.$RefreshHelpers$ &&
  null !== globalThis.$RefreshHelpers &&
  p.registerExports(v, globalThis.$RefreshHelpers$);
```

Also skips trying to resolve the `react-refresh` package.

<!-- 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 #

-->
2025-02-03 15:47:56 +01:00
Niklas Mischkulnig 0175834ba3 Turbopack: Skip Traced chunking type in module graph (#75608)
Co-authored-by: Will Binns-Smith <wbinnssmith@gmail.com>
2025-02-03 15:39:06 +01:00
Tobias Koppers 5537946e08 [Turbopack] add more options for production chunking (#75544)
add more options for production chunking

adjust chunking options

<!-- 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 #

-->
2025-02-03 15:38:51 +01:00
Tobias Koppers 29fde37bce [Turbopack] disable dependency tracking when running build without persistent caching (#75243)
### What?

When running next build there won't be any changes during build and we don't need to capture dependencies at all.
2025-02-03 15:32:55 +01:00
Tobias Koppers 51ce3989bf [Turbopack] allow to manually mark tasks as root (#75436)
### What?

Add `mark_root()` to manually mark tasks as root as performance optimization.
2025-02-03 14:44:44 +01:00
Tobias Koppers 9a6b0f517c [Turbopack] disable lifo slot to make all tasks stealable (#75472)
### What?

* pass rustflags to windows too
* disable lifo slot to make all tasks stealable

### Why?

Since we do a lot of CPU bound work in tokio tasks this can lead to future polling taking several seconds. With the lifo slot, one task is not stealable and need to wait for these several seconds to be executed. This delays that task and causes reduced parallelization of tasks.
2025-01-30 11:07:57 +01:00
Jude Gao 8db39d6c00 fix: client-only error message format (#75446)
Looking at the test file change should convince you that this fixes the formatting issue.

https://linear.app/vercel/issue/NDX-671/error-from-client-only-package-is-malformed
2025-01-29 19:33:59 -05:00
Donny/강동윤 8d7b202ed6 build: Update swc_core to v12.0.0 (#75327)
### What?

Update `swc_core` to the next version.

ChangeLog: https://github.com/swc-project/swc/compare/swc_core%40v10.5.0...swc_core%40v12.0.0

### Why?

To apply an enormous amount of performance patches.
2025-01-30 07:24:42 +09:00
Donny/강동윤 3813b2ca82 perf: Update SWC plugins (#75324)
### What?

Applies

 - https://github.com/swc-project/plugins/pull/396
 - https://github.com/swc-project/plugins/pull/397 
 - https://github.com/swc-project/plugins/pull/398
 - https://github.com/swc-project/plugins/pull/399

### Why?

To remove needless allocations.
2025-01-27 17:35:26 +09:00
Hendrik Liebau 7aa61377fb Emit build error when useCache is enabled and Edge runtime is used (#75279)
The `"use cache"` directive is not compatible with the Edge runtime.

When the `experimental.useCache` flag is enabled, we now emit a build
error for pages with `export const runtime = 'edge'`. This is analogous
to using the `experimental.dynamicIO` flag.

The other route segment configs that are forbidden when `dynamicIO` is
enabled, are currently still allowed for `useCache`:

- `dynamicParams`
- `dynamic`
- `fetchCache`
- `revalidate`
2025-01-24 17:33:24 +00:00
Niklas Mischkulnig e431f9e653 Turbopack: migrate global module ids to single-graph (#73752) 2025-01-24 18:16:18 +01:00
Hendrik Liebau bc3e597ae5 Fix export statement validations for app router pages (#75278)
Fixes all issues related to the current export statement validation for
app router pages, as highlighted in #75277.
2025-01-24 17:55:26 +01:00
Hendrik Liebau 958b9669fb Add test fixtures demonstrating export statement validation bugs (#75277)
The issues with the current export statement validation for app router
pages are documented in the added fixtures, see also the inline comments
in the diff.
2025-01-24 17:24:02 +01:00
Donny/강동윤 e3e337b78c perf(turbopack): Reduce needless allocations for SWC plugins (#75275)
### What?

Reduce allocations for SWC plugins, by applying
https://github.com/swc-project/plugins/pull/393

### Why?

Those are actually noop so they should not allocate too much.
2025-01-24 15:44:40 +01:00
Niklas Mischkulnig a2fe4aeccb Turbopack: optimize client manifest generation (#75248)
**View diff without whitespace changes!**

This brings the number of `AssetIdent::path` calls down from 5M to 100k

```
### canary (de984c2695b):
~16,60GB
582.76s user 109.72s system 815% cpu 1:24.95 total
583.30s user 108.45s system 805% cpu 1:25.86 total

### plus mischnic/client-manifest-optimization:
still ~16,60GB
547.70s user 105.24s system 811% cpu 1:20.48 total
550.16s user 108.14s system 782% cpu 1:24.10 total
```
2025-01-24 10:53:50 +01:00
Hendrik Liebau bf726d3c21 Introduce standalone experimental.useCache flag (#75240) 2025-01-24 00:28:05 +01:00
Donny/강동윤 c783ef8b2c perf(turbopack): Use Cow::into_owned instead of .to_string() (#75216)
### What?

`Cow::into_owned()` does not allocate in some cases, while `to_string()` always allocate.

### Why?

In the name of the performance.

### How?
2025-01-23 09:18:36 +00:00
Tobias Koppers c33eb2b650 [Turbopack] use new backend by default (#72434)
<!-- 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 #

-->


Closes PACK-3412
2025-01-23 01:25:04 +01:00
Hendrik Liebau 5f97eb9a80 Fix source mapping of generated cache wrapper calls (#74987)
In the SWC transform we're now using the span of the original `"use cache"` function for the generated cache wrapper call, e.g. so that the captured timeout error stack can be source mapped correctly.

This also fixes the wrongly placed `/*#__TURBOPACK_DISABLE_EXPORT_MERGING__*/` marker for the generated
cache wrapper statements.

**Before:**
<img width="1496" alt="404215955-c354d1f5-4aeb-4f35-9385-a9531219dc4c" src="https://github.com/user-attachments/assets/34d1863a-d557-419f-8477-577bd759341b" />

**After:**
<img width="1496" alt="404215977-a0157fad-a1f8-409a-b9b9-9709e07f7c05" src="https://github.com/user-attachments/assets/f00b7776-6674-4714-b425-d0de994abbff" />

Closes NDX-675
2025-01-23 01:08:57 +01:00
Will Binns-Smith b6a4b0d03c Remove endpoint.write_to_disk() in favor of standardized endpoint.output() (#75059)
This:
- Makes the Endpoint trait not manage any file writing on its own,
instead returning a structure containing OutputAssets, the paths where
the OutputAssets can be found, and the associated Project.
- Allows for OutputAssets to be written at a future point in Turbopack
- Implements `endpoint_write_to_disk` for compatibility in dev. This
continues to be used for prod builds, but in the future it won’t.

In a future PR, production builds will dedupe and unify all output
assets, writing them to disk at once, rather than exposing individual
endpoint writes to JS to occur sequentially.

Test Plan: CI
2025-01-22 13:39:06 -08:00
Niklas Mischkulnig 73efa184f6 Turbopack: don't generate CSS for Node.js (#75117) 2025-01-22 19:06:52 +01:00
Benjamin Woodruff ab87453774 chore(turbopack): Mark ResolvedVc::resolve as deprecated to prevent resolving an already-resolved ResolvedVc (#75168)
Same as we were already doing for `ResolvedVc::to_resolved`.

This function essentially just acts like a deref when called on `ResolvedVc`.

I'd eventually like to replace `Vc::resolve` with `Vc::to_resolved`. These are the easiest callsites to remove.
2025-01-22 09:49:04 -08:00
Jude Gao 07d2820645 Track use cache usage (#75007)
We’re updating the SWC transform to
[track](https://nextjs.org/telemetry) how the "use cache" directive is
used during builds. Each use of "use cache" is counted based on the
handler it’s linked to.

By default, "use cache" counts toward a feature called
"useCache/default". If a custom handler is defined in the Next.js config
(e.g., "custom"), then "use cache: custom" will count toward
"useCache/custom".

The build process will collect these counts and combine them across all
source files and workers. This data is reported under the
NEXT_BUILD_FEATURE_USAGE event, allowing us to filter by "useCache/*" to
see how often each cache handler is used.

*Only support webpack prod build for now.

Closes NDX-683
2025-01-22 11:41:04 -05:00