Commit graph

2799 commits

Author SHA1 Message Date
vercel-release-bot
4df90ac6ff v14.3.0-canary.83 2024-05-26 10:42:09 +00:00
Tim Neutkens
216ce33b5b
Implement typeof window inlining for Turbopack (#66128)
## What?

Update: Implemented a feature in Turbopack for `typeof window` inlining:
https://github.com/vercel/turbo/pull/8211. Verified the changes in that
PR + this PR fix the test 💯


Turbopack upgrade:

* https://github.com/vercel/turbo/pull/8081 <!-- Alexander Lyon - add
support for upload speed / remaining in the cache upload step -->
* https://github.com/vercel/turbo/pull/7673 <!-- Alexander Lyon -
[turbo-trace] add additional filter modes for allocs over time -->
* https://github.com/vercel/turbo/pull/8191 <!-- Will Binns-Smith -
Turbopack: Register react refresh exports in module factory -->
* https://github.com/vercel/turbo/pull/8195 <!-- Donny/강동윤 - feat:
Remove lint for `grid-template-areas`" -->
* https://github.com/vercel/turbo/pull/8207 <!-- Benjamin Woodruff -
chore: Remove unused `base16` dependency and dead `hex` wrapper function
-->
* https://github.com/vercel/turbo/pull/8185 <!-- Tim Neutkens - Update
contributing guide to mention snapshot test updating -->
* https://github.com/vercel/turbo/pull/8211 <!-- Tim Neutkens - Add
option for inlining typeof window -->
* https://github.com/vercel/turbo/pull/8214 <!-- Will Binns-Smith -
Revert "Turbopack: Register react refresh exports in module factory
(#8191)" -->

---

Previous PR description::

Implements a failing test for issue #66058.
The test only fails when using Turbopack.

While digging into that issue I found that `typeof window` replacement
is either not applied or does not cause `import()` or `require()` to be
removed. In the reproduction that approach is used to load a particular
package only in Node.js and another only in the browser.

<!-- 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-05-26 12:25:40 +02:00
vercel-release-bot
20201a11a2 v14.3.0-canary.82 2024-05-25 23:21:46 +00:00
vercel-release-bot
0f1d9e9f7b v14.3.0-canary.81 2024-05-24 23:21:57 +00:00
Tim Neutkens
08b75b77b0
Handle next/navigation import in middleware (#66175)
## What?

Ensures that `next/navigation` and React is aliased in middleware in the
same way that it's aliased in Route Handlers. This matches the behavior
we have in Next.js with webpack.

Fixes #66162

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

-->

---------

Co-authored-by: Hendrik Liebau <mail@hendrik-liebau.de>
2024-05-24 15:39:08 +00:00
Alexander Lyon
82a7c9c2c0
add bash script to run a benchmark (#64717) 2024-05-24 16:00:23 +01:00
Alexander Lyon
f993ea3d04
add next-build-test binary / library (#64121)
This adds a new target in the next-swc package designed as an entrypoint
for collecting memory benches. Later PRs in the stack add a script to
run the benches and finally a manual-triggered CI step
2024-05-24 15:14:39 +02:00
vercel-release-bot
dfe7fc03e2 v14.3.0-canary.80 2024-05-23 23:23:20 +00:00
Benjamin Woodruff
5017a41c75
feat(turbopack): Attempt to detect and warn about slow file IO (#66057)
We'd like to warn users if they have particularly slow file IO, so that they can correct the problem themselves, and don't send us reports of poor performance.

- Feature request: https://vercel.slack.com/archives/C03KAR5DCKC/p1716051650641529
- Tweet about how Bun does this: https://x.com/jarredsumner/status/1637549427677364224
- Bun implementation: 06a9aa80c3/src/install/install.zig (L3038)

**Why 100ms?** Bun used to use 10ms, found it too noisy, and switched to 100ms.

This benchmark should run non-blocking in the background and should not meaningfully slow down server startup (even on slow disks).

## Simulated Testing

I looked around and found https://github.com/schoentoon/slowpokefs/. It hasn't been updated in 10 years, but still seems to build fine.

In a nextjs project directory, turn `.next` into an artifically slow mount point:

```
fusermount -uz .next; rm -rf .next .next.real && mkdir .next .next.real && ~/slowpokefs/slowpokefs -m 50 -M 50 --no-slow-read -F .next.real .next
```

<img width="695" alt="Screenshot 2024-05-21 at 4 14 58 PM" src="https://github.com/vercel/next.js/assets/180404/217d7692-33cf-42b7-bbf7-5a530b9e0df1">

Run `pnpm dev --turbo` and see that the warning is generated.

## "Real World" Testing

The following tests are from a linux VM using virtiofs to connect to a 5400 RPM USB 2.0 HDD with APFS:

Only the .next is on an HDD (bind mount):
Otherwise idle disk: `4.86ms 4.44ms 5.31ms`
Otherwise busy disk (copying files): `69.34ms 53.75ms 25.12ms`

The whole project directory is on the HDD (more realistic):
Otherwise idle disk: `20.29ms 35.61ms 48.12ms`
Otherwise busy disk (copying files): `131.40ms 21.71ms 87.33ms`

Most of the time the threshold was not reached, but the 131.40ms test did trigger the warning!

Fixes PACK-3087
2024-05-23 09:52:33 -07:00
vercel-release-bot
7fe4f41e13 v14.3.0-canary.79 2024-05-23 14:45:18 +00:00
vercel-release-bot
24180bda25 v14.3.0-canary.78 2024-05-23 02:39:11 +00:00
vercel-release-bot
74be1f68c2 v14.3.0-canary.77 2024-05-22 23:23:25 +00:00
Benjamin Woodruff
ad8d1c27ff
[turbopack] Use updated RawOutput API (#65300)
Use updated API suggested by sokra in review on #65223:

https://github.com/vercel/next.js/pull/65223#discussion_r1587157258

Depends on https://github.com/vercel/turbo/pull/8075
2024-05-22 11:10:58 -07:00
Benjamin Woodruff
4ead5fc00d
next-swc-napi: Enable "plugin" feature by default (#66006)
As noted in (https://github.com/vercel/nextpack/pull/103), by not having
this as a default feature, when running the `build-native` script it's
not able to re-use any cargo caches that might already exist from a
default build.

Because this feature impacts the swc crate, everything dependent on it
can be forced to rebuild.

By making this a default feature, the hope/theory is that the number of
different ways we potentially build our dependency graph reduces, and
cargo cache hits will improve.

## Changes

- Add `plugin` to the default set of features for `next-swc-napi`.
- Consolidate `build-native-no-plugin-woa` with
`build-native-no-plugin`. Given the lack of any other default features,
these are equivalent.
- `i686-pc-windows-msvc`: Switch to `build-native-no-plugin-release` in
CI instead of just supplying the `--release` flag. This has the benefit
of also enabling `tracing/release_max_level_info`, which might reduce
the size of or speed up these builds.
- `x86_64-apple-darwin`: Remove a redundant `--release` flag in the CI
config (no expected changes).

## Testing

I've tested this locally on Linux (`pnpm run build-native`) and
Windows-on-ARM (`pnpm run build-native-no-plugin`) by making sure things
still build. I'll also make sure CI passes.
2024-05-22 11:09:04 -07:00
vercel-release-bot
d299bbf431 v14.3.0-canary.76 2024-05-21 23:23:05 +00:00
Will Binns-Smith
35d300e5cc
Add dedicated client entry for Turbopack builds (#65824)
Previously with Turbopack, we would attempt to establish a websocket
connection to the HMR server, even when running production builds. This
adds `next-turbopack.ts`, which includes the necessary runtime code for
Turbopack, but does not include HMR code.

Test Plan: `TURBOPACK=1 TURBOPACK_BUILD=1 pnpm next build
test/e2e/app-dir/app-middleware`

---------

Co-authored-by: Tim Neutkens <tim@timneutkens.nl>
2024-05-21 22:43:41 +00:00
vercel-release-bot
22f822ebb7 v14.3.0-canary.75 2024-05-21 21:18:04 +00:00
vercel-release-bot
5cba51e342 v14.3.0-canary.74 2024-05-21 19:54:31 +00:00
vercel-release-bot
49c1e127aa v14.3.0-canary.73 2024-05-20 23:23:18 +00:00
Will Binns-Smith
4ff11d0631
Turbopack: Implement next/font/local with BeforeResolvePlugin and show custom error message (#65870)
Depends on vercel/turbo#8165

This:
- Creates and uses a `BeforeResolvePlugin` to handle requests to
`next/font/local/target.css` instead of `ImportMapping` replacers
- Returns a `ResolveResultItem::Error` which includes a custom
`StyledString` describing the missing font file

Test Plan: `TURBOPACK=1 pnpm test-dev
test/e2e/app-dir/next-font/next-font.test.ts`
2024-05-20 15:46:19 -07:00
vercel-release-bot
14a98734e3 v14.3.0-canary.72 2024-05-20 10:35:37 +00:00
Janka Uryga
79bebe7bd3
experimental: unstable_after (#65038)
Implements `unstable_after`, which lets the user schedule work to be
executed after the response is finished.

### Implementation notes

- `unstable_after()` is a dynamic function (bypassable only with `export
dynamic = "force-static"`)
- Usable in: server components (including `generateMetadata`), actions,
route handlers, middleware
- It is meant to run its callbacks even if a response didn't complete
successfully (thrown error) or called `notFound()`/`redirect()`
- Currently gated behind a `experimental.after` feature flag, because it
touches many runtime bits (including a React monkeypatch...)
- The state for `unstable_after()` in a given request lives in
`requestAsyncStorage` (added via `RequestAsyncStorageWrapper`)

- the implementation is based around two functions that we inject via
`renderOpts`:
- `waitUntil(promise)` - keep a function invocation alive until a
promise settles. it is provided as a platform primitive in serverless
contexts, and a noop in `next start`
- for serverless (nodejs), Next.js will attempt to get `waitUntil` from
`globalThis[Symbol.for('@next/request-context')].get().waitUntil`. This
should be considered unstable for now. See
`packages/next/src/server/after/wait-until-builtin.ts` for details.
- `onClose(callback)` **[NEW]** - run something when a response is done.
basically `res.on('close', callback)`, but also implemented for Web APIs
- unfortunately, for Web, this requires some potentially expensive
tricks - see `packages/next/src/server/web/web-on-close.ts`
2024-05-20 08:49:53 +00:00
vercel-release-bot
3843166730 v14.3.0-canary.71 2024-05-18 23:21:55 +00:00
vercel-release-bot
9c31149967 v14.3.0-canary.70 2024-05-17 23:23:12 +00:00
vercel-release-bot
48b91dcc0b v14.3.0-canary.69 2024-05-17 21:19:07 +00:00
Donny/강동윤
138e45cf56
Update turbopack & swc_core (#65450)
### What?

* https://github.com/vercel/turbo/pull/8101 <!-- Tobias Koppers - fix
off-by-one bug while reading heaptrack files -->
* https://github.com/vercel/turbo/pull/8130 <!-- Tobias Koppers -
refactor memory tracking -->
* https://github.com/vercel/turbo/pull/8097 <!-- Donny/강동윤 - build:
Update `swc_core` to `v0.92.5` -->

Update swc_core.


### Why?

To keep in sync and fix styled-jsx issues

### How?

Closes PACK-3042

---------

Co-authored-by: hrmny <8845940+ForsakenHarmony@users.noreply.github.com>
2024-05-17 20:15:51 +02:00
vercel-release-bot
cd5287e932 v14.3.0-canary.68 2024-05-16 23:22:25 +00:00
vercel-release-bot
f6a242474c v14.3.0-canary.67 2024-05-16 21:16:20 +00:00
vercel-release-bot
531f7c2dda v14.3.0-canary.66 2024-05-16 20:04:48 +00:00
vercel-release-bot
84014c2971 v14.3.0-canary.65 2024-05-16 18:15:02 +00:00
vercel-release-bot
5469e6427b v14.3.0-canary.64 2024-05-16 09:25:50 +00:00
OJ Kwon
5863261cf0
feat(next): experimental react compiler support (#65804)
### What

This PR exposes new experimental configuration for next.js,
`experimental.reactCompiler`. Under the hood, this option configures to
use new experimental react compiler
(https://react.dev/learn/react-compiler#). `reactCompiler` value can be
either boolean or an object contains partial set of compiler itself's
configuration option.

For the webpack and turbopack both it is enabled by adding a babel
plugin for the react compiler. If user have an existing .babelrc, plugin
will be appended to the config. Otherwise, swc will still kicks in (for
webpack) or turbopack for the general transform but only compiler babel
plugin will run via babel.

---------

Co-authored-by: Tim Neutkens <tim@timneutkens.nl>
2024-05-16 11:22:28 +02:00
hrmny
25b767eb84
feat(turbopack-ecmascript): use import attributes for annotations (#59370) 2024-05-16 02:58:43 +00:00
Will Binns-Smith
81d5daddf3
Turbopack: Remove EcmascriptChunkingContext (#65716)
Depends on vercel/turbo#8133. See that PR for rationale.
2024-05-15 15:51:08 +00:00
Luca Forstner
0840d521d5
Add clientTraceMetadata experimental option to propagate tracing data to the client (#64256)
### What?

This PR adds an experimental option `clientTraceMetadata` that will use
the existing OpenTelemetry functionality to propagate conventional
OpenTelemetry trace information to the client.

The propagation metadata is propagated to the client via meta tags,
having a `name` and a `content` attribute containing the value of the
tracing value:

```html
<html>
    <head>
        <meta name="baggage" content="key1=val1,key2=val2">
        <meta name="traceparent" content="00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01">
        <meta name="custom" content="foobar">
    </head>
</html>
```

The implementation adheres to OpenTelemetry as much as possible,
treating the meta tags as if they were tracing headers on outgoing
requests. The `clientTraceMetadata` will contain the keys of the
metadata that're going to injected for tracing purpose.

### Why?

Telemetry providers usually want to provide visibility across the entire
stack, meaning it is useful for users to be able to associate, for
example, web vitals on the client, with a span tree on the server. In
order to be able to correlate tracing events from the front- and
backend, it is necessary to share something like a trace ID or similar,
that the telemetry providers can pick up and stitch back together to
create a trace.

### How?

The tracer was extended with a method `getTracePropagationData()` that
returns the propagation data on the currently active OpenTelemetry
context.
We are using `makeGetServerInsertedHTML()` to inject the meta tags into
the HTML head for dynamic requests.
The meta tags are generated through using the newly added
`getTracePropagationData()` method on the tracer.

It is important to mention that **the trace information should only be
propagated for the initial loading of the page, including hard
navigations**. Any subsequent operations should not propagate trace data
from the server to the client, as the client generally is the root of
the trace. The exception is initial pageloads, since while the request
starts on the client, no JS has had the opportunity to run yet, meaning
there is no trace propagation on the client before the server hasn't
responded.

Situations that we do not want tracing information to be propagated from
the server to the client:
- _Prefetch requests._ Prefetches generally start on the client and are
already instrumented.
- _Any sort of static precomputation, including PPR._ If we include
trace information in static pages, it means that all clients that will
land on the static page will be part of the "precomputation" trace. This
would lead to gigantic traces with a ton of unrelated data that is not
useful. The special case is dev mode where it is likely fine to
propagate trace information, even for static content, since it is
usually not actually static in dev mode.
- _Clientside (soft) navigations._ Navigations start on the client and
are usually already instrumented.

### Alternatives considered

An implementation that purely lives in user-land could have been
implemented with `useServerInsertedHTML()`, however, that implementation
would be cumbersome for users to set up, since the implementation of
tracing would have to happen in a) the instrumentation hook, b) in a
client-component that is used in a top-level layout.

### Related issues/discussions

- https://github.com/vercel/next.js/issues/47660
- https://github.com/vercel/next.js/discussions/62353 (Could be used as
an alternative to the server-timing header)
- https://github.com/getsentry/sentry-javascript/issues/9571

---------

Co-authored-by: Jiachi Liu <inbox@huozhi.im>
2024-05-15 12:19:27 +02:00
Dmitry Belyaev
1c81480168
feat: remove font family hashing in next/font css (#53608)
<!-- 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?

Adding support for supporting a custom fontFamily name when using
next/font

### Why?

By default, next/font hashes the font name when generating css to
achieve proper scoping.
However, that makes it impossible to use next/font with 3rd party
libraries that provide CSS with pre-defined font names.

### How?

To solve this, I've added a new argument to the next/font function call
– `usedFontFamilyName`.
It allows developers to pick the fontFamily name that is going to be
used in the CSS output instead of the default one and make it work with
vendor CSS files.

```
import { Inter } from "next/font/google";

const inter = Inter({
  subsets: ["latin"],
  fixedFontFamily: "Inter",
});
```

Fixes [#43452](https://github.com/vercel/next.js/discussions/43452)

---

Edit:

I've changed the implementation to use `disabledFontFamilyHashing`
boolean flag which removes the hashing but keeps the original font
family name instead of allowing a custom name

---------

Co-authored-by: JJ Kasper <jj@jjsweb.site>
Co-authored-by: Zack Tanner <1939140+ztanner@users.noreply.github.com>
2024-05-14 18:22:43 -07:00
vercel-release-bot
4229ff4e4d v14.3.0-canary.63 2024-05-14 23:21:46 +00:00
OJ Kwon
64f38c4b0b
fix(next): add alias to new react exports (#65761)
### What

There is a new react exports entrypoints in pkg.json, which we didn't
add alias as similar to other export conditions.
2024-05-14 21:44:10 +00:00
vercel-release-bot
caf261288e v14.3.0-canary.62 2024-05-14 18:13:36 +00:00
vercel-release-bot
8dea9963d7 v14.3.0-canary.61 2024-05-13 23:22:28 +00:00
Jiachi Liu
47769d14bc
Remove swc minify related code branches (#65690)
### What

Remove `swcMinify` related branches as the option is deprecated and it's
always enabled

* Remove the related branches for checking `config.swcMinify`
* Remove the related telemetry about `swcMinify`
2024-05-13 23:37:37 +02:00
vercel-release-bot
9561a2988b v14.3.0-canary.60 2024-05-13 20:22:10 +00:00
Tim Neutkens
ac6e41292b
Reapply "Implement Turbopack trace server bindings" (#65419) (#65527)
Applies #65419 with the latest version of Turbopack that uses a
different websocket library.

<!-- 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-3363
2024-05-13 18:59:59 +02:00
Donny/강동윤
1518895728
fix(next-swc): Fix SWC env target - include option (#65693)
### What?

Enable private properties pass correctly.

### Why?

To allow using private properties with brand checking

### How?

Closes PACK-3059

---------

Co-authored-by: Jiachi Liu <inbox@huozhi.im>
2024-05-13 16:31:36 +00:00
Donny/강동윤
fedb675520
fix(next-swc): Do not reuse compiler instance (#65602)
### What?

Do not reuse `Compiler` instance.

### Why?

It exists only to support preserving comments from `print()` API for
modules created with `parse()` API, but it causes a problem for
`transform()` for very huge apps.

### How?

 - Closes https://github.com/swc-project/swc/issues/8932
 - Fixes #48960
 - Fixes #65436
2024-05-13 00:54:01 +00:00
vercel-release-bot
9296434815 v14.3.0-canary.59 2024-05-12 23:22:32 +00:00
Jiachi Liu
6635cc07a4
Apply react-server conditions to middleware (#65424)
### What

Reland #57448 , add react-server condition resolving and apply
server-only rules to middleware

Closes NEXT-1653
Closes NEXT-3333

### Why

Middleware as the pre-routing layer that is indended to be light-weight.
Since it's on edge runtime and only run on server but not on client, it
doesn't need to include the client react bundles. Hence we apply
`react-server` export condition, that if users import React we can only
bundle server required APIs and if users use React client hooks we can
error.
2024-05-12 14:26:37 +02:00
vercel-release-bot
c26840909c v14.3.0-canary.58 2024-05-11 23:21:54 +00:00
vercel-release-bot
b9af6a9b22 v14.3.0-canary.57 2024-05-10 23:22:03 +00:00
vercel-release-bot
406a11eefe v14.3.0-canary.56 2024-05-10 22:30:08 +00:00
vercel-release-bot
505fc7b259 v14.3.0-canary.55 2024-05-10 21:18:58 +00:00
hrmny
c98c6d6f8b
feat(turbopack): add support for bundlePagesRouterDependencies (#65520) 2024-05-10 20:51:55 +02:00
Jiachi Liu
f94e213de5
remove legacy deprecated warnings (#65579)
# What
Remove the previous deprecated flags and warnings

Removed deprecated types:

In `next.config.js`
- `experimental.incrementalCacheHandlerPath` (has moved to new options
in next 14)
- `experimental.isrMemoryCacheSize` (has moved to new options in next
14)
- `outputFileTracing` (not support customization anymore)
- `swcMinify` (not support customization anymore)

In `next/types`
- `unstable_includeFiles` (already deprecated for a while)
- `unstable_excludeFiles` (already deprecated for a while)
2024-05-10 20:13:06 +02:00
vercel-release-bot
cc10bf5d1f v14.3.0-canary.54 2024-05-09 23:22:54 +00:00
vercel-release-bot
c3c0c4f8a3 v14.3.0-canary.53 2024-05-09 17:22:50 +00:00
vercel-release-bot
718d94a21c v14.3.0-canary.52 2024-05-09 11:01:48 +00:00
Jiachi Liu
09baadfd70
Remove auto appending xml extension to dynamic sitemap routes (#65507)
### What

Remove the auto appending `.xml` extension to the sitemap routes when
it's a dynamic route.


### Why

Previously we were adding `.xml` to `/[...paths/]sitemap` routes, but
the bad part is when you use it to generate multiple sitemaps with
`generateSitemaps` in format like `/[...paths/]sitemap.xml/[id]`, which
doesn't look good in url format and it can be inferred as xml with
content-type. Hence we don't need to add `.xml` in the url.

Before this change it could also result into the different url between
dev and prod:
dev: `/sitemap.xml/[id]`
prod: `/sitemap/[id].xml` 

Now it's going to be aligned as `/sitemap/[id]`. Users can add extension
flexiblely.

Closes NEXT-3357
2024-05-09 11:05:24 +02:00
vercel-release-bot
067eac6383 v14.3.0-canary.51 2024-05-08 23:22:49 +00:00
vercel-release-bot
5ff2731c58 v14.3.0-canary.50 2024-05-08 19:53:50 +00:00
OJ Kwon
531348d864
feat(next): revise server component error message (#65468)
### What

Coming from internal feedback:
https://vercel.slack.com/archives/C046HAU4H7F/p1714858224393659
2024-05-08 12:39:37 -07:00
Tobias Koppers
a3ee23ba52
add page name to crashes (#65504)
### What?

helps in finding the page name on turbopack crashes
2024-05-08 17:31:45 +02:00
Tobias Koppers
4117442b1b
improve versioned content map (#65466)
### What?

Improves performance
2024-05-08 10:51:10 +02:00
vercel-release-bot
e61db9298d v14.3.0-canary.49 2024-05-08 08:43:30 +00: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
vercel-release-bot
715e157cba v14.3.0-canary.48 2024-05-08 06:38:45 +00:00
Tobias Koppers
84602cdf66
make sure children is first in loader tree to fix head css bug on client navigation (#65279)
### What?

make sure children is first in loader tree to fix head css bug on client
navigation

### Why?

### How?

Fixes PACK-3028

---------

Co-authored-by: Tim Neutkens <tim@timneutkens.nl>
2024-05-08 08:35:25 +02:00
vercel-release-bot
0edf4f951e v14.3.0-canary.47 2024-05-07 23:20:36 +00:00
vercel-release-bot
aa9d3f2d3e v14.3.0-canary.46 2024-05-07 21:29:02 +00:00
vercel-release-bot
b91019df41 v14.3.0-canary.45 2024-05-07 18:49:12 +00:00
Ethan Arrowood
d0d22ac625
Promote and rename server bundling options serverComponentsExternalPackages and bundlePagesExternals (#65421)
This PR promotes and renames experimental configuration options related
to server bundling:
- `serverComponentsExternalPackages` -> `serverExternalPackages`
- `bundlePagesExternals` -> `bundlePagesRouterDependencies`

Existing docs for `serverComponentsExternalPackages` was changed. 
New docs for `bundlePagesRouterDependencies` were added.

Closes NEXT-3332
2024-05-07 11:19:35 -06:00
Sebastian Silbermann
2c31c79ac8
Support React 19 in App and Pages router (#65058)
Closes NEXT-3218

---------

Co-authored-by: Jiachi Liu <inbox@huozhi.im>
2024-05-07 18:18:32 +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
vercel-release-bot
69baf6d8ae v14.3.0-canary.44 2024-05-06 23:21:59 +00:00
vercel-release-bot
180d4f5a6e v14.3.0-canary.43 2024-05-06 22:21:45 +00:00
OJ Kwon
8a1ac28d7b
fix(next-core): mark turbopack embed fs to be internals (#65420)
### What?

We were marking only next.js specific embed_fs as internals, in result
user transform runs against turbopack's runtime.
2024-05-06 14:38:05 -07:00
Wyatt Johnson
cdb415451a
[PPR] Enable incremental adoption (#63847)
Enabling Partial Prerendering (PPR) for an entire application is
ideally, the goal for teams wanting to test out the feature or adopt it
in their applications to get ready for when it becomes the default
rendering pattern. For large applications, with many routes the new
behaviours of old API's may prove a difficult pill to swallow all at
once.

This aims to enable incremental adoption of PPR for pages and routes
that want to support it in a similar way to how existing segment-level
configurations. Segments can now add:

```ts
export const experimental_ppr = true
```

To enable PPR for that segment and those descending segments. Any subset
of those routes that have it enabled can add:

```ts
export const experimental_ppr = false
```

<details>
<summary>An aside on the choice of <code>experimental_ppr</code>
name</summary>
<blockquote>
<p>It is against common JS semantics to use snake-case, and preference
is given to camel-case instead. The choice to make this snake-case was
to re-enforce that this is an experimental feature, an ugly incremental
path, and ideally, developers should aim to remove all references of it
from their codebase.</p>
<p>Additionally, this mirrors what we've done for unstable API's like
`unstable_cache`.</p>
</blockquote>
</details> 

To disable PPR for that segment and those descending segments. To use
this new option, the `experimental.ppr` configuration in
`next.config.js` must be set to `"incremental"`:

```js
// next.config.js
module.exports = {
  experimental: {
    ppr: "incremental",
  },
} 
```

If a segment does not export a `experimental_ppr` boolean, it is
inferred from it's parent. If no parent has it defined, it's default
value is `false` and therefore disabled.

Once all your segments have PPR enabled via this config, it would be
considered safe for teams to set their `experimental.ppr` value in the
`next.config.js` to `true`, enabling it for the entire app and for all
future routes.

### Aside

I also took the liberty to rename `isPPR` and `supportsPPR` to be the
clearer `isAppPPREnabled` and `isRoutePPREnabled`.

---------

Co-authored-by: Hendrik Liebau <mail@hendrik-liebau.de>
2024-05-06 14:55:00 -06:00
vercel-release-bot
e5b1d50101 v14.3.0-canary.42 2024-05-06 18:36:15 +00:00
JJ Kasper
aa51bedbbe
Revert "Implement Turbopack trace server bindings" (#65419)
This is failing to compile for some of our targets to reverting to
unblock CI

Reverts vercel/next.js#65410

Closes NEXT-3331
2024-05-06 11:25:38 -07:00
vercel-release-bot
b6d07bfa82 v14.3.0-canary.41 2024-05-06 15:26:55 +00:00
Tim Neutkens
b85210d64e
Implement Turbopack trace server bindings (#65410)
## What?

Implements support for running the Turbopack trace server, which is the
websocket server that powers https://turbo-trace-viewer.vercel.app/ when
using `NEXT_TURBOPACK_TRACING=1 NEXT_TURBOPACK_TRACE_SERVER=1`.

Currently you have to manually run the server through the Turbo
repository which in practice means that only people working on Turbopack
are able to run it.

With the bindings implemented anyone should be able to run the trace
server.

Note that the traces that come out of Turbopack are very low level,
they're meant for optimizing Turbopack like finding slowdowns / large
memory usage / optimizing performance.

However, it's useful for people that want to peek into why their
application is slow to compile. I.e. we've used
https://turbo-trace-viewer.vercel.app to investigate reports in #48748.

This PR adds support for `trace.log` by default, so if you add
`NEXT_TURBOPACK_TRACING=1 NEXT_TURBOPACK_TRACE_SERVER=1` it will
automatically select the `trace.log` for the current instance of
Next.js. You can only have one trace server running at the same time.

### `next internal` 

In order to support running the trace server standalone, which is useful
for investigating trace files other people have shared, I've added a new
subcommand `internal` that is not covered by semver / use at your own
risk. It's meant for internal tools that are useful to be bound to the
version of Next.js, the turbo-trace-server is a great example of that as
it has an internal binary format for storing data that needs to match
the trace.log file.

If you want to take a look at `.next/trace` instead the new `next
internal` subcommand can be used for that:

```sh
# Replace [path] with a path to a file.
next internal turbo-trace-server [path]
```

For example:

```sh
next internal turbo-trace-server ~/Downloads/trace
```

Currently the trace server does not support loading multiple files, just
hasn't been implemented yet. Once we can load two or more files we can
load both `.next/trace` and `trace.log` when
`NEXT_TURBOPACK_TRACE_SERVER=1` and support multiple paths passed to
`next internal turbo-trace-server`.


### Turbopack upgrade


PR includes a Turbopack upgrade:

* https://github.com/vercel/turbo/pull/8073 <!-- OJ Kwon -
feat(webpack-loaders): support dummy span interface -->
* https://github.com/vercel/turbo/pull/8083 <!-- OJ Kwon - fix(webpack):
print resource, project path when relative calc fails -->
* https://github.com/vercel/turbo/pull/8094 <!-- Tim Neutkens -
Implement bindings for Turbopack trace server -->


<!-- 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-3328
2024-05-06 15:23:40 +00:00
vercel-release-bot
1ae14bafdb v14.3.0-canary.40 2024-05-05 23:21:26 +00:00
vercel-release-bot
c9291d6dd5 v14.3.0-canary.39 2024-05-04 23:21:52 +00:00
vercel-release-bot
7ee16934e9 v14.3.0-canary.38 2024-05-03 23:22:07 +00:00
Benjamin Woodruff
8dc0eff89a
Delete dead concatenate_output_assets function (#65337)
I noticed this was dead while working on other changes to this file.

Checked that it built with:

```
cargo check
```
2024-05-03 14:20:08 -07:00
Benjamin Woodruff
e8acd2d9e5
Remove broken #[turbo_tasks::value(transparent)] attributes (#65336)
The `transparent` option only does something when the struct is a field-less unit struct with a single item.

Right now, an invalid `transparent` option is silently ignored. I'm working on a PR to change this to a compilation error, so that it's obvious that the option won't work. These are the callsites in `next.js` that my tweak brought up as potential issues.

Functionally, this PR should be a no-op.
2024-05-03 14:17:44 -07:00
Benjamin Woodruff
eba364a985
Emit polyfill-nomodule.js into the build manifest polyfillFiles (#65223)
### Why?

`polyfill-nomodule.js` is a pre-built file containing polyfills for
older browsers (gated by the `<script>` tag `nomodule` attribute).

### How?

- The turbopack server needs to emit a raw OutputAsset for this file, so
that it is copied into the output chunks directory.
- That file needs to be passed into `polyfillFiles`, and preserved when
we're merging manifests inside of the development server.

### Test Plan

```
HEADLESS=true pnpm testonly-dev test/e2e/app-dir/app/index.test.ts -t 'should serve polyfills for browsers that do not support modules'
HEADLESS=true pnpm testonly-dev-turbo test/e2e/app-dir/app/index.test.ts -t 'should serve polyfills for browsers that do not support modules'
```

Build a project with `next dev --turbo` and inspect:

![Screenshot 2024-05-01 at
10.40.39 PM.png](https://graphite-user-uploaded-assets-prod.s3.amazonaws.com/HAZVitxRNnZz8QMiPn4a/fe0214b2-ca56-4c03-a133-921f1dc51775.png)
![Screenshot 2024-05-01 at
10.40.20 PM.png](https://graphite-user-uploaded-assets-prod.s3.amazonaws.com/HAZVitxRNnZz8QMiPn4a/d41dbf91-34d2-44c4-90ec-30e3212ce0f8.png)

Verify that the polyfill file exists and resolves in the browser.

Closes PACK-2993
2024-05-02 22:15:09 -07:00
vercel-release-bot
50f3823d7e v14.3.0-canary.37 2024-05-02 23:23:31 +00:00
vercel-release-bot
6475431a4c v14.3.0-canary.36 2024-05-01 23:22:31 +00:00
vercel-release-bot
673abe469b v14.3.0-canary.35 2024-05-01 22:36:34 +00:00
vercel-release-bot
c9a34f8b5c v14.3.0-canary.34 2024-05-01 15:38:17 +00:00
Tobias Koppers
77706b68a7
Turbopack: rename source map prefix (#64965)
### What?

see https://github.com/vercel/turbo/pull/8034

### Why?

### How?
2024-05-01 05:21:50 +00:00
vercel-release-bot
34a96e126a v14.3.0-canary.33 2024-04-30 23:21:55 +00:00
vercel-release-bot
a55b912f41 v14.3.0-canary.32 2024-04-30 09:29:58 +00:00
Tim Neutkens
bbd8452d6b
Fix crypto import in edge runtime with Turbopack (#65171)
## What?

Ensures just importing `crypto` does not error, only when it is used it
shows an error in the edge runtime. This matches webpack behavior. The
`crypto` module was missing the list of unsupported packages in the
Next.js Turbopack integration.

Fixes #64464
Fixes PACK-2954

## TODO

While adding tests for this issue I found another bug that only happens
with webpack.

Specifically these 4 packages are accidentally being polyfilled even
when they're not set up to be polyfilled. i.e. there's no npm package
installed for polyfilling them through aliasing or such. Even in that
case `punycode`, `process`, `querystring`, and `string_decorder` get
polyfilled regardless, this causes the newly added test to fail.

Removing the polyfills would be potentially breaking so we'll want to
change it in Next.js 15 instead.

<!-- 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-3252
2024-04-30 11:26:52 +02:00
vercel-release-bot
3ec0a137d5 v14.3.0-canary.31 2024-04-29 23:21:59 +00:00
vercel-release-bot
c24987b06f v14.3.0-canary.30 2024-04-28 23:21:28 +00:00
vercel-release-bot
3f907d38cb v14.3.0-canary.29 2024-04-27 20:33:30 +00:00
vercel-release-bot
5897fc051d v14.3.0-canary.28 2024-04-26 23:21:55 +00:00
Will Binns-Smith
9a3c9ed29f
Turbopack: Allow client components from foreign code in app routes (#64751)
This extends #64520 to cover cases where client components originate
from node_modules (foreign code).

Test Plan: Extended the integration test to cover this

Closes #64412
Fixes PACK-3014

---------

Co-authored-by: OJ Kwon <1210596+kwonoj@users.noreply.github.com>
2024-04-26 15:26:33 -07:00