Commit Graph

60 Commits

Author SHA1 Message Date
Benjamin Woodruff ‮ 7b58e5880c Turbopack: Add support for specifying additional roots (#98003)
Full motivation and plan here:
https://app.notion.com/p/vercel/Turbopack-pnpm-Global-Virtual-Store-383e06b059c480579403ddfd71cc2d40?source=copy_link

The goal is to allow `DiskFileSystem` to traverse outside of it's own
root to other configured `DiskFileSystem`s when following symlinks. We
may allow traversal in other situations in the future, but this is
limited to symlink resolution for now.

## Global Virtual Store

The motivation for this is to enable [pnpm's Global Virtual Store
feature](https://pnpm.io/global-virtual-store) (and there are other
package managers doing this, including nub and bun).

We'd expose the ability to manually configure this in `next.config.js`,
but we should also auto-configure ourselves for popular package managers
(or at least make a best effort to do so, the `PNPM_HOME` semantics can
be complicated). The `ignoreIfMissing` option is provided for this
situation: We can configure a bunch of roots automatically, and they
only actually get set up if they exist, the check for directory
existence is cheap.

## NFT changes

This requires a couple extensions to the `*.nft.json` file format:
https://github.com/vercel/next.js/pull/98469

## Related Issues

- #93556
- https://github.com/pnpm/pnpm/issues/14972
2026-09-18 17:08:40 -07:00
Will Binns-Smith d5276f04a1 Make TurbopackResult payloads disjoint (#98575)
### 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: vercel-fleet-prod[bot] <318278635+vercel-fleet-prod[bot]@users.noreply.github.com>
Co-authored-by: Will Binns-Smith <755844+wbinnssmith@users.noreply.github.com>
2026-09-11 16:25:09 -07:00
Will Binns-Smith e2fb664ceb Remove HmrTarget (#97253)
With #94948 we intended to move the client over to the firehose feed of
HMR events with the intent of unifying the code paths for maintenance.
However, now that Server HMR is moving to a pull-based model (which
client HMR will not be able to implement), let's keep the split.

There's no need to encode the HmrTarget into each surface, and we can
just use the function name to indicate which mode of HMR it's for.
2026-08-19 17:22:47 -07:00
Sam Poder bb9af37519 [turbopack] Rename rscEndpoint to rscHmrEndpoint (#95538)
I'm introducing a new endpoint that doesn't compile SSR when doing a
page navigation, I'd like to call it a `rscEndpoint` but currently this
name is taken. `rscEndpoint` appears to be used for detecting changes
for HMR so I've renamed it to `rscHmrEndpoint` so I can use that name
for the new `rscEndpoint`.
2026-07-07 18:19:40 -07:00
Luke Sandberg f32234cc1a Turbopack: Add an experimental option for eviction (#94439)
`experimental.turbopackMemoryEviction = "full" | false`

controls the new feature, currently it is disabled.
2026-06-07 16:38:35 +00:00
Tim Neutkens 7da98e1318 Convert more tests from createNext -> nextTestSetup (#93799)
## What?

Converts more tests that use `createNext` to `nextTestSetup`

Follow-up to #93767

---------

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-18 09:51:36 +02:00
Luke Sandberg e8f8f498e8 [turbopack] fix feature usage telemetry (#93100)
## Report Turbopack feature-usage telemetry

Turbopack never reported `NEXT_BUILD_FEATURE_USAGE` telemetry for production builds. This PR wires it up and fixes a correctness bug in how the counts were computed, then cleans up the API surface that carried them across the napi boundary.

### Changes

- **JS**: `turbopackBuild()` now records `EVENT_BUILD_FEATURE_USAGE` events after `writeAllEntrypointsToDisk` via a new `eventBuildFeatureUsageFromTurbopackDiagnostics` helper. Dev is out of scope — webpack's `TelemetryPlugin` is `!dev && isClient` too.
- **Rust**: aligned feature names with the JS `EventBuildFeatureUsage['featureName']` union — SWC triple is now `swc/target/<triple>`; dropped `persistentCaching` (redundant with `turbopackFileSystemCache`) and `turbotrace: false` (hardcoded).

### Correctness fix: count unique importers, not resolves

Previously feature-usage counts for module imports (`next/image`, `next/font/google`, …) were computed from a `BeforeResolvePlugin` that emitted one event per resolve. Turbopack caches resolves, so the emission fired at most **once per unique request** — the count was effectively `1` for every feature that was imported anywhere. Webpack's equivalent counts unique importing modules via `moduleGraph.getIncomingConnections(module).size`.

This PR replaces the resolve-plugin emission with a single whole-app module-graph traversal on `Project`. For each tracked feature, we accumulate the set of unique parent modules of each matching node (mirroring webpack's "unique origin modules" semantics). Fonts are matched against their synthesized `/target.css?…` virtual modules produced by the SWC font-loader transform — matching webpack's `FEATURE_MODULE_REGEXP_MAP` approach. Paths are matched via `phf_map!` tables in `next_telemetry.rs`.

### Incidental simplifications

While in here, the `Diagnostic` collectibles subsystem got right-sized and then removed entirely, since feature usage was its only consumer:

- `Project::project_feature_usage()` returns a structured `Vc<ProjectFeatureUsageSummary>` instead of emitting diagnostics. Surfaced to JS as a dedicated `project.featureUsage(): Promise<BuildFeatureUsage[]>` napi method, called once at build's end.
- `TurbopackResult<T>` loses its `diagnostics: BuildFeatureUsage[]` field — it's now just `{ result, issues }`. Every napi result type and ~10 construction sites are correspondingly simpler.
- Deleted `turbopack_core::diagnostics` entirely (`Diagnostic` trait, `DiagnosticExt`, `DiagnosticContextExt`, `CapturedDiagnostics`, `PlainBuildFeatureUsage`). Deleted `FeatureUsageTelemetry`, `ModuleFeatureReportResolvePlugin`, `get_diagnostics()` aggregation, the `feature_usage`/`diagnostics` fields on `AllWrittenEntrypointsWithIssues`/`OperationResult`/`EntrypointsWithIssues`/`WrittenEndpointWithIssues`/`HmrUpdateWithIssues`/`HmrChunkNamesWithIssues`/`EndpointIssuesAndDiags`/`WriteAnalyzeResult`, and the defensive `drop_collectibles::<Box<dyn Diagnostic>>()` scrub in `entrypoints_without_collectibles_operation`.

Feature-usage telemetry now flows as a plain return value end-to-end: `Project::project_feature_usage()` → napi `projectFeatureUsage()` → JS `project.featureUsage()` → `telemetry.record()`. No collectibles, no peeking, no emission-as-side-effect.

### Tests

Un-skipped four previously webpack-only integration tests in `test/integration/telemetry/test/config.test.ts`: `image/script/dynamic`, `next/legacy/image`, `transpilePackages`, and middleware options. All pass under Turbopack. The remaining three skipped tests (`swc` flags, `@vercel/og`, `useCache`) cover features Turbopack doesn't emit yet — left skipped with TODOs.

Added unit test for the helper at `packages/next/src/telemetry/events/build.test.ts`. Updated the Turbopack `next-rs-api` snapshot to reflect the new diagnostic shape.

<!-- NEXT_JS_LLM_PR -->
2026-05-10 17:50:30 -07:00
Niklas Mischkulnig 26cfeb8531 Allow overriding outputHashSalt in modifyConfig (#92856) 2026-04-16 12:43:26 +02:00
Tobias Koppers 69264a763f test: reduce writeToDisk memory test iterations to fix CI timeout (#92586)
### What?

Reduces `RUNS` from 10,000 to 1,000 in the `next.rs api writeToDisk
multiple times` test in `test/development/basic/next-rs-api.test.ts`.

### Why?

The test was frequently timing out on CI. It spawns a child `node
--expose-gc` process that calls `writeToDisk()` in a loop (`RUNS` times
per batch) for each discovered route (~11 routes), with up to 11
measurement batches per route. At 10,000 runs per batch that is up to
~1.1 million `writeToDisk()` calls total — all under the global
60-second Jest timeout.

Each call, even in the turbo-tasks memoized steady state, has
non-trivial overhead: an NAPI crossing, a task-cache lookup, a
`read_strongly_consistent()` wait, and an O(N effects) iteration over
output assets (each requiring a mutex acquisition). On slow CI hardware
this easily exceeds 60 seconds.

### How?

Reduce `RUNS` to 1,000. This gives a 10× speedup without compromising
the test's ability to detect memory leaks: a leak of even a single OS
page (4 KB) per 1,000 calls is still detectable via the RSS delta check.
The warmup + measurement loop structure is unchanged.

<!-- NEXT_JS_LLM_PR -->

Co-authored-by: Tobias Koppers <sokra@users.noreply.github.com>
Co-authored-by: Claude <noreply@anthropic.com>
2026-04-10 08:52:46 +00:00
Tobias Koppers 3e0158846e feat: add NEXT_HASH_SALT env var for content-hash filename salting (#91871)
### What?

Adds a `NEXT_HASH_SALT` environment variable **and** a
`experimental.outputHashSalt` config option that mix a user-supplied
string into every content-addressed hash used to generate chunk
filenames and static asset filenames. This works for both Webpack and
Turbopack.

When both are set, the values are concatenated (`outputHashSalt +
NEXT_HASH_SALT`), so a per-project salt can be baked into
`next.config.js` while a per-deployment salt is injected at build time
via the environment variable.

### Why?

Content-addressed filenames (e.g. `chunk.abc123.js`) are derived from
file content, so they only change when the content changes. There are
deployment scenarios where you need to force all filenames to rotate —
for example after a CDN misconfiguration has poisoned caches for a
particular hash space — without actually changing source code. A stable,
opt-in salt lets operators do this without touching application code.

Some customers prefer the config-file approach
(`turbopack.outputHashSalt`) over environment variables, so both are
supported.

### How?

**Webpack** already has `output.hashSalt` in its config. We simply
forward `NEXT_HASH_SALT` to that option.

**Turbopack** required threading the value through several layers:

1. The effective hash salt is computed once in
`assignDefaultsAndValidate` as `config.turbopackHashSalt =
(turbopack.outputHashSalt ?? '') + (NEXT_HASH_SALT ?? '')` and stored on
`NextConfigComplete`. Both `turbopackBuild` (production) and
`createHotReloaderTurbopack` (dev) read from this single field.
2. `ProjectOptions.hash_salt` receives the pre-computed salt.
3. `Project` stores the salt and passes it into the three chunking
context option structs (`ClientChunkingContextOptions`,
`ServerChunkingContextOptions`, `EdgeChunkingContextOptions`).
4. Both `BrowserChunkingContext` and `NodeJsChunkingContext` gain a
`hash_salt: RcStr` field.
5. A new `deterministic_hash_with_salt(salt, input, algorithm)` function
in `turbo-tasks-hash` writes the salt bytes first, then the content
bytes, into a single hasher — one pass, no hash-of-hash composition.
6. A matching `content_hash_with_salt` method is added to `FileContent`
and `AssetContent`.
7. `ChunkingContext::asset_path` is changed to accept `Vc<AssetContent>`
(instead of a pre-computed `Vc<RcStr>`) so the chunking context can
choose the correct hash path itself. `StaticOutputAsset::path`
simplifies accordingly.

Without `NEXT_HASH_SALT` and without `turbopack.outputHashSalt` set,
behaviour is identical to before — no hash change, no performance
impact.

**e2e test** (`test/production/app-dir/hash-salt/`) verifies:
- Two builds with the same salt produce identical chunk and static asset
filenames.
- A build with a different salt produces different filenames.
- `turbopack.outputHashSalt` (config) changes filenames vs no salt.
- Combined config + env salt differs from either alone.
- Runs for both Turbopack and Webpack.

---------

Co-authored-by: Tobias Koppers <sokra@users.noreply.github.com>
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Luke Sandberg <lukesandberg@users.noreply.github.com>
2026-04-01 22:03:50 +02:00
Tobias Koppers 891cfe69c8 Turbopack: Add Next.js version to "initialize project" trace span (#90545)
## Summary

Adds the Next.js version as a `version` field on the Turbopack
"initialize project" tracing span. The version is passed from the
TypeScript side (`process.env.__NEXT_VERSION`) through the NAPI bindings
into Rust `ProjectOptions`, where it is recorded on the span.

This makes it easy to correlate trace data with the specific Next.js
version that produced it.

Also standardizes all version reads in `packages/next/src/` to use
`process.env.__NEXT_VERSION` (which is inlined at build time by
`taskfile-swc.js`) instead of `require('next/package.json').version` or
`import { version } from 'next/package.json'`.

### Changes

**Trace span (commit 1):**
- **`crates/next-api/src/project.rs`** — Added `next_version` field to
`ProjectOptions`; recorded as `version` on the `"initialize project"`
span
- **`crates/next-napi-bindings/src/next_api/project.rs`** — Added
`next_version` to `NapiProjectOptions` and wired it through the `From`
impl
- **`crates/next-build-test/src/main.rs`** — Added `next_version` to
test `ProjectOptions` init
- **`packages/next/src/build/swc/generated-native.d.ts`** — Added
`nextVersion` to the TypeScript `NapiProjectOptions` interface
- **`packages/next/src/server/dev/hot-reloader-turbopack.ts`**,
**`packages/next/src/build/turbopack-build/impl.ts`**,
**`packages/next/src/build/turbopack-analyze/index.ts`** — Pass
`nextVersion: process.env.__NEXT_VERSION` when creating the Turbopack
project
- **`test/development/basic/next-rs-api.test.ts`** — Added `nextVersion`
to both `createProject` call sites

**Consistent `__NEXT_VERSION` usage (commit 2):**
- **`packages/next/src/server/dev/hot-reloader-shared-utils.ts`** —
`require('next/package.json').version` → `process.env.__NEXT_VERSION`
- **`packages/next/src/lib/patch-incorrect-lockfile.ts`** —
`nextPkgJson.version` → `process.env.__NEXT_VERSION`; narrowed import to
only `optionalDependencies`
- **`packages/next/src/telemetry/events/swc-load-failure.ts`** — `import
{ version as nextVersion }` → `process.env.__NEXT_VERSION`; narrowed
import to only `optionalDependencies`

## Test Plan

- Verified Rust compilation with `cargo check -p next-api`, `cargo check
-p next-build-test`
- Verified TypeScript types with `pnpm --filter=next types`

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-02-26 18:37:15 +01:00
Will Binns-Smith aac4ebb7ac Turbopack: Server HMR infrastructure (#88870)
This adds some basic JavaScript/TypeScript infrastructure for Next to receive and handle server-side HMR updates from Turbopack.

This:
- Renames some existing hmr code as explicitly client hmr
- Adds counterpart apis for server hmr (e.g. subscribe to server HMR events via `project.serverHmrEvents()`)
- Add `__turbopack_server_hmr_apply__` runtime function (this is a stub for now, just logs on updates)

**Alternatives considered**
A single firehose for hmr events, pushing the filtering to the JS side. I figured separate dedicated apis would be cleaner since they’d have to be filtered and switched on anyway.

**In future PRs**
- Rust: Make Turbopack send 'partial' updates for server file changes
- Node dev runtime: Implement module factory replacement in `__turbopack_server_hmr_apply__`
- add client notification to trigger re-fetch of rsc
- e2e tests
2026-02-10 12:20:52 -08:00
Niklas Mischkulnig a2ee2d5830 Turbpopack: fix is_persistent_caching_enabled (#89533)
The next config setting was renamed, so this was always false.

So far, this was only used for telemetry.
2026-02-05 21:37:05 +01:00
Tobias Koppers f7b7f3c14f Turbopack: add NEXT_TURBOPACK_WRITE_ROUTES_HASHES_MANIFEST to write hashes into manifest (#86257)
### What?

Add an env var to write route hashes into a diagnostics file.
2025-11-20 22:47:20 +01:00
Joshua Hannaford df6aed34f0 fix(Turbopack): Add better error messaging for when we can't determine Next.js root (#83918)
## Improve error message when Next.js package can't be found

### What?
Enhances the `get_next_package` function to provide a more informative
error message when the Next.js package cannot be found from the context
directory.

### Why?
When users encounter issues with Next.js package resolution, the
previous generic error message "Next.js package not found" didn't
provide enough context or guidance on how to fix the problem. The
improved error message explains potential causes and solutions.

### How?
- Updated the function to use Vc<FileSystemPath> for context_directory
- Improved error handling with a detailed message that:
  - Explains the issue clearly
  - Shows the context directory path where resolution failed
  - Suggests setting `turbopack.root` in the Next.js config
  - Mentions potential issues with symlinks
  - Provides a link to documentation for more information

### How to Test

To test this, 
1. Modify `<projectRoot>/bench/basic-app/next.config.js` to 
    ```js
    module.exports = {
      experimental: {
        serverMinification: true,
      },
      turbopack: {
        root: __dirname,
      }
    }
    ```
2. Run `pnpm build && pnpm swc-build-native` to ensure that you have the
updated code
3. Run `pnpm next dev --turbo bench/basic-app` and ensure the error
shows up exactly once
4. Run `pnpm next build --turbo bench/basic-app` and ensure the same
error shows up exactly once

---------

Co-authored-by: Niklas Mischkulnig <4586894+mischnic@users.noreply.github.com>
Co-authored-by: Luke Sandberg <lukeisandberg@gmail.com>
2025-10-06 19:43:58 +00:00
Tobias Koppers 2838b8b0a5 Turbopack: add test case that checks memory leak (#83849)
### What?

add test case for memory leak
2025-09-19 10:20:32 +02:00
Tim Neutkens af962cb257 Turbopack: Remove passing jsConfig (#83331)
## What?

These values were only provided to emit events and not for the actual
handling of jsconfig/tsconfig `paths` and such, those are handled
separately by Turbopack itself. This removes the events as they're no
longer relevant and it's not worth slowing down dev/build for them.
2025-09-04 12:41:03 +02:00
Niklas Mischkulnig 443a31b990 Turbopack: fix dist dir on Windows (#81758)
Regression from #80683

Closes PACK-5071
Closes https://github.com/vercel/next.js/issues/81628
2025-07-19 07:56:41 +02:00
JJ Kasper 58bc2f112c Migrate usage of web-server in edge-ssr (#80915)
This continues the work for the `handlers` interface for the edge
runtime and re-uses the existing `route-module` interface we have
instead of initializing and using `web-server`/`base-server`.

Validated against our deploy tests
https://github.com/vercel/vercel/actions/runs/15987684940/job/45095833866?pr=13505
https://github.com/vercel/next.js/actions/runs/15987664161/job/45095390463
2025-07-02 10:18:13 -07:00
Niklas Mischkulnig c2be57cc1d Turbopack: pass current Node.js version from JS side instead of invoking node (#80949) 2025-06-27 08:27:16 +02:00
Tim Neutkens 5802ba8122 Turbopack Build: Implement browserslist for CSS / JS (#80603)
## What?

Implement browserslist for CSS / JS handling in Turbopack.

For JS it's not fully implemented yet, but for CSS it should be good
now.
2025-06-24 19:11:06 +02:00
Sebastian "Sebbie" Silbermann 100881542a [test] Use NEXT_TEST_CI when forking test in CI (#79354) 2025-05-21 20:29:19 +02:00
JJ Kasper d937203f39 Implement initial handler interface for pages routes (#79260)
Continuation of https://github.com/vercel/next.js/pull/78166 this
implements the `handler` interface for pages routes, This does not move
the response handling inside of the handler yet as that will be in a
follow-up PR to keep the changes isolated. This still returns the
`RenderResult` for the `base-server` to continue to handle.

Validated against `vercel/vercel` deploy tests here
https://github.com/vercel/vercel/pull/13349
2025-05-20 16:23:50 -07:00
Hendrik Liebau 07e6680ddf Restore --no-mangling CLI option for next build (#75921)
The `--no-mangling` CLI option for `next build` was originally
introduced in #42633. However, we lost this feature during our migration
from Terser to SWC. As part of broader improvements for debugging
dynamic accesses with Dynamic I/O enabled, I needed this functionality
back, so I restored it for Webpack and also added it to Turbopack.

fixes #67037
fixes #50208

---------

Co-authored-by: Benjamin Woodruff <benjamin.woodruff@vercel.com>
2025-02-12 11:08:03 +00:00
Will Binns-Smith f4177614a0 Split entrypoint/route handling into separate dev and prod versions (#75169)
Currently, for `handleEntrypoints`, `handlePagesErrorRoute`,
`handleRouteType`, etc, both dev and prod use cases are combined into
the same functions. This leads to a lot of branching, use-case-specific
arguments, etc. for minimal opportunity for shared code.

In a following PR, entrypoint writing for prod will be done through a
single napi call to rust, further branching the two versions.

This splits them formally, at the cost of duplicating a handful of lines
in each case. Perhaps in the future we can develop a better system for
sharing code, but this makes things far clearer and easier to maintain
in this moment.

Test Plan: CI
2025-01-23 14:25:27 +01:00
Jude Gao d6dd69f210 (e2e) module-level patchFileDelay flag (#72439) 2024-11-12 06:29:03 -05:00
Benjamin Woodruff 80384ac110 Revert "feat(turbopack): Add an env var to debug-print the fast refresh invalidation reason (#72296)" (#72421)
Not sure why this is happening, but @kdy1 bisected this commit to a null pointer assertion error in napi: https://vercel.slack.com/archives/C03EWR7LGEN/p1730901839682439?thread_ts=1730899709.760659&cid=C03EWR7LGEN

Reverting until I can repro and root cause.

Closes PACK-3402
2024-11-06 11:10:18 -08:00
Benjamin Woodruff 8abe1fd55b feat(turbopack): Add an env var to debug-print the fast refresh invalidation reason (#72296)
Setting the environment variable when building (`next dev`)

```
NEXT_TURBOPACK_INCLUDE_UPDATE_REASONS=1
```

causes `[Update Reasons]` messages to be logged to the terminal console (not in the browser) when a file is changed:

![Screenshot 2024-11-04 at 4.31.16 PM.png](https://graphite-user-uploaded-assets-prod.s3.amazonaws.com/HAZVitxRNnZz8QMiPn4a/1af5a4f0-cfba-4ca8-b188-d6be2064b0dc.png)

These messages will not appear if no reason was recorded when the invalidation happened, so this provided on a best-effort basis.

**Why?** The hope is that this can help debug cases where users get stuck in a fast refresh update loop: https://vercel.slack.com/archives/C03S8ED1DKM/p1730737898652749

Closes PACK-3374
2024-11-05 10:49:41 -08:00
Tobias Koppers 3b9889e1d8 [Turbopack] add new backend (#69667)
### What?

Add a new turbo-tasks backend that stores data normalized and is
prepared for persistent caching.

No longer keeps state in task locals, but all state is stored
immediately. This is required for persistent caching since it could
store and resume at any point and we always need to be in a valid state.

Tasks stay dirty until recomputed. (Previously dirty was changed to
scheduled)

### Why?

* Reduced memory usage
* preparation for persistent caching
2024-10-04 09:57:55 +02:00
hrmny 35a053a91a feat(turbopack): add support for polling file watcher (#69684)
### What?
The normal file watcher doesn't work inside a docker container, the
workaround is to enable a polling file watcher, which was supported in
webpack but not turbopack so far.

This PR adds support for a polling file watcher to turbopack and a
`next.config.js` option to configure the polling file watcher for both
webpack and turbopack.


Unfortunately, the rust file watcher seems to be a lot slower than the
poll interval.

Closes PACK-3206
Fixes #68255
2024-10-01 19:48:05 +02:00
Sebastian "Sebbie" Silbermann 1cb6faaee1 Extend support of Pages router to React 18 (#70219) 2024-09-25 19:08:13 +02:00
hrmny 0539477e7c types: improve napi binding typing using generated types (#69680)
### Why?

All the `any` and `unknown` types kept bothering me.

I've also removed some unused napi functions
2024-09-24 16:39:19 +02:00
Tim Neutkens ab493f1583 Turbopack dev/build: Initial browserslist passing (#69781)
## What?

This implements passing the browerslist config from Next.js to
Turbopack. Initially I implemented passing the user browserslist config
in this PR as well but found that when this is lowered it causes test
failures, those need to be investigated separately but shouldn't block
these changes landing.

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

-->
2024-09-09 12:11:33 +02:00
hrmny 64b718c661 chore: update prettier to 3.2.5 (#65092) 2024-05-08 21:47:14 +02:00
JJ Kasper dcff078936 Re-land build(edge): extract buildId into environment (#65426)
### What

* Extract `buildId` and server action encryption key into environment
variables for edge to make code more deterministic
* Fixed the legacy bad env names from #64108
* Always sort `routes` in prerender manifest for consistent output
* Change `environments` to `env` in middleware manifest, confirmed with
@javivelasco this is a fine change without need to bumping the version

### Why

Dynamic variants like `buildId`, SA `encryptionKey` and preview props
are different per build, which results to the non determinstic edge
bundles. Once we extracted them into env vars then the bundles become
deterministic which give us more space for optimization


Closes NEXT-3117

Reverts vercel/next.js#65425

Co-authored-by: Jiachi Liu <inbox@huozhi.im>
2024-05-08 10:40:15 +02:00
JJ Kasper 85a874a35b Revert "build(edge): extract buildId into environment" (#65425)
Needs to hold until upstream roll-out

Reverts vercel/next.js#64521
2024-05-06 16:54:23 -07:00
Jiachi Liu ce99c61b9e build(edge): extract buildId into environment (#64521)
### What

* Extract `buildId` and server action encryption key into environment
variables for edge to make code more deterministic
* Fixed the legacy bad env names from #64108
* Always sort `routes` in prerender manifest for consistent output
* Change `environments` to `env` in middleware manifest, confirmed with
@javivelasco this is a fine change without need to bumping the version

### Why

Dynamic variants like `buildId`, SA `encryptionKey` and preview props
are different per build, which results to the non determinstic edge
bundles. Once we extracted them into env vars then the bundles become
deterministic which give us more space for optimization


Closes NEXT-3117

---------

Co-authored-by: Tobias Koppers <tobias.koppers@googlemail.com>
Co-authored-by: JJ Kasper <jj@jjsweb.site>
2024-05-06 16:52:24 -07:00
Jiachi Liu 1e3a1cbaab Upgrade typescript to 5.3 (#64043)
Closes NEXT-2997

---------

Co-authored-by: eps1lon <sebastian.silbermann@vercel.com>
2024-04-17 18:35:29 +02:00
Tim Neutkens 54adb71a8d Ensure undefined values end up being replaced (#63138)
## What?

Follow-up to #63128

`JSON.stringify(undefined)` ends up with the value `undefined`. However
for Webpack/Turbopack to correctly inject `undefined` into the code it
has to be the string `'undefined'`. This change ensures the
serialization takes into account that case.

<!-- 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 NEXT-2773
2024-03-12 16:04:50 +01:00
Tim Neutkens c262e6118f Consistently use /_not-found for not found page in App Router (#62679)
## What?

#62528 caused test/e2e/app-dir/not-found/conflict-route to fail
compilation in Turbopack, this compiler error was previously already
reported by Turbopack but Next.js didn't show it, which #62528 resolved.

This PR changes the handling for the not-found handling to be consistent
between development and build, which ensures that the "special" page no
longer conflicts with app/not-found/page.js.

Closes NEXT-2617


Note: this is a reworked iteration of
https://github.com/vercel/next.js/pull/62585 which wasn't sufficient.

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

-->
2024-02-29 14:47:31 +00:00
Leah ecb4d7484e refactor(turbopack): resolve routes by page name instead of pathname (#61778)
### Why?

We currently use `page` and `pathname` in different places for file
system paths (manifests can be in a different folder to the js entry),
this PR makes more things just use `page` directly instead of going
through `pathname`.

This PR also adds an entry key (similar to the webpack version) uniquely
identifying all entry points (and assets).


Closes PACK-2432
2024-02-19 15:13:39 +00:00
Tim Neutkens b3cd381d76 Add dev option to Turbopack createProject() (#62083)
## What?

Adds the `dev` option to switch between development and production
output flags for Turbopack.
Note: This only adds the option, the `false` value (production) doesn't
work yet.

<!-- 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 NEXT-2499
2024-02-15 13:50:08 +01:00
Tim Neutkens 0a58a0d07f Remove leftover server addr references (#61997)
## What?

Follow-up to #61932 to remove serverAddr references from the JS code
too.

<!-- 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 NEXT-2477
2024-02-13 17:36:41 +01:00
Leah e4b3531377 fix(turbopack): don't parse .ts files as .tsx (#61219)
### What?

We currently parse JSX syntax in all typescript files which is wrong.

Closes PACK-2302

Turbo PR: https://github.com/vercel/turbo/pull/7121

### Turbopack Updates

* https://github.com/vercel/turbo/pull/7099 <!-- Donny/강동윤 -
fix(turbopack): Fix panic from `EcmascriptModuleFacadeModule::content`
-->
* https://github.com/vercel/turbo/pull/7121 <!-- Leah - fix(turbopack):
don't parse `.ts` files as `.tsx` -->
2024-01-29 21:13:32 +00:00
Leah 10ca4346f2 fix(turbopack): use correct layout for 404 page (#61032)
### What?

This fixes 2 issues with app 404 pages.
1. The root layout in a group was previously ignored when hitting the
404 page.
2. The default app 404 page was missing the correct path for dev
`/not-found` so it would fall back to the pages 404 page.

Closes PACK-2241
Fixes #60688
2024-01-24 20:07:06 +01:00
Will Binns-Smith 7b9e711ed5 Report HMR latency as trace spans for Turbopack (#60799)
This:
- Makes makes reporting hmr changes more accurate by emitting an
explicit start event and lowering the aggregation period for reporting
completed turbo tasks
- Parameterizes the aggregation period, allowing JS subscribers to
request different intervals, such as for the next-rs-api test
- Aligns path pattern with webpack by normalizing its layer names
- Fixes a bug in `drainAndGetNext` where the stream never could drain
past the first item
- Sends `client-hmr-latency` spans from Turbopack in both page and app
router pages


Closes PACK-2252

---------

Co-authored-by: Tobias Koppers <tobias.koppers@googlemail.com>
2024-01-19 15:34:17 -08:00
Will Binns-Smith 154268a144 Turbopack: Use styled issue titles and details (#58743)
This uses styled issue titles and details introduced in
vercel/turbo#6535, which also moves "Module not found" messaging to the
title field for those issues.


Closes PACK-2013

---------

Co-authored-by: Tobias Koppers <tobias.koppers@googlemail.com>
Co-authored-by: Leah <github.leah@hrmny.sh>
Co-authored-by: Zack Tanner <zacktanner@gmail.com>
2023-11-22 13:39:24 +01:00
Tobias Koppers f7a7a8efa3 use postcss transforms consistently also on server side (#57434)
### What?

Server side should also apply postcss transforms in node_modules

### Why?

### How?


Closes WEB-1863
2023-10-26 03:09:37 +02:00
Tobias Koppers 43150fc677 Turbopack: Improve error handling (#57386)
### What?

* avoid some crash with server actions parsing
* don't send serverComponentChanges when there are errors

### Why?

### How?



Closes WEB-1852
2023-10-26 01:59:38 +02:00
Tobias Koppers f42b69209d disable test temporarily (#57368)
It's flaky

Closes WEB-1849
2023-10-24 15:39:29 -07:00