Commit Graph

1409 Commits

Author SHA1 Message Date
Donny/강동윤 a720ef8e05 refactor(turbopack): Make invalidator flag explicit (#80414)
### What?

Make `#[turbo_tasks::function(invalidator)]` a thing. It's a preparation for the automatic (runtime) detection of statically-analyzable immutable turbo task.

### Why?

We need it for an advanced optimization
2025-06-12 20:40:47 +00:00
Donny/강동윤 51092ee3c1 test(turbopack): Configure HMR benchmark (#80219)
### What?

Configure HMR benchmark. I'm not sure if this benchmark would be stable enough, but let's try.

I'll remove this from the automated benchmark later this week if it turns out to be flaky.

### Why?

x-ref: https://vercel.slack.com/archives/C06PPGZ0FD3/p1748943158878159


### How?

Closes PACK-4758
2025-06-12 14:46:32 -04:00
xusd320 c8ac2a52d8 refactor(turbopack): remove lazy_static dependency (#80226)
## Why
lazy_static  is deprecated, see [Officially deprecate lazy_static #214
](https://github.com/rust-lang-nursery/lazy-static.rs/issues/214)
2025-06-11 10:58:23 -07:00
Donny/강동윤 c8bcde6bf8 feat(turbopack): Add simple tree shaker (#78286)
### What?

Implement a simple tree-shaking. Simple tree shaking is a tree-shaking implementation that only has two options for each export: used/unused. This information is shared among the whole application, so there's no fine-grained control for each export. 

### Why?

Because advanced tree shaking requires some more time to implement.
2025-06-11 14:26:46 +02:00
Luke Sandberg 041c9413ed Require that turbo_tasks::value_trait items be annotated with turbo-tasks::function (#79178)
On its own this is just adding pure overhead.  The next step will be to make it _optional_ for a value_trait item to be a turbo-tasks function.

Part of PACK-4560
2025-06-10 23:35:16 -07:00
Donny/강동윤 60fb2f1c0c build(turbopack): Update swc_core to v27.0.1 (#80338)
### What?

ChangeLog: https://github.com/swc-project/swc/compare/swc_core%40v26.4.4...swc_core%40v27.0.1

ChangeLog for plugins: https://github.com/swc-project/plugins/pull/466

### Why?

Apply `swc_sourcemap` performance optimization.
2025-06-11 03:36:53 +00:00
Benjamin Woodruff 624df11aed fix(next-swc-wasm): Only enable turbo-rcstr's napi feature when building the next-swc-napi crate/package (#80390)
Fixes https://vercel.slack.com/archives/C04KC8A53T7/p1749584921462879

```
pnpm swc-build-wasm
```
2025-06-10 15:31:43 -07:00
Benjamin Woodruff 4250c5b318 feat(turbopack): Invalidate the persistent cache upon panic (#80225)
This is intended as a band-aid "fix" for persistent caching where issues stick around after restarts of the development server. It builds on top of the same codepath we're using for the explicit cache clearing button in the devtools.

As part of this work, this adds a centralized registry for dynamically-registered panic hooks.

## Notes & Next Steps

- I'll disable this behavior for Vercel employees in front, so that we continue to get valuable bug reports.
- I'll follow up with some warning message in the terminal so that the subsequent restart of `next dev` will warn the user that the persistent cache was cleared and that's why build may be slow.
- We've got a some in-progress work handed to me from @wbinnssmith for better logging of anonymized (uncaught) panics to telemetry, so that should be useful in cases like this.
- Yes, this will still invalidate the cache on caught panics. I'm not 100% sure that's the behavior we want, but I think it is.

## Test Plan

Built with:

```
pnpm pack-next -p ~/front/apps/vercel-site
cd ~/front
pnpm i
pnpm turbo --filter=vercel-site dev
```

Restarted a few times and looked at the persistent cache files and saw that they keep accumulating.

Then, deleted a random `.sst` file, restarted, and observed a bunch of panics. Saw that the invalidation file was written. Restarted the server again and saw that it recovered itself by clearing the cache.
2025-06-09 21:10:39 -07:00
Benjamin Woodruff 62f40e55df chore(next-swc-napi): Update tracing-chrome crate to 0.7.2 (#80331)
I noticed that we were depending on the old unmaintained `json` crate
(https://lib.rs/crates/json). Update `tracing-chrome` to a newer version
(https://github.com/thoren-d/tracing-chrome/releases) that uses
`serde_json` instead.
2025-06-09 21:54:17 +00:00
Luke Sandberg 98c5c8d573 [turbopack] Remove the _for_input options from turbo_tasks::value and the TypedForInput trait. (#80185)
# Remove `auto_for_input` serialization mode from turbo-tasks

This PR removes the `auto_for_input` and `custom_for_input` serialization modes from turbo-tasks, along with the `TypedForInput` marker trait.

These were used for values passed via the `Value<>` type, but that is dead.
2025-06-08 20:03:42 -07:00
Luke Sandberg f607d0cf97 [turbopack] Remove the final uses of Value<..> and delete the type (#80144)
Remove the final uses of `Value<..>` and destroy it.

### Why?
The `Value<>` type is confusing and error prone, lets destroy it!

As discussed over slack, turbo_tasks::Value type always implements is_resolved as true and is_transient as false which is incorrect and can enable smuggling transient vcs into turbo tasks.

• https://vercel.slack.com/archives/C03EWR7LGEN/p1743456121241529
• https://vercel.slack.com/archives/C04NGV98TPS/p1743455453764879
2025-06-08 17:36:10 -07:00
Luke Sandberg 1009c5061e [turbopack] Remove uses of Value<..> instead make the payloads impl Taskinput (#80141)
Remove uses of `Value<..>` instead make the payloads impl Taskinput

### Why?
The Value<> type is confusing and error prone, lets destroy it!

As discussed over slack, turbo_tasks::Value type always implements is_resolved as true and is_transient as false which is incorrect and can enable smuggling transient vcs into turbo tasks.

• https://vercel.slack.com/archives/C03EWR7LGEN/p1743456121241529
• https://vercel.slack.com/archives/C04NGV98TPS/p1743455453764879
2025-06-08 09:47:26 -07:00
Luke Sandberg 19e8e3c3c2 Revert "Revert "[turbopack] Compute Import Traces for Issues"" (#80220)
Reverts vercel/next.js#80215 which was a revert of vercel/next.js#79351

Closes PACK-4105
2025-06-07 15:28:07 -07:00
Luke Sandberg 660df3c925 [turbopack] Replace uses of Value<ExecutionEnvironment> with just ExecutionEnvironment (#80135)
Remove Value<ExecutionEnvironment> instead just use ExecutionEnvironment

Why?
The Value<> type is confusing and error prone, lets destroy it!

As discussed over slack, turbo_tasks::Value type always implements is_resolved as true and is_transient as false which is incorrect and can enable smuggling transient vcs into turbo tasks.

• https://vercel.slack.com/archives/C03EWR7LGEN/p1743456121241529
• https://vercel.slack.com/archives/C04NGV98TPS/p1743455453764879
2025-06-06 09:07:35 -07:00
Luke Sandberg 352b80d702 [turbopack] Replace uses of Value<Pattern> with just Pattern
(#80134)

Replace uses of `Value<Pattern>` in the resolve crate with `Pattern`

This required a manual implementation of `TaskInput` which ended up being trivial since there are no captured `Vcs`. However, the `derive` macro failed because it is a recursive type.

### Why?
The Value<> type is confusing and error prone, lets destroy it!

As discussed over slack, turbo_tasks::Value type always implements is_resolved as true and is_transient as false which is incorrect and can enable smuggling transient vcs into turbo tasks.

• https://vercel.slack.com/archives/C03EWR7LGEN/p1743456121241529
• https://vercel.slack.com/archives/C04NGV98TPS/p1743455453764879
2025-06-06 07:04:11 -07:00
Luke Sandberg ae96d7bee6 [turbopack] Remove Value::new wrapper for ServerContextType parameters (#80133)
Remove Value::new wrapper for ServerContextType parameters

### Why?
The Value<> type is confusing and error prone, lets destroy it!

As discussed over slack, turbo_tasks::Value type always implements is_resolved as true and is_transient as false which is incorrect and can enable smuggling transient vcs into turbo tasks.

• https://vercel.slack.com/archives/C03EWR7LGEN/p1743456121241529
• https://vercel.slack.com/archives/C04NGV98TPS/p1743455453764879
2025-06-06 02:44:15 +02:00
Luke Sandberg cc6163aa26 [turbopack] Remove Value::new wrapper for Availabilityinfo parameters (#80132)
Remove Value::new wrapper for Availabilityinfo parameters

### Why?
The Value<> type is confusing and error prone, lets destroy it!

As discussed over slack, turbo_tasks::Value type always implements is_resolved as true and is_transient as false which is incorrect and can enable smuggling transient vcs into turbo tasks.

• https://vercel.slack.com/archives/C03EWR7LGEN/p1743456121241529
• https://vercel.slack.com/archives/C04NGV98TPS/p1743455453764879
2025-06-06 00:49:33 +02:00
Luke Sandberg 0d2e80554a Revert "[turbopack] Compute Import Traces for Issues" (#80215)
Reverts vercel/next.js#79351

See https://github.com/vercel/next.js/actions/runs/15474422003/job/43570614813#step:34:1556
2025-06-05 13:44:39 -07:00
Luke Sandberg 7a66008cae [turbopack] Compute Import Traces for Issues (#79351)
When turbopack reports an issue, compute a set of import-traces for that file so the user can better understand the context of the issue and trivially answer questions like:

* Why is this file included at all?
* Why does next think this is a client-component?

To do this we leverage the `SingleModuleGraph` and use the `astar` algorithm from `petgraph` to compute the shortest path to a root module.  This isn't the most optimal approach but should be sufficient since we don't anticipate this being a performance issue.

A complex part of this is that the module-graph tracks the relationships between _modules_ but Issues are associated with _files_.  While modules are also associated with files this is a many-to-one relationship.  This is why we might report _multiple_ traces for a single issue and also why a single file might appear multiple times in a trace.

## Open formatting questions

* how should we represent paths from other 'filesystems'?
    - for disk filesystems i could compute relative paths to the root of the current directory? the `[project]` filesystem?  For now i just use the filesystem name as a hypothetically cromulent root.


## Alternatives

The main alternative investigated was associating  Issues with `Modules` by collecting them during graph construction. This unfortunately proved to be a non-trivial performance regression and so it was abandoned.  The core problem is that we would need to introduce additional `OperationVc` and task roots to simply `collect` the issues.  This also wouldn't eliminate the duplicate traces issue, and instead we might end up reporting duplicate issues instead.

## Performance
TODO

Closes PACK-4105
2025-06-05 11:21:11 -07:00
Niklas Mischkulnig f684e973f1 Turbopack: ignore module ids config in dev (#80204)
`deterministic` doesn't work with HMR and causes odd errors.

So we'll ignore the `turbopack.moduleIds` config in dev

See https://vercel.slack.com/archives/C03EWR7LGEN/p1748971192561939 as well
2025-06-05 16:41:37 +02:00
Niklas Mischkulnig 1429d72421 Upgrade rust version to 2025-06-04 (#80200)
All code changes come from `cargo clippy --fix` to collapse ifs
2025-06-05 15:46:36 +02:00
Luke Sandberg 1f941656ce [turbopack] Remove uses of Value<ReferenceType> by making ReferenceType a TaskInput (#80130)
Remove `Value::new` wrapper for `ReferenceType` parameters

### Why?

The `Value<>` type is confusing and error prone, lets destroy it!

As discussed over slack, `turbo_tasks::Value` type always implements `is_resolved` as `true` and `is_transient` as `false` which is incorrect and can enable smuggling transient vcs into turbo tasks. 

• https://vercel.slack.com/archives/C03EWR7LGEN/p1743456121241529
• https://vercel.slack.com/archives/C04NGV98TPS/p1743455453764879
2025-06-05 11:11:31 +02:00
Luke Sandberg e6e002d92c [turbopack] Remove uses of Value<ClientContextType> by making ClientContextType a TaskInput (#80127)
Refactor ClientContextType to use TaskInput instead of Value wrapper

### Why?
The `Value<>` type is confusing and error prone, lets destroy it!

As discussed over slack, `turbo_tasks::Value` type always implements `is_resolved` as `true` and `is_transient` as `false` which is incorrect and can enable smuggling transient vcs into turbo tasks. 

• https://vercel.slack.com/archives/C03EWR7LGEN/p1743456121241529
• https://vercel.slack.com/archives/C04NGV98TPS/p1743455453764879
2025-06-05 09:23:09 +02:00
Tim Neutkens 5736391cf6 Turbopack Build: Fix metadata dynamic force-dynamic (#80167)
## What?

`export const dynamic` was not being re-exported when creating the route
handler wrapper so it wasn't picked up during builds, causing the tests
to fail. Added the re-exports.
2025-06-04 19:42:19 +02:00
Luke Sandberg 4e110ef3af [turbopack] Eliminate many calls to into and from and cell involving RcStr (#80076)
Adopt the `rcstr!` macro in turbopack

Instead of `"foo".into()` call `rcstr!("foo")` while being slightly more annoying to type the macro approach is more readabie and faster as it can leverage constant folding for small strings and amortize construction of larger strings.  In general these performance improvement are very small but consistent.

At the same time, eliminate uses of turbo-tasks where they were amortizing construction of RcStr instances since the `rcstr!` macro can do the same thing.  Generally speaking we should prefer `RcStr` over `ResolvedVc<RcStr>` as a task input since it has much more reasonable equality semantics and observationally many of these values were constructed via `Vc::cell("foo".into())`.

## Why?

Generally this should be a small consistent memory and performance improvement.  My understanding is that many uses of `ResolvedVc<RcStr>` actually predate `RcStr` when we were using `String` directly.  In that world, turbotasks are fulfilling a vital function, but now that we can rely on RcStr this is much less needed.

## How?

Mostly this was a bunch of regex replacements and manual fixups.  An AstGrep rule would have been ideal but beyond matching `RcStr::from("...")` this doesn't work since it was mostly calls to `into()` which rely on type inference.  Still by seeding the codebase with the pattern we can probably prevent regressions.

## Performance

From measuring vercel-site this is a latency progression of a few percent.  codspeed agrees!

![image.png](https://graphite-user-uploaded-assets-prod.s3.amazonaws.com/AwJ29EfoPcPdLSwCZxAz/c08ffcaa-2856-4742-a049-1306491d69ba.png)
2025-06-03 19:10:05 -07:00
Benjamin Woodruff b981ac58e1 chore(turbopack): Remove unused dependencies reported by cargo-shear (#80121)
Remove unused dependencies to (hopefully) speed up the build.

https://github.com/boshen/cargo-shear

```
$ cargo shear --expand --exclude=wasm
Analyzing /home/bgw.linux/next.js

No unused dependencies!
```
2025-06-03 17:37:54 -07:00
Joshua Hannaford 0329a7e294 fix(turbopack): Allow google font fetch errors to propagate when in production (#79999)
## Fail Google Fonts in Production Builds When Fetch Fails

### What?
This PR changes the behavior of Google Fonts in Next.js to properly fail
production builds when font fetching fails, while still allowing
development to continue with fallback fonts.

### Why?
Previously, font fetch failures were only logged as warnings but didn't
stop production builds. This could lead to production deployments with
missing fonts, creating a poor user experience. Development mode should
be more forgiving to allow work to continue offline.

### How?
- Added `is_dev_mode()` method to the `ChunkingContext` trait to
determine the current environment
- Modified the Google font fetching logic to:
- In development: Show a warning and use fallback fonts when fetching
fails
- In production: Throw an error that fails the build when fetching fails
- Passed the execution context to the font file replacer to access the
chunking context

This ensures that production builds will fail fast when font resources
can't be fetched, while development builds can continue with appropriate
fallbacks.

Fixes #PACK-4667

### Future Hopes

I would hope to eventually expose an enum for the build mode rather than
just a boolean flag like I have here. I started going down that path for
this PR, but it was expanding the scope significantly of what would have
to be done, so I have left it as a bool to fix this problem.
2025-06-03 17:45:52 +00:00
Hamidreza Hanafi 669a8ca539 Fix(turbopack): Resolve experimentalDecorators from extended tsconfig (#79755)
Co-authored-by: Jude Gao <jude.gao@vercel.com>
2025-06-03 12:25:56 +02:00
Tim Neutkens 4e67ca6117 Turbopack Build: Implement regions for pages router (#80063)
## What?

Implements the missing `regions` property for the edge manifest.
2025-06-03 09:52:01 +02:00
Benjamin Woodruff f30797f8fb fix(napi): Use strong consistency for the entire project_trace_source function (#79917)
This function does a few more `Vc` reads than just looking up the source map, so it's better to move the entire thing inside one strongly-consistent operation.

This was an attempt to fix a loop (tracing an error -> react fast refresh -> triggers the same error again -> ...) https://vercel.slack.com/archives/C046HAU4H7F/p1747837763588429, though it doesn't seem like this fixes it.
2025-06-02 18:02:21 -07:00
Luke Sandberg fb0ce72dc8 [turbopack] Simplify the definition of AssetIdent (#79805)
Replace the `ResolvedVc<RcStr>` uses inside of `AssetIdent` with `RcStr` directly

## Why

This simplifies construction and usage and provides more reasonably equality semantics.  In principle, storing `ResolvedVc` would enable finer grained invalidations.  e.g. if only the `query` changed and a task only depended upon the `modifiers` then that task wouldn't get invalidated.  However, the entire `Assetident` is often consumed monolithically already.  For example, it is when producing output chunks and constructing the modulegraph (via the `to_string` function).  So modeling it more monolitically seems appropriate.

Additionally, by accepting `RcStr` values as _values_ instead of `cells` we clarify equality semantics.  So we should expect to get _more_ cache hits from `AssetIdent::new`.   In principle this may make equality slower, but it is very rare that any of the RcStr instances involved are more than a handful of bytes, so this shouldn't be much of a concern.

This makes the type slightly smaller, now it is `120 bytes` instead of `144 bytes`, which should help with performance a bit since there are many thousands of these in a build.

## What

This was mostly done by just replacing the types and chasing build errors backwards to remove the `ResolvedVc` values at the source.  This allowed me to replace many tiny turbotask functions with the `rcstr!` macro and remove many calls to `cell`.

## Performance

![image.png](https://graphite-user-uploaded-assets-prod.s3.amazonaws.com/AwJ29EfoPcPdLSwCZxAz/70962bb3-5a5a-4762-9580-a38141f84c1c.png)

Testing `vercel-site` reveals a small improvement in MaxRSS which is expected due to 1. eliminating a bunch of turbotask cells, and 2 reducing the size of `AssetIdent`
2025-06-02 08:50:59 -07:00
Tim Neutkens cabf31b2a7 Turbopack Build: Implement locale:false middleware matcher (#80057)
## What?

Found `locale: false` matchers were 99% implemented but the value was
not passed so it didn't work.
2025-06-02 17:37:51 +02:00
Donny/강동윤 d1fa7cfca0 refactor(turbopack): Do not use Result for Rope#read (#80004)
### What?

Use `Cow<'_, [u8]>` instead of `Result<Cow<'_, [u8]>>`. 

### Why?

`RopeReader` never fails.
2025-06-02 07:05:27 -07:00
Tobias Koppers 1f0e536add Turbopack: remove verbose output (#80044)
### What?

Remove unactionable log line. Make log line shorter.
2025-06-02 12:41:41 +02:00
Tim Neutkens aefa6f1526 Turbopack Build: Fix underscore path tests (#79778)
## What?

Implements handling for `%5F` to `_` conversion to handle pathnames in
App Router that want to bypass the underscore ignore folder.

Implementing this was a bit of a hassle not on the Turbopack side but
there's an additional layer of route handling before the compiler that
turns the filesystem paths into routable routes. Turns out there was
some additional places where the normalization needs to apply.

For now implemented it so that it special cases Turbopack handling,
might change the webpack implementation in the future to output the
files into the same path that Turbopack outputs it at. This is only
relevant for dev, production is handled the same already.
2025-05-31 11:40:35 +02:00
Benjamin Woodruff 2ef787b12e [devtools] Add a query parameter to restart endpoint to invalidate the persistent cache (#79425)
Creates and passes through an option to turbopack to invalidate the cache. The dev overlay can then (not implemented) call this endpoint.

Invalidation is performed by writing a marker file to disk, and then actually deleting the cache upon the next startup because:

- Getting the database to drop all file handles is tricky.
- You can't delete open files on Windows.
- Writing an invalidation file is atomic, recursively deleting a directory is not.

### Testing

Set up a small app with a large dependency (three.js). Ran the build, restarted the dev server, saw that the cached run was fast.

Ran

```
curl -v --request POST --header "Content-Type: application/json" --data '{}' http://localhost:3000/__nextjs_restart_dev\?invalidatePersistentCache\=
```

And saw that the server restarted and the next page load was slow.

### Remaining Work (will come in subsequent PRs)

In rough order of priority:

- A separate endpoint to poll to see when the server is back up.
- A webpack+rspack implementation. It looks like I can do a hack to forcibly change the webpack cache version, which should trigger similar behavior upon the next restart.
- Passing a boolean to the dev overlay telling it if persistent caching is enabled or not.
- The devtools UI implementation.
- Telemetry.
- A CLI subcommand that leverages this, so that you can do it from the terminal.
2025-05-30 17:49:14 -07:00
Luke Sandberg 0084361f4b [turbopack] Fix URL fragment and query handling in Turbopack (#79993)
Fix URL fragment and query handling in Turbopack

## What?
This PR improves how URL fragments and query strings are handled in Turbopack by:

1. Standardizing the representation of fragments and queries in `AssetIdent`
2. Ensuring fragments and queries are either empty or include their prefix characters (`#` and `?`)
3. Fixing the URL parsing logic to correctly handle fragments that contain `?` character
4. Removing some ad-hoc workarounds for this issue in the `resolver` and `Assetident::to_string`

## Why?
The previous implementation had inconsistencies in how fragments and queries were represented which lead to a variety of confusing issues e.g. does `AssetIdent::to_string` need to add a `?` ?, well sometimes depending on how it was constructed.
2025-05-30 11:09:35 -07:00
Luke Sandberg 1f39908c97 Remove subissues from Issue (#79988)
Remove `sub_issues` from Issue representation

It is dead.

Part of PACK-4105
2025-05-30 10:58:10 -07:00
Niklas Mischkulnig 1d11db3cba Turbopack: more deterministic manifest order (#79977)
Fix non-deterministic next font manifest order:

![Bildschirmfoto 2025-05-30 um 15.41.12.png](https://graphite-user-uploaded-assets-prod.s3.amazonaws.com/sjZSbv6AFeuDg7Gb9rma/e2de4601-a90e-41db-ac4c-7fde7ffec146.png)
2025-05-30 17:26:18 +02:00
Tobias Koppers 9ff3f848a6 Turbopack: only keep old database version if not on CI (#79964)
<!-- 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-05-30 14:13:35 +02:00
Benjamin Woodruff 8fa42deefd refactor(napi): Implement napi traits for RcStr (#79806)
This lets us use `RcStr` directly in function arguments and as part of `#[napi(object)]`s.

*You can just `RcStr` things!*

Here's an example of rspack doing something similar for a custom napi type: https://github.com/web-infra-dev/rspack/blob/35f1126963d5ba6860e9eba939fd5d62f9aa217f/crates/rspack_regex/src/napi.rs
2025-05-28 17:09:45 -07:00
Luke Sandberg 21182268f7 [turbopack] Reduce the size of module graph datastructures (#79706)
## Refactor module graph to reduce memory usage

### What?
This PR refactors the module graph implementation to reduce memory usage by:
1. Changing `graph_idx` from `usize` to `u32` to reduce memory footprint
2. Removing unused fields from `SingleModuleGraphModuleNode` (layer and issues)
3. Moving layer resolution to the point of use in dynamic imports and server actions

This is a small progression in runtime:

![image.png](https://graphite-user-uploaded-assets-prod.s3.amazonaws.com/AwJ29EfoPcPdLSwCZxAz/d669023b-9ac4-44d5-ac9f-54e42b71d341.png)

### Why?
These changes optimize memory usage in the module graph, which is particularly important for large applications. By removing unused fields and using more compact types, we can reduce the memory footprint of the graph.

Notably, SingleModuleGraphNode is now 24 bytes instead of  48.  To make it smaller still we would need to reduce the size of visited moduel, perhaps by storing a reference to the graph that did the original visit?  This would be tricky from a lifetimes perspective but much more optimal.
2025-05-28 11:53:29 -07:00
Joshua Hannaford 826da1f786 update(turbopack): Update the messaging UX for timing writing files to disk (#79469)
## Refactor Turbopack Compilation Events and Timing Reporting

### What?
This PR refactors how compilation events are created, displayed, and
formatted in Turbopack. It introduces a dedicated `TimingEvent` type for
timing-related messages and improves the formatting of duration
displays.

Additionally we now display all compilation events now that it has been
shown to be stable with no breakages.

### Why?
To provide more consistent and user-friendly output for compilation
events, especially for timing information. The new approach makes
duration formatting more readable by automatically selecting appropriate
units (ms, s, min) based on the duration length.

### How?
- Added a new `TimingEvent` struct that properly formats durations based
on their duration
- Updated the `DiagnosticEvent` constructor to take severity first, then
message
- Improved event handling in the build process to properly categorize
and display different severity levels
- Enhanced file I/O benchmarking to use the new timing event format
- Fixed the formatting of compilation events in the UI

---------

Co-authored-by: Niklas Mischkulnig <4586894+mischnic@users.noreply.github.com>
2025-05-27 16:52:11 -04:00
Hendrik Liebau 1f25118390 Fix name tracking for closures in server actions transform (#79657)
When a server function passes a closure to a method on a closed-over
value (e.g. an array), we must correctly track the value itself so that
it's included in the bound arguments.

For example, in this snippet, `list` must be bound to the server action:

```js
export function Component({ list }) {
  return (
    <form
      action={async () => {
        'use server'
        console.log(list.find((x) => !!x))
      }}
    >
      <button>submit</button>
    </form>
  )
}
```

This use case used to work but was accidentally broken by #73189.

fixes #79608
fixes #77247
closes NAR-8
2025-05-27 17:23:25 +02:00
Tim Neutkens 9225917fdc Turbopack Build: Fix runtime value test (#79654)
## What?

Ensures the warning message is the same between webpack/Turbopack.

Found that Turbopack does have the info we check in the test but it's
currently not logged, seems intentionally. Need to check with
@wbinnssmith because it was commented out here:
https://github.com/vercel/next.js/blob/d1d64ea12ff819035d1abdb6f9e9b8aac950457f/packages/next/src/shared/lib/turbopack/utils.ts#L198

When `detail` is logged it will include more information like what
exactly was wrong.
2025-05-27 15:44:39 +02:00
Tim Neutkens 7cbc15ab70 Turbopack Build: Fix conflicting page error (#79634)
## What?

Implements the missing part of the error to make the test pass.

Small difference between webpack/Turbopack is that Turbopack will spot
the conflict earlier and because of that errors earlier too, making the
path still correct but shorter, not a problem in my opinion.

---------

Co-authored-by: Niklas Mischkulnig <4586894+mischnic@users.noreply.github.com>
2025-05-27 15:43:43 +02:00
Tim Neutkens 0eb276b4ca Turbopack Build: Fix edge _document test (#79628)
## What?

Currently there's a specific case when you set `runtime:
'experimental-edge'` for `_document.js` or `_app.js` where we
incorrectly write a bundle that is wrapped with the route handling code
to disk. This in turn causes `_document.js` to break during
prerendering. Seems no users ran into this one yet since it was
experimental. This change ensures that we always write the module code
for _app / _document instead. This has no negative effect on edge
runtime modules because those include the direct imports for _app /
_document already in the single route module.
2025-05-27 15:43:29 +02:00
Will Binns-Smith 185b4b76d0 Turbopack: derive de/serialize for loader config (#79581) 2025-05-27 07:14:19 +00:00
Benjamin Woodruff f2e448ead4 chore(turbo-tasks): Remove old and unused turbo-tasks-memory backend (#79560)
I'm deleting all of @sokra's hard work in favor of @sokra's hard work.

RIP memory backend, you served us well 🫡

The new `turbo-tasks-backend` supports both persistent (via LDMB or `turbo-persistence`) and in-memory databases (via the no-op storage implementation), and tends to be faster than `turbo-tasks-memory` when used with the no-op storage. Maintaining both has increasingly become a headache.
2025-05-26 22:30:03 -07:00
Donny/강동윤 c810c30c4e test(next-swc): Add tests for the React Compiler support (#79499)
### What?

Add tests for the interestingness detection for the RC

### Why?
2025-05-23 17:21:16 +00:00