Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] canary from vercel:canary #546

Open
wants to merge 8,346 commits into
base: canary
Choose a base branch
from
Open

[pull] canary from vercel:canary #546

wants to merge 8,346 commits into from

Conversation

pull[bot]
Copy link

@pull pull bot commented Jun 6, 2023

See Commits and Changes for more details.


Created by pull[bot]

Can you help keep this open source service alive? 💖 Please sponsor : )

Marukome0743 and others added 28 commits August 6, 2024 18:14
## For Contributors

### Improving Documentation

- [x] Run `pnpm prettier-fix` to fix formatting issues before opening
the PR.
- [x] Read the Docs Contribution Guide to ensure your contribution
follows the docs guidelines:
https://nextjs.org/docs/community/contribution-guide

### What?
Add switchers of `next.config.js` and `next.config.ts`.
In addition, insert some commas.
### Why?
Config file type isn't same in the [PPR
docs](https://rc.nextjs.org/docs/app/building-your-application/rendering/partial-prerendering).
### How?
N/A

x-ref: #68210

---------

Co-authored-by: Delba de Oliveira <32464864+delbaoliveira@users.noreply.github.com>
…n.toml (#68592)

Discussion:
https://vercel.slack.com/archives/C03EWR7LGEN/p1722904371113719

Between @wbinnssmith and myself, we determined that if you don't specify
this component here:
- `rustup` won't install rust-analyzer by default (it isn't part of the
"minimal" profile)
- `rustacean.nvim` won't install it by default, and will instead just
ask you to install it if you run a health check:
https://github.com/mrcjkb/rustaceanvim/blob/193f1d7925a61a066f7aa7d5d75f0cfe17dc0a9e/lua/rustaceanvim/health.lua#L210
- The VSCode plugin will look for a rustup-installed version, but since
it doesn't exist, it will silently fall back to using its own bundled
version, which doesn't match our toolchain version:
https://github.com/rust-lang/rust-analyzer/blob/b23142209ef632475915e858f5f20901ef7c12da/editors/code/src/bootstrap.ts#L58-L60

Enabling this component ensures that everyone's IDE (VSCode or Neovim
with Rustacean.nvim) uses a version of rust-analyzer that matches the
rest of our toolchain. This also ensures reproducibility across the
whole team.

Copied the line from
https://github.com/vercel/nextpack/blob/main/rust-toolchain.toml

## Tradeoffs

This will install `rust-analyzer` in CI where it's not needed.

## Test Plan

```
rustup component remove rust-analyzer
rustup which rust-analyzer
```

Before this change, the `rustup which` command would fail. With this
change, it will auto-install `rust-analyzer`.
This ensures we are able to properly replace even when an env variable
value wasn't initially provided and also ensures an env that is
interpolated in a string properly replaces. We don't use the stringified
version of `process.env` as that can cause issues with interpolation and
such.
…8593)

### What?

We use turbo to build the native portion of nextjs / turbopack which relies on turborepo for caching, with manually specified inputs. When moving the project we missed adding the new crates folder to the `turbo.json` file, leading to erroneous cache hits.

### Why?

Erroneous cache hits = bad.

### How?

Add the new path to the turbo.json file for next-swc. I did not include the `turbopack/packages` folder, since it is not used in native builds.
This cleans up some of the logic around builds to have the generate
functions return arrays of objects instead of multiple keyed arrays.
This lets us more cleanly access the associated encoded and raw forms of
the pathnames as they're moving through build.

This also extracts some types away from function signatures to improve
readability.
## Why?

Let's update the nav title to CSS instead of Stylesheets.

- x-ref:
https://vercel.slack.com/archives/C07BS1WEYAZ/p1722293684814579?thread_ts=1722289964.258269&cid=C07BS1WEYAZ
- x-ref: #68304 (re-opened because
the previous PR had wild git conflicts)
While testing noticed we were incorrectly copying from the cache when in
`store-only` mode so this fixes that condition to ensure we skip that
case properly.
### What

Remove the async client modules collection from shared plugin state,
which was used for flight client manifest.


### Why

This was the legacy logic when React RSC renderer requires the `async`
property in the flight manifest, but then React dropped that change and
all the async modules are handled on the framework side, React won't do
any extra await for the modules which are marked as `async: true` in the
manifest.

The new async module logic is handled in [this
PR](#66990) now, most critically
in [this
line](https://github.com/vercel/next.js/pull/66990/files#diff-20be1066bb3785bdd9f255179957039e7ce035324bc7753aefe89ffc6bb6f1edR115).
Hence we removed that state for flight manifest.

cc @unstubbable
### What & Why?

We want to enforce that values that functions return contain only
`ResolvedVc` and not `Vc` (though the outermost `Vc` is okay). We can do
that using the `ResolvedValue` marker trait
(vercel/turborepo#8678).

This PR allows enforcing that by passing a `resolved` argument to the
`#[turbo_tasks::function(...)]` macro.

This enforcement behavior is currently opt-in, but the goal is
eventually to make it opt-out, so that most functions can easily be
converted to use local tasks.

Bigger picture:
https://www.notion.so/vercel/Resolved-Vcs-Vc-Lifetimes-Local-Vcs-and-Vc-Refcounts-49d666d3f9594017b5b312b87ddc5bff

### How?

The key part of the macro is this bit:

```
fn assert_returns_resolved_value<
    ReturnType,
    Rv,
>() where
    ReturnType: turbo_tasks::task::TaskOutput<Return = Vc<Rv>>,
    Rv: turbo_tasks::ResolvedValue + Send,
{}
assert_returns_resolved_value::<#return_type, _>()
```

That creates no-op code that successfully compiles when the return value
(inside of the outermost `Vc`) is a `ResolvedValue`, but fails when it
isn't. This is the same trick that the [`static_assertions`
library](https://docs.rs/static_assertions/latest/static_assertions/macro.assert_type_eq_all.html)
uses.

### Test Plan

Lots of [trybuild](https://github.com/dtolnay/trybuild) tests!

```
cargo nextest r -p turbo-tasks-macros-tests
```

**Hint:** Use `TRYBUILD=overwrite` when intentionally changing the
tests.
### What?

Update `swc_relay`

### Why?

To fix a bug in operation name parsing. See swc-project/plugins#333



### How?

Fixes #67614
### What?

Update `lightningcss` crate of next.js


### Why?

To apply parcel-bundler/lightningcss#784 and parcel-bundler/lightningcss#783

### How?

- Closes PACK-2933
- Closes PACK-3100
- Closes #66191
- Closes #64299
…#68522)

### Why?

This issue occurs when a project is NPM Workspace, and has no other
package managers but NPM is installed.

Next.js runs [npm config get
registry](https://github.com/vercel/next.js/blob/e35710f71f8e0f2844add1a97513a65a54a6f2a3/packages/next/src/lib/helpers/get-registry.ts#L13)
to fetch the registry.
However, running `npm config get registry` at a NPM Workspace is not
allowed resulting a `ENOWORKSPACES` error.

```
$ npm config get registry  
npm error code ENOWORKSPACES
npm error This command does not support workspaces.
```

As we didn't consume the error, it threw when the enabled `next
telemetry` [triggered
getVersionInfo](https://github.com/vercel/next.js/blame/fb2d2dd01a5f73ac62c4809b7b9c1490617f8705/packages/next/src/server/dev/hot-reloader-webpack.ts#L725-L728)
calling `getRegistry` which threw as above.

### How?

Add `--no-workspaces` flag when the pkgManager is `'npm'`.
It is safe for non-workspace projects as it's equivalent to default
`--workspaces=false`.

Fixes #47121
Fixes NEXT-832
Fixes NDX-150

---------

Co-authored-by: Sebastian Silbermann <silbermann.sebastian@gmail.com>
…fix` is provided (#68518)

### Why?

URL validation of `normalizeAssetPrefix` was wrong as it checks if is
starting with `://`:


https://github.com/vercel/next.js/blob/37df9ab243690187725a236cbf2debbcaeb33cfa/packages/next/src/shared/lib/normalized-asset-prefix.ts#L4-L7

This resulted the value to be `/https://example.com` instead of
`example.com`.

x-ref:
#68518 (comment)

### How?

As `normalizeAssetPrefix` function was added for `getSocketUrl`, it
removes the protocol of the URL.
But for reusability, this could be a friction to other callers.
Therefore we validate the URL and let the callers handle the URL (e.g.
protocol).
…68608)

### What?

Enable tree shaking for modules with `"use server"`.

### Why?

Using server action should not de-optimize the module.

### How?

Closes PACK-3174
Image Tag should be available in sitemap.xml, which is not currently
support in sitemap.

In this pr, I solved issue #68033  which I faced in my project.

cc  @leerob @delbaoliveira  @samcx 

x-ref:
https://developers.google.com/search/docs/crawling-indexing/sitemaps/image-sitemaps

---------

Co-authored-by: Jiachi Liu <inbox@huozhi.im>
Co-authored-by: Delba de Oliveira <32464864+delbaoliveira@users.noreply.github.com>
### What?

move tests into common folder

allow to change backend on turbo tasks tests

### Why?

Preparation for a new backend for persistent caching
#68624)

### What/Why

Running `pnpm clean` always removes the
`packages/next-swc/native/.gitignore` file in `next-swc`, which is
annoying because that's meant to stay checked in. This PR moves the
`.gitignore` file out from the `native` directory to avoid this.

How to reproduce this problem:

```console
$ pnpm clean
<snip>

$ git status
<snip>
Changes not staged for commit:
  (use "git add/rm <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
	deleted:    packages/next-swc/native/.gitignore
```
This is because the `clean` script just removes the entire `native`
directory:

https://github.com/vercel/next.js/blob/a5e2a02f5a988d50a35fc2932b069dff5200e2c6/packages/next-swc/package.json#L6

so moving the `.gitignore` file out from there avoids this.
Follow up to #68624. Fixes a crash during test installation if
`next-swc/native` doesn't exist (because it might have been deleted by
`pnpm clean`)
…URRENT_TASK_STATE (#68607)

## Why?

- These three task locals were pretty much always entered/exited at the same time.
- Syntactically, this lead to some awkwardness, as each scope introduces another level of indentation.
- Each task local adds more entries to the stack traces.
- While entering/exiting each task local's scope is very cheap, it's not free, and it must happen on every task's await points. One task local instead of three reduces the work that needs to happen.

## Benchmarking

Any change in performance is too small to benchmark.

```
cargo bench -p turbopack-bench -p turbopack-cli -- "hmr_to_eval/Turbopack CSR"
```

Manually increased the number of samples and execution time:

```
diff --git a/turbopack/crates/turbopack-bench/src/lib.rs b/turbopack/crates/turbopack-bench/src/lib.rs
index 4e3df12db0..e2f16fb0d6 100644
--- a/turbopack/crates/turbopack-bench/src/lib.rs
+++ b/turbopack/crates/turbopack-bench/src/lib.rs
@@ -127,8 +127,8 @@ enum CodeLocation {

 pub fn bench_hmr_to_eval(c: &mut Criterion, bundlers: &[Box<dyn Bundler>]) {
     let mut g = c.benchmark_group("bench_hmr_to_eval");
-    g.sample_size(10);
-    g.measurement_time(Duration::from_secs(60));
+    g.sample_size(50);
+    g.measurement_time(Duration::from_secs(300));

     bench_hmr_internal(g, CodeLocation::Evaluation, bundlers);
 }
```

Using a machine configured for low-noise: https://github.com/bgw/benchmark-scripts

**Before:**
```
bench_hmr_to_eval/Turbopack CSR/1000 modules
                        time:   [14.713 ms 14.779 ms 14.862 ms]
Found 1 outliers among 50 measurements (2.00%)
  1 (2.00%) high mild
```

**After:**
```
bench_hmr_to_eval/Turbopack CSR/1000 modules
                        time:   [14.732 ms 14.800 ms 14.886 ms]
                        change: [-1.1606% +0.1132% +1.5420%] (p = 0.86 > 0.05)
                        No change in performance detected.
Found 1 outliers among 50 measurements (2.00%)
  1 (2.00%) high mild
```
### What

Support merging the static metadata file conventions `favicon.ico` with
other customized metadata icon from the module export.


### Why

`favicon.ico` should be displayed everywhere as it's the icon
representative of the website for all pages. Any customized `icon` in
metadata export `export const metadata` or `export function
generateMetadata()` shouldn't override the `favicon.ico` file
convention.


Fixes #55767

---------

Co-authored-by: hrmny <8845940+ForsakenHarmony@users.noreply.github.com>
I've simplified @timneutkens's tests from #66486
The resolver fix is in vercel/turborepo#8820

Closes #66486
Related issue: #66487

---------

Co-authored-by: Tim Neutkens <tim@timneutkens.nl>
### What?

Ports a few more useful scripts from nextpack, namely:

- `patch-next`
- `sweep`
- `build-native` (to clean up incremental artifacts on compiler panics)
- the macOS compression agent
This auto-generated PR updates the production integration test manifest
used when testing Turbopack.
This auto-generated PR updates the development integration test manifest
used when testing Turbopack.
…68546)

### What
During SSG, the fetch cache isn't shared between renders of different
pages within a single export worker. This means that if **Page A**
fetches `/foo` and **Page B** also fetches `/foo`, they will not be
deduped and instead will be fetched from origin within each worker.
Additionally, we currently only prerender 1 path per worker, which
doesn't allow us to take advantage of concurrency or smarter groupings.

### Why
Currently the export worker is set up to handle indivdual pages. We fire
off an exportPage request to all of the known paths and jest-worker
handles concurrency & parallelization.

### How
This refactors the export worker to accept an array of paths. For this
iteration, it doesn't attempt to do any smart grouping of paths (ie ones
that share a layout, etc), it just tries to create reasonably sized
groups. It will chunk a minimum of 25 pages per worker, and each worker
will process `experimental.staticGenerationMaxConcurrency` (defaults to
2, tbd on final numbers here) exports at a time.

This lets us set up the `IncrementalCache` inside of the worker before
we process pages. As we process pages, the incremental cache will be
populated with entries, and subsequent requests will leverage the cache
rules therein.

This also disables the auto no-cache behavior that we introduced with
Next 15 during SSG. Unless a fetch is explicitly opting out of caching,
we'll attempt to cache it during SSG so another worker can re-use it.

Closes NDX-78
Closes NDX-19
Sam-Phillemon9493 and others added 30 commits August 22, 2024 22:23
…er (#68941)

This PR updates the custom-routes-proxying example to use the App
Router. Here are the changes that have been made:

- Renamed the "pages" folder to the "app" folder.
- Updated the routing for /, /about & /hello/[slug] files to align with
the App Router.
- Added the layout.tsx file as part of the App Router.
- Updated the package.json file.
- Updated the Readme file.

CC: @samcx

---------

Co-authored-by: Lee Robinson <me@leerob.io>
Co-authored-by: samcx <sam@vercel.com>
This PR added importing `type NextConfig` in examples of next-config-ts.
Closes NDX-227
### What?

Implement a lint for imports from node.js internal modules.

### Why?

It will not work on runtime because edge runtime does not have such
modules.

x-ref:
https://vercel.slack.com/archives/C04KC8A53T7/p1724310187996899?thread_ts=1723669243.397119&cid=C04KC8A53T7

### How?


Closes PACK-3216
This auto-generated PR updates the production integration test manifest
used when testing Turbopack.
## Why?

We don't have any documentation about the experimental `next.config.ts`
config `useLightningcss`.

- Fixes: #69030

Co-authored-by: Delba de Oliveira <32464864+delbaoliveira@users.noreply.github.com>
…tion (#68946)

### What?

Add documentation about Partytown configuration on the `Script`
documentation page.

### Why?

The
[`Script`](https://nextjs.org/docs/pages/building-your-application/optimizing/scripts)
component with the `strategy` prop set to `worker` uses
[Partytown](https://partytown.builder.io/) under the hood.

Users may need to customize [Partytown
options](https://partytown.builder.io/configuration) such as `forward`,
`loadScriptsOnMainThread`, and `resolveUrl`, to allow for third party
scripts such as Segment and Google Tag Manager to work properly.

This used to be documented on `docs/basic-features/script.md`, as you
can see on the [pull request that originally introduced the `worker`
strategy](https://github.com/vercel/next.js/pull/34244/files#diff-62dbdb4bc703f7997ea259ad68d8e823d9fafed1e9571155e01c4de21abb6b47R165-R197),
but this doc page was removed (potentially unintendedly) on
#50701, and there's no longer
mention of Partytown configuration in Next.js docs.

### How?

Adding back the documentation text originally written by
@housseindjirdeh in his pull request
#34244

Fixes #68943

---------

Co-authored-by: samcx <sam@vercel.com>
Co-authored-by: Lee Robinson <me@leerob.io>
The PR moves `module.exports = nextConfig` into the code block. This was
introduced in #69161

/cc @samcx
### What?

Refactored module ID strategies implementation to walk modules graph individually for each endpoint.

Based on feedback from [next.js#68408](#68408) and [turbo#8912](vercel/turborepo#8912).

Comments marked with `NOTE(LichuAcu)` are intended to make reviewing easier and will be removed before merging.
### What?
Improves the traversal of the module graph by doing a more exhaustive search of the children modules, thus increasing the "hit rate" for optimized module IDs (which should be 100%).

### Why?
Some structs that implement the `Module` trait return an empty list in the `references` method, but still "own" some child modules. This is the case of `EcmascriptClientReferenceModule`, for example, which returns empty in `references` but owns a `client_module` and an `ssr_module`. These modules are ignored when traversing the module graph with the `get_referenced_modules` function we used before, so neither they nor their children are ever assigned an optimized ID.

### How?
To solve this, a `children_modules` method is added to the `Module` trait, which should exhaustively return all direct children of the module. The function defaults to `primary_referenced_modules`, which simply calls `references`, but structs like `EcmascriptClientReferenceModule` can reimplement it and return "hidden" children modules like the aforementioned `client_module` and `ssr_module`.
This logs a span representing the entire lifetime of the devserver.
…timization (#68993)

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

-->
…void circularities (#69075)

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

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

-->
Reapply #68842 after it was reverted in
#69156

Now it should really only do it if it's really not an ESM module (= CJS)

The replacement now has the same condition as used when Turbopack
determines whether a given module should get access to `module`:


https://github.com/vercel/next.js/blob/161cd00c7bc91e9dc29842427af0cc6f810267bb/turbopack/crates/turbopack-ecmascript/src/chunk/item.rs#L51


https://github.com/vercel/next.js/blob/161cd00c7bc91e9dc29842427af0cc6f810267bb/turbopack/crates/turbopack-ecmascript/src/lib.rs#L880-L881
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet