Commit graph

4834 commits

Author SHA1 Message Date
Tim Neutkens
8502d0aab0
Skip webpack test in Turbopack test run (#57195)
This test checks webpack loaders so can be safely disabled for Turbopack.
2023-10-21 20:58:11 +00:00
Tim Neutkens
23bcfffad2
Fix SCSS and SCSS loader handling tests for Turbopack (#57192)
These tests depend on the order of test runs in order to run, so they fail if the first test has not run. This ensures it's skipped for the others.
2023-10-21 20:45:57 +00:00
Tim Neutkens
2bb9b2a7c2
Fix two tests that use exportPathMap for Turbopack (#57194)
More Turbopack test 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 #

-->
2023-10-21 13:32:48 -07:00
Jiachi Liu
c43c915961
Polish auto create layout warning color (#57190)
### After
<img width="643" alt="image" src="https://github.com/vercel/next.js/assets/4800338/254f2ecf-1a22-4756-baf8-d497fa9485ee">

### Before
![image](https://github.com/vercel/next.js/assets/4800338/8acf8c6e-690f-4827-a8fb-bd729e276f0f)
2023-10-21 19:21:22 +00:00
Shu Ding
a383b93556
Encoding and decoding variables of Server Actions from the closure (#56377)
This PR implements encryption and decryption for Server Action bound values that are from the closure level. Explicit `.bind` values, function arguments and module-level values are NOT handled.

### Compiler

The compiler now groups all closure bound values to an array which gets wrapped with `encrypt`. And then inside the action body, it prepends an expression to recreate the values via `await decrypt`.

Since closure-closed variables will only exist on the server layer, the encryption utility has `"server-only"` annotated.

### Encryption

During build time, a private AES-GCM encryption key is randomly generated and stored in the built server manifest. Before encrypting/decrypting, an extra round of Flight server and client will be used to serialize/deserialize the value.

When encrypting, a salt that contains the action ID is provided to prevent replay attack towards different API endpoints. The encryption key can be overridden via the `NEXT_SERVER_ACTIONS_ENCRYPTION_KEY` env variable so it can be built on multiple machines on scale.

A global singleton for storing the client reference manifest was made for Flight's serialization/deserialization as that might happen outside of rendering.

After encryption, we then serialize the ArrayBuffer as Base64 to send it to the client.
2023-10-21 17:52:06 +00:00
Jimmy Lai
4e27b908fe
misc: fix injecting --inspect with NODE_OPTIONS (#57159)
This PR fixes the passing of the `--inspect` option when calling Next.js with it. It's still not great because you need to target the next file in node_modules directly but I'll add a `next --inspect` option in the future.
2023-10-21 00:49:41 +00:00
Will Binns-Smith
1ffef0f1a3
Turbopack: support more server code in tracing error stack frames (#57156)
This:
- Uses `isServer` to use the appropriate Turbopack `FileSystem` when
creating `FileSystemPath`s
- Properly uri decodes path segments originating from `file://` uris
- Correctly reads chunks starting at the project path instead of the
root path


Closes WEB-1815

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2023-10-20 17:09:10 -07:00
Leah
0d2edbb23f
chore: move layer from chunking context to asset context (#57149)
The asset context is a better place to store the layer, because it's
affected by transitions unlike the chunking context

This PR also removes a bunch of unused code

### Why?

See https://github.com/vercel/turbo/pull/6237 for the rationale
Also needs to wait for that PR to be merged

Closes NEXT-1814

#### Turbopack Changes
* https://github.com/vercel/turbo/pull/6237 <!-- Leah - chore: move
layer from chunking context to asset context -->

---------

Co-authored-by: Tobias Koppers <tobias.koppers@googlemail.com>
2023-10-21 02:05:00 +02:00
Jiachi Liu
e6fbeabd1a
Display experimental features for next build (#57152)
Display full information of experimental features in `next build`, so we'll have full insights for build logs


Close NEXT-1697

* `next build`
<img width="668" alt="image" src="https://github.com/vercel/next.js/assets/4800338/6ab75923-0336-4624-905f-347fedbff5a9">
2023-10-20 22:37:23 +00:00
Josh Story
5528cc6d4e
Remove the experimental serverActions flag (#57145)
Remove the experimental `serverActions` flag

Co-authored-by: Shu Ding <3676859+shuding@users.noreply.github.com>
Co-authored-by: Jiachi Liu <4800338+huozhi@users.noreply.github.com>
2023-10-20 20:45:25 +00:00
Balázs Orbán
f9bd6f7621
chore: drop web streams polyfilling on globalThis (#57077)
### What?

`globalThis.ReadableStream` and `globalThis.WriteableStream` has been exposed since Node.js 18, which is our new default requirement. (#56943)

### Why?

This simplifies the code and might result in slightly better performance.

### How?

Drop any checks of `globalThis` properties that are always defined now.
2023-10-20 19:38:35 +00:00
Balázs Orbán
2277797dc2
chore: drop form-data (#57141)
### What?

Dropping `form-data` polyfill as Node.js 18+ versions all expose it on `globalThis`

### Why?

Reduce the amount of shipped code in Next.js

### How?

Similar to #56899

See: https://nodejs.org/docs/latest-v18.x/api/globals.html#class-formdata
2023-10-20 19:25:42 +00:00
Tobias Koppers
a63c74924a
make test case less flaky (#57138)
### What?

test case is flaky

### Why?

### How?


Closes WEB-1813
2023-10-20 19:46:02 +02:00
Sebastian Markbåge
c41debd23a
Expose Experimental Taint APIs (#56507)
Exposes the new experimental Taint APIs using the `taint` flag which
enables experimental React.

As an example for how we can use it, I use it to taint `process.env`
with a better error message. I'm not sure where this should live since
it's a global init but it needs access to the global config. It's
unnecessary to retaint it for every render but not sure if there's a
better place for it.

---------

Co-authored-by: Jimmy Lai <laijimmy0@gmail.com>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2023-10-19 19:02:37 -07:00
Jimmy Lai
6d2df8636a
build: don't error when bundling optional peer deps (#57073)
This PR adds a resolver plugin to verify during bundling that when a module is unresolved, that it is not an optional peer dependency specified in the package.json of the caller. An error would happen if you try to bundle packages like `typeorm` since there are `require` calls in the code to those dependencies.

Also, swallow dynamic dependencies warnings in `require` calls error if they come from `node_modules`. They are not actionable at all generally.
2023-10-20 00:57:06 +00:00
Tobias Koppers
040a4f75e8
update test manifest (#56938)
Update test manifest from daily test run

Closes WEB-1792
2023-10-20 00:43:56 +00:00
JJ Kasper
477cf794e1
Update CNA tests more (#57088)
Follow-up to https://github.com/vercel/next.js/pull/57025 this updates other places we run the `create-next-app` CLI in tests.
2023-10-19 23:49:31 +00:00
Steven
a3aa6590ff
chore(next/image)!: mark domains as deprecated in favor remotePatterns (#57062)
We already had `domains` as "not recommended" but this PR marks it as "deprecated" and prints a warning if its detected.

I also updated all examples to switch from `domains` to `remotePatterns`.
2023-10-19 20:24:48 +00:00
Balázs Orbán
4c46ddd92a
chore: drop undici (#56899)
### What?

Note: This is not a breaking change, just removing some unused code.

### Why?

Since #56896 we don't need this, as Node.js 18+ has `fetch` exposed by default.

### How?

Depends on #56896, #56909

We already didn't load `fetch` if `globalThis` had it (ie. Node.js 18+ environments), and since we are dropping support for Node.js 16, these code paths should have no effect on runtime behavior.
2023-10-19 18:35:12 +00:00
Balázs Orbán
33db463fe4
chore: upgrade jest (#56909)
### What?

Upgrade jest to its latest version

### Why?

#56899 fails because historically Jest stripped the globals in Node.js, but 28+ isn't doing that anymore. If we upgrade, we don't have to keep track of Node.js globals and when they are added. This will be useful in removing even more polyfills for things that are natively shipped in Node.js now.

### How?

Jest 29 introduced a change to the snapshot format: https://jestjs.io/blog/2022/08/25/jest-29

First, I tried setting the old compat option to not require updating snapshots, but some tests were still failing: https://dev.azure.com/nextjs/next.js/_build/results?buildId=70633&view=logs&j=8af7cf9c-43a1-584d-6f5c-57bad8880974&t=7ae70e63-3625-50f4-6764-5b3e72b4bd7a&l=273 So going through the pain now instead.
2023-10-19 17:38:24 +00:00
Jiachi Liu
a6d4c77f41
Prefer module over main on main fields for app router server compiler (#56960)
Reverts vercel/next.js#56766
Reland vercel/next.js#56532 

x-ref: https://vercel.slack.com/archives/C04DUD7EB1B/p1697576563771229?thread_ts=1697146531.305779&cid=C04DUD7EB1B

This change was breaking package which was actually a dual package but marked as esm module, and when the package is ESM but import a CJS dependency without fully spepcified file path it will fail to resolve. The way is to either remove the esmodule type in package.json or change the import to full path import with extension for the package
2023-10-19 16:06:47 +00:00
Jiachi Liu
a3e56c9c1e
Move ImageResponse to next/og (#56662)
### Story

Since we introduced `ImageResponse` into `next/server` export, there're a few libraries relying on `next/server` that accidentally ended up with bundling og image into the bundle. As og package is quite large that could easily raise the size concern for middleware, edge runtime routes.

### Struggles
 We've done optimizations. The tree-shaking strategies are tricky, we tried modularize imports and also optimize cjs require/exports to make sure you're not including og package into bundle if it's not being used. However, it's still not 100% can handle all the bundle optimization cases, such as `import {..} from "next/server.js"` could also ended up with the cjs bundle that failed the tree-shaking.

### Move on
So we decide to move og `ImageResponse` into a separate export `next/og`

Closes NEXT-1660
2023-10-19 14:26:48 +00:00
JJ Kasper
3010ae10e1
Update CNA tests to avoid publish conflict (#57025)
This avoids testing against latest exact canary version as this causes these tests to fail while the publish is still in progress. As a follow-up we can investigate moving this post publish or packing/deploying tarballs to use. 

Co-authored-by: Steven <229881+styfle@users.noreply.github.com>
2023-10-19 13:52:10 +00:00
Quentin
abe8b1e0a8
Improve performance of String.prototype.split uses (#56746)
This PR adds the optional `limit` parameter on String.prototype.split uses.

> If provided, splits the string at each occurrence of the specified separator, but stops when limit entries have been placed in the array. Any leftover text is not included in the array at all.

[MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split#syntax)

While the performance gain may not be significant for small texts, it can be huge for large ones.

I made a benchmark on the following repository : https://github.com/Yovach/benchmark-nodejs

On my machine, I get the following results:
`node index.js`
> normal 1: 570.092ms
> normal 50: 2.284s
> normal 100: 3.543s

`node index-optimized.js`
> optmized 1: 644.301ms
> optmized 50: 929.39ms
> optmized 100: 1.020s

The "benchmarks" numbers are : 
- "lorem-1" file contains 1 paragraph of "lorem ipsum"
- "lorem-50" file contains 50 paragraphes of "lorem ipsum"
- "lorem-100" file contains 100 paragraphes of "lorem ipsum"
2023-10-19 00:25:15 +00:00
Steven
8e2034573e
Revert "chore(next/image): remove deprecation of onLoadingComplete temporarily" (#57024)
Reverts vercel/next.js#57020

This should be safe to land again after the patch release
2023-10-19 00:15:31 +00:00
Steven
67781ee34e
chore(next/image): remove deprecation of onLoadingComplete temporarily (#57020)
- Temporary revert of #56944
2023-10-18 21:58:07 +00:00
Wyatt Johnson
07c434d54b
Web Streams cleanup (#56819)
This updates some code related to web streams and encoding.

- Removes some unused code related to base64 encoding/decoding (Edge runtime currently supports it natively via `Buffer`)
- Prefer readable stream `pull` versus `.on("data", (chunk) => { ... })` event handlers (simplifies execution)
- Utilize `pipeTo` and `pipeThrough` on web streams to remove custom code related to stream pumping
- Updates pipe readable function to utilize web streams first class rather than relying on manual pumping + stream management
  - This also takes advantage of the `AbortController` when piping so that the response can use it to cancel the stream
2023-10-18 21:38:28 +00:00
Steven
92cccfb47b
chore(test): add logs for create-next-app tests (#56957)
This will help us debug why these tests sometimes flake by logging which command was running last.
2023-10-18 17:39:49 +00:00
Zack Tanner
c2ac8df073
add better logs around worker restarts (#57004)
We currently log when a worker is restarted but not when we send the kill signal, which can create a delta in logs of cryptic errors while the worker is exiting. This explicitly logs when we're terminating the static worker prior to a restart, and also adds an optional logger fn so that we pretty-print the messages. 

[slack x-ref](https://vercel.slack.com/archives/C061DJBG8PN/p1697491350970269)
2023-10-18 16:11:40 +00:00
Tobias Koppers
607ba02a26
Reland "feat(turbopack): support basic next/dynamic" (#56934)
This reverts commit 8a51ebcb67.

### What?

see #56389 


Closes WEB-1791
2023-10-18 02:53:40 +00:00
Balázs Orbán
523474c8be
chore: lower Node.js version requirement (#56943) 2023-10-17 23:15:31 +02:00
Steven
3a459ca986
chore(next/image)!: mark onLoadingComplete as deprecated in favor of onLoad (#56944)
## History

We used to pass `onLoad` through directly to the underlying img so `onLoadingComplete` was introduced in order to handle the case when `placeholder="blur"` was used and `onLoad` would trigger before the placeholder was removed.

We have since changed the behavior of `onLoad` so that it acts the same as `onLoadingComplete` and therefore `onLoadingComplete` is no longer needed.

## What is this PR doing?

This PR marks `onLoadingComplete` as deprecated in favor of `onLoad`. In the future, we may remove `onLoadingComplete`.
2023-10-17 21:12:22 +00:00
Steven
6ed4fddf8a
chore(test): set COREPACK_ENABLE_STRICT: 0 for create-next-app tests (#56955)
I think some of the runners are missing `yarn` globally installed so its attempting to install with corepack. But the default behavior of corepack is to use the repo version (pnpm in this case) so running `yarn` will error. This PR disables corepack strict mode to avoid that problem.
2023-10-17 19:56:06 +00:00
Janicklas Ralph
5e474a3f19
Adding useGoogleTagManager hook to @next/third-parties (#56106)
This PR adds the `useGoogleTagManage` hook to `@next/third-parties` repo.
2023-10-17 18:04:53 +00:00
Jimmy Lai
451a54cb2e
cache: add unstable_noStore API (#56930)
This PR introduces a new API, `unstable_noStore`, which will allow users to declaratively opt out of caching anywhere during static generation in the same way that you can specify `cache: 'no-store'` on a fetch call in Next.js.

An important caveat and difference from just calling `cookies()` to opt-out of static generation is that this won't opt you out when called from within `unstable_cache` and instead defers to the cache configuration to it.

```
import {unstable_noStore as noStore} from 'next/cache';

export default async function Component() {
  noStore();
  const result = await db.query(...);
}
```
2023-10-17 14:52:46 +00:00
dpnolte
218d0709eb
feat: set status code to 500 if unexpected error occurs before streaming in app router (#56236)
<!-- 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 #

-->

This PR therefore introduces to always set response status code to 500
unless it is a `NotFoundError` or `RedirectError`. This PR would fix
issue #56235. See also:
https://codesandbox.io/p/sandbox/nice-panini-2z3mcp .

**Current Behavior**
At the moment, when an unexpected error occurs during app server
rendering, a 200 ok is returned as status code. This seems to be
undesirable because of the success status CDNs will cache the error
pages and crawlers will index the page considering the error content as
the actual content.

**Desired Behavior**
This issue is related to discussion
https://github.com/vercel/next.js/discussions/53225. Even though I
understand that the response status code cannot be set if streaming has
started, in my view it would be best to set the response status to 500
whenever it can (so before the streaming has started) for SEO and (CDN)
http caching. This would also be consistent with how 404s currently
work; that is, response status code is set to 404 if `NotFoundError`
occurred before streaming (related
[issue](https://github.com/vercel/next.js/issues/43831) &
[PR](https://github.com/vercel/next.js/pull/55542)).

Ideally, when a runtime error happens after streaming, a `<meta
name="robots" content="noindex" />` would also be added. But I didn't
want to make the PR too complex before receiving feedback.

---------

Co-authored-by: Vũ Văn Dũng <me@joulev.dev>
Co-authored-by: Tobias Koppers <tobias.koppers@googlemail.com>
2023-10-17 15:32:20 +02:00
Mateusz Burzyński
db214214d6
Update Babel dependencies (#51962)
### What?

Update Babel packages across the board

### Why?

Since you ship vendored presets and plugins it's impossible for people to update this stuff at their own pace - independently from Next. So users of `next/babel` are currently stuck with old versions and, for example, they might not be able to use the TS `satisfies` operator.

### How?

I just updated ranges (to pinned ones) where I could find them, run `corepack pnpm i` and re-run build scripts in the `packages/next`.

Fixes #43799
2023-10-17 02:25:57 +00:00
Josh Story
0a80017d03
Update React from d900fadbf to 09fbee89d. Removes server context and experimental prefix for server action APIs (#56809)
The latest React canary builds have a few changes that need to be
adopted for compatability.

1. the `useFormState` and `useFormStatus` hooks in `react-dom` and the
`formData` opiont in `react-dom/server` are no longer prefixed with
`experimental_`
2. server content (an undocumented React feature) has been removed. Next
only had trivial intenral use of this API and did not expose a coherent
feature to Next users (no ability to seed context on refetches). It is
still possible that some users used the React server context APIs which
is why this should go into Next 14.

### React upstream changes

- https://github.com/facebook/react/pull/27513
- https://github.com/facebook/react/pull/27514
- https://github.com/facebook/react/pull/27511
- https://github.com/facebook/react/pull/27508
- https://github.com/facebook/react/pull/27502
- https://github.com/facebook/react/pull/27474
- https://github.com/facebook/react/pull/26789
- https://github.com/facebook/react/pull/27500
- https://github.com/facebook/react/pull/27488
- https://github.com/facebook/react/pull/27458
- https://github.com/facebook/react/pull/27471
- https://github.com/facebook/react/pull/27470
- https://github.com/facebook/react/pull/27464
- https://github.com/facebook/react/pull/27456
- https://github.com/facebook/react/pull/27462
- https://github.com/facebook/react/pull/27461
- https://github.com/facebook/react/pull/27460
- https://github.com/facebook/react/pull/27459
- https://github.com/facebook/react/pull/27454
- https://github.com/facebook/react/pull/27457
- https://github.com/facebook/react/pull/27453
- https://github.com/facebook/react/pull/27401
- https://github.com/facebook/react/pull/27443
- https://github.com/facebook/react/pull/27445
- https://github.com/facebook/react/pull/27364
- https://github.com/facebook/react/pull/27440
- https://github.com/facebook/react/pull/27436

---------

Co-authored-by: Zack Tanner <zacktanner@gmail.com>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
Co-authored-by: Jiachi Liu <inbox@huozhi.im>
2023-10-16 15:46:10 -07:00
Balázs Orbán
1ff7f07875
feat: drop Node.js 16 (#56896)
### What?

BREAKING CHANGE: Bump the minimum required Node.js version.

### Why?

Node.js 16 has reached end-of-life in September.

Bumped to `18.18.2` since it contained some security-related patches: https://nodejs.org/en/blog/vulnerability/october-2023-security-releases

### How?

Bumped `engines` where needed, upgraded the workflows.

This will allow us to remove quite a few polyfills, I'll open separate PRs for those.
2023-10-16 21:41:38 +00:00
Steven
d32121b736
chore(test): test remote image from proxy (#56895)
This PR adds a test to ensure we don't regress again when using proxies
in front of Next.js with `connection: 'upgrade'`.

- Regression introduced in https://github.com/vercel/next.js/pull/56226
- Issue reported in https://github.com/vercel/next.js/issues/56038
- Rolled back in https://github.com/vercel/next.js/pull/56836
2023-10-16 14:48:29 -04:00
Zack Tanner
3e77d69ca0
improve next-image-proxy test (#56893)
This fixes a warning where the test server was exiting before all the
proxy requests finished. This also throws an error to fail the test if
any of the proxied requests aren't fulfilled.

[slack
x-ref](https://vercel.slack.com/archives/C04DUD7EB1B/p1697465502593889?thread_ts=1697143786.511779&cid=C04DUD7EB1B)
2023-10-16 08:36:34 -07:00
Tobias Koppers
8a51ebcb67
Revert "feat(turbopack): support basic next/dynamic" (#56885) 2023-10-16 06:37:41 -07:00
Tim Neutkens
4e435e2fe6
Skip webpack specific tests in Turbopack test run (#56877)
Looked for `webpack(config` in the test suites and disabled the ones that are testing webpack specifically. There are a few more that are not skipped as they should be implemented for Turbopack.
2023-10-16 10:34:50 +00:00
OJ Kwon
5b52e7772d
feat(turbopack): support basic next/dynamic (#56389)
Closes WEB-1702

This PR implements initial support for the `next/dynamic` in Turbopack,
more specifically resolving some hydration errors and other components
boot up cases.

Previously, turbopack had partial next/dynamic support via its own mode
(https://github.com/vercel/next.js/pull/56389/files#diff-e1af4f79cb88a73f819a25443d15ed4b1ffabcbb879256caa59b751fad46d7c4L68),
which does a transform against `next/dynamic` wrapped import to embed
dynamically resolvable chunk ids like
(ad42b610c2/packages/next-swc/crates/next-transform-dynamic/tests/fixture/wrapped-import/output-turbo-dev-server.js).

However, since next.js relies on static path to the chunks to the
dynamic import and passing those ids in between client-server to ensure
component load (and avoid hydration errors), it doesn't work out of the
box. This PR changes turbopack's behavior to closely mimic what current
next.js's webpack plugin does, by

1. Traverse the module graph, find out `dynamic(import())`
2. Generate chunks for those imports, creates a partial LoadableManifest
per each imports
3. Merge partial manifest into a single `react-loadable-manifest.json`
4. For the id, use static (Webpack mode) instead of dynamic so we can
embed it in `react-loadable-manifest` as well as next.js can use it to
pass it between server-client context.

I left a small comment to the implementation
(https://github.com/vercel/next.js/pull/56389/files#diff-bf12ed2c69d0bc89a06884779da4ae44967eb8becada031dea12bedef28e2622R155)
for the lifecycle of this feature in case to fix further.

This makes to pass most of the basic next-dynamic related integration
tests, except if the import have webpack specific features like
ad42b610c2/test/development/basic/next-dynamic/pages/dynamic/multiple-modules.js (L5).

---------

Co-authored-by: Tim Neutkens <tim@timneutkens.nl>
2023-10-16 10:24:54 +02:00
Tim Neutkens
82e1057a7f
Fix CSP test when using Turbopack (#56833)
Since Turbopack doesn't use eval-source-map the CSP nonce will pass correctly, nice improvement over the current state where you can't check CSP in dev.
2023-10-14 20:07:29 +00:00
Tim Neutkens
c6fe20a31f
Remove specific hash checks for metadata.test.ts (#56843)
This ensures the tests pass in both webpack and Turbopack.

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

-->
2023-10-14 19:54:55 +02:00
Tim Neutkens
83d8867470
Add missing nanoid dependency to app-dir tests (#56830)
Fixes a bunch of the Turbopack test failures for `test/e2e/app-dir/app/index.test.ts`. Not sure how this passed with webpack before as the dep was indeed missing.
2023-10-14 11:32:10 +00:00
Balázs Orbán
fe0bfbf911
fix: add x-forwarded-* headers (#56797)
### What?

Adding back `x-forwarded-*` headers.


### Why?

Starting with #52492, these headers were lost.

### How?

We can populate these headers before executing a request.

Closes NEXT-1663
Fixes #55942
2023-10-13 17:58:33 +00:00
Tobias Koppers
04bad16bf4
Turbopack: Chunking Refactoring (#56756)
### What?

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

### Turbopack Changes

* https://github.com/vercel/turbo/pull/6116 
* https://github.com/vercel/turbo/pull/6140 
* https://github.com/vercel/turbo/pull/6118 
* https://github.com/vercel/turbo/pull/6128 
* https://github.com/vercel/turbo/pull/6129 
* https://github.com/vercel/turbo/pull/6160 


Closes WEB-1772

Co-authored-by: Justin Ridgewell <112982+jridgewell@users.noreply.github.com>
2023-10-13 11:44:44 +00:00
Tobias Koppers
e8a92a9507
update manifest (#56737)
### What?

updates from daily test run


Closes WEB-1766
2023-10-13 11:19:54 +02:00
Zack Tanner
3264d91dab
memoize useParams (#56771)
`useParams` is not referentially equal between renders which can lead to unexpected behavior when used as a dep. 
This memoizes the response from `useParams` similar to `useSearchParams`.

[slack x-ref](https://vercel.slack.com/archives/C04DUD7EB1B/p1697145987740229)
2023-10-13 07:47:05 +00:00
Zack Tanner
476af24628
Revert "Prefer module over main on main fields for app router server compiler" (#56766)
This was causing some issues with our deployments.

[slack x-ref](https://vercel.slack.com/archives/C04DUD7EB1B/p1697146531305779)
2023-10-12 21:38:44 +00:00
Jiachi Liu
6814ff147a
Prefer module over main on main fields for app router server compiler (#56532)
This change is to pick the esm assets for RSC server layer and server rendering side, this is for production and development perf purpose, also to let them apply with the ESM related optimization such as tree-shaking, barrel files optimizations, etc.

We found a few packages that can't be optimized easily in bundling because we're using "main" field so the packages are not able to be tree-shaked, ending up with large bundle in the dist. This will change a lot for the bundling improvements as some packages are only having "main" and "module" field. So switching from CJS to ESM means better bundling, more optimization, and faster code.

#56501 was a precondition for this, as previously the bundling strategy was applied to some library but triggered the invalid hooks erroring.

### Other Monior Change
Previously we'll prefer to resolve CJS as there're 2 versions of react, using CJS assets will help let them pass by require-hook to use canary react for app router bundling assets. But now we changed the approach to bundling nextjs runtime and react packages. Now we dropped the condition that prefered to resolve CJS exports for externals, since if you're putting them in `serverComponentsExternalPackages`, they're not using the built-in react, so could potentially having trouble if any dependency is using react but excluded in bundles. So far we didn't see any report to this.

Closes NEXT-1286
2023-10-12 16:10:55 +00:00
Tim Neutkens
3bb80cfb83
Improve chunk encoding test to check right path for Turbopack (#56747)
This only fixes the test check, Turbopack wil have to `encodeURI` the
files in the FlightManifest. Similar to what the webpack plugin does:
https://github.com/vercel/next.js/blob/canary/packages/next/src/build/webpack/plugins/flight-manifest-plugin.ts#L111

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

-->
2023-10-12 14:59:26 +02:00
Jimmy Lai
35a99232c0
misc: tweak stats github action (#56694)
This PR adds a few tweaks to our Github actions PR:
- expand by default the main section
- add some heuristics to not show hash/id changes in the diff view
- add some heuristics to not show increase/decrease size when it's too small (100 bytes is noise most often)
- add rendering runtimes to the list of tracked files


after vs before

![CleanShot 2023-10-11 at 14 56 36@2x](https://github.com/vercel/next.js/assets/11064311/548781bc-e893-45d1-aca4-de73b2b30299)

![CleanShot 2023-10-11 at 14 57 11@2x](https://github.com/vercel/next.js/assets/11064311/8e1c77e3-bed5-46ec-a756-62496df6729e)
2023-10-12 08:27:44 +00:00
Zack Tanner
d735d317d1
fix static worker restart behavior (#56728)
In [55841](https://github.com/vercel/next.js/pull/55841), this file was reworked to improve type safety and readability, but it changed the behavior of how we were invoking methods on the worker. Specifically, when a restart occurred, this timeout wrapping function was referencing an already ended worker, resulting in a "Farm is ended, no more calls can be done to it" build error.

This PR ensures that we're fetching the method from the current `this._worker` at the time of invocation, not at the time of method creation.

[Slack x-ref](https://vercel.slack.com/archives/C04KC8A53T7/p1697064752635179?thread_ts=1696952142.759769&cid=C04KC8A53T7)
2023-10-12 00:19:29 +00:00
Tim Neutkens
5be28886c3
Use unique names for separate test suites (#56695)
These two get reported under the same name which makes it harder to
distinguish in the dashboard.

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

-->
2023-10-11 14:42:12 +02:00
JJ Kasper
dabeb51fff
Fix SSG query with experimental-compile (#56680)
Ensures query isn't omitted when using experimental compile mode with SSG pages as it skips the isReady delay that is normally done with prerendering.
2023-10-11 01:52:36 +00:00
Will Binns-Smith
c8b2d1b44a
(test only) Integration tests: remove flatMap polyfill (#56546)
This has been supported since Node 11. Remove this from our integration tests.

Test Plan: CI


Closes WEB-1735
2023-10-10 20:39:54 +00:00
JJ Kasper
7a08f0082d
Fix trace ignore handling (#56674)
This ensures we separate our ignore handling for next-server runtime entries and `.next/server` chunks. When these were combined our ignores caused modules that should were actually needed by user code to be excluded. 

Verified patch against the provided minimal repros

![CleanShot 2023-10-10 at 11 56 36@2x](https://github.com/vercel/next.js/assets/22380829/1dd83996-fa95-462a-98ed-485ce6c4d3f5)

![CleanShot 2023-10-10 at 12 01 08@2x](https://github.com/vercel/next.js/assets/22380829/c17c6147-0e3e-422b-bf2d-5fedfd6827ef)


x-ref: https://github.com/vercel/next.js/pull/56048#discussion_r1345651964
Fixes: https://github.com/vercel/next.js/issues/56357
2023-10-10 19:41:44 +00:00
Tobias Koppers
52356a0e14
invert test filtering logic to exclude known failing (#56663)
### What?

instead of include known passing tests

also updates the update test manifest

### Why?

Newly added test cases should always pass turbopack (or at least you would need to manually opt-out of it.

### How?

Uses a exclude list of tests instead of an allow list

Closes WEB-1752
2023-10-10 18:26:40 +00:00
Steven
35f507242c
fix: next dev with edge runtime on windows (#56502)
- Reverts https://github.com/vercel/next.js/pull/44616
- Regression introduced in https://github.com/vercel/next.js/pull/51651
- Fixes https://github.com/vercel/next.js/issues/55013
2023-10-10 14:03:03 +00:00
Jimmy Lai
56fe014532
chore: bump pnpm to 8.9 (#56649)
There's allegedly a bump in performance for mac for pnpm 8.9 so upgrading it in the repo.
2023-10-10 11:23:10 +00:00
Leah
b4660d8f25
feat(turbopack): add support for edge app pages (#56426)
<!-- 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: Tim Neutkens <tim@timneutkens.nl>
2023-10-09 16:32:20 +02:00
stefanprobst
e75c366826
fix: don't add isolateModules to tsconfig when extending from tsconfig with verbatimModuleSyntax (#54164)
<!-- 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 #

-->

this is a follow-up to #48018 (don't add `isolatedModules: true` to
`tsconfig.json` when `verbatimModuleSyntax: true` is set), which also
handles the case where `verbatimModuleSyntax: true` is set in a base
tsconfig which is being referenced via `tsconfig#extends`.

---------

Co-authored-by: Zack Tanner <zacktanner@gmail.com>
2023-10-07 07:38:56 -07:00
Tobias Koppers
542f080524
update test manifest (#56522)
update manifest from daily results

Closes WEB-1728
2023-10-07 11:07:59 +02:00
Sukka
edb92a30b5
test: speed up isolated next instance test setup (#56525) 2023-10-07 00:15:59 +02:00
Will Binns-Smith
3c326ea5e8
Turbopack + app router: always use externals for predefined packages (#56440)
This applies the predefined list of packages in server-external-packages.json as always external when used by app router in Turbopack

Test Plan: Added integration tests

Closes WEB-1709
2023-10-06 19:08:01 +00:00
Jimmy Lai
c4c60b37f7
misc: force run e2e deploy tests with bundled server (#56513)
This PR forces the deployments used for e2e testing to use the bundled server.

Manual deploy run https://github.com/vercel/next.js/actions/runs/6430048350
2023-10-06 17:42:41 +00:00
Will Binns-Smith
58db85fb02
Add test for using external node_modules for pages (#56433)
This adds a test that asserts that, without additional configuration like `experimental.bundlePagesExternals`, Next.js does not bundle `node_modules` for pages.


Closes WEB-1708
2023-10-06 17:32:37 +00:00
Shu Ding
9b671046b9
Flatten recursive wildcard exports in barrel optimization (#56489)
This PR flattens the recursive optimization logic of our barrel optimization loader. So now if there're any recursive `export * from ...`, they won't be created as multiple individual Webpack modules, but optimized in one module.

With this change, we are running SWC transform to get the export map directly inside the barrel loader (instead of a separate loader rule). And that map is recursively calculated and cached in memory.

I also published https://unpkg.com/browse/recursive-barrel@1.0.0/ to give this a test. It contains 4 levels of 10 `export *` expressions, which is 10,000 modules in total. Without this change, it takes ~30s to compile and with this change, it goes down to ~7s.
2023-10-06 15:39:15 +00:00
Tim Neutkens
f95421289f
Remove isTurbo check in custom-routes test (#56360)
This variable wasn't used anymore.
<!-- 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 #

-->
2023-10-06 11:10:12 +02:00
Tim Neutkens
5a49b88fb9
Use consistent name for App Router tests (#56352)
Ensures all App Router tests have a unique name and similar reference
(with `-`).

<!-- 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: Jiachi Liu <inbox@huozhi.im>
2023-10-06 11:06:06 +02:00
Tim Neutkens
2a479316ea
Remove app dir warning test (#56350)
This test was failing in Turbopack because the option no longer exists.
Fine to remove it for now.

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

-->
2023-10-06 11:05:45 +02:00
Jiachi Liu
9d150b116d
Loose RSC import restrictions for 3rd party packages (#56501)
When we landed #51179 it broke library like `apollo-client` as it's bundling client hooks into RSC bundle, so our RSC linter caught them and reported fatal errors. But those client hook APIs won't get executed in RSC. The original purpose of erroring on invalid hooks for server & client components was to catch bugs easier, but it might be too strict for the 3rd party libraries like `apollo-client` due to few reasons. 

We changed the rules only applying on user land source code. For 3rd party packages if they're not being imported correctly into proper server or client components, we're still showing runtime errors instead of fatal build errors.

x-ref: https://github.com/apollographql/apollo-client/issues/10974
Closes NEXT-1673
2023-10-05 23:59:22 +00:00
Sukka
d21025cc3a
refactor: rewrite config schema in zod (#56383)
The PR supersedes the https://github.com/vercel/next.js/pull/53150, which is way too outdated, has way too many conflicts, and also heavily relies on GitHub Copilot (which makes the progress slow and tedious).

The PR uses [`json-schema-to-zod`](https://github.com/StefanTerdell/json-schema-to-zod) (instead of the GitHub Copilot) to generate the zod schema, and manually replaces all generated `z.customRefine` with my hand-written zod schema.

TODO:

- [x] Convert schema
- [x] Reduce `z.any()` usage
- [x] Create human-readable errors from the `ZodError`
- [x] Update test cases to reflect the latest error message

-----

The benefit of using zod over ajv:

- Easier maintenance: zod schema is straightforward to compose.
- Better typescript support: config schema now strictly reflects the `NextConfig` type.
- Smaller installation size: by replacing `ajv` and `@segment/ajv-human-errors` w/ `zod`, I am able to reduce installation size by 114 KiB.
- Better Extension: the zod error message is easy to customize.

-----

In the previous PR https://github.com/vercel/next.js/pull/56083, @feedthejim replaces `zod` w/ `superstruct`. `superstruct` is lightweight and fast, which makes it perfect for creating simple schemas for RSC payload. But, this also means `superstruct` has its limitations compared to `zod`:

- `superstruct`'s syntax is different, and some utilities's usage is counter-intuitive:
  - `z.array(z.string()).gt(1)` vs `s.size(s.array(s.string()), 1)`
  - `z.numer().gt(1)` vs `s.size(s.number(), 1)`, `s.min(s.number(), 1)`
  - `z.boolean().optional().nullable()` vs `s.nullable(s.optional(z.boolean()))`
- `superstruct` has weaker TypeScript support and worse DX compared to `zod` when composing huge schema:
  - `zod.ZodType + z.object()` can provide a more detailed type mismatch message on which specific property is the culprit, while `Describe + s.object()` provides almost no information at all.
- `zod`'s schema is more powerful
  - `z.function()` supports `z.args()` and `z.returns()`, while `superstruct` only has `s.func()`
  - zod also has Promise type `z.promise()` and intersection type `z.and()`
- `superstruct`'s error is harder to parse compared to `zod`'s `ZodError` 

So in the PR, I re-introduced `zod` for `next.config.js` validation.
2023-10-05 15:46:53 +00:00
Tim Neutkens
524b31513a
Fix logging level in actions test (#56473)
This test was using the old format and because of that failed in
Turbopack. This fixes that.

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

-->
2023-10-05 12:30:39 +02:00
Justin Ridgewell
feca3ce21c
Turbopack: Implement Server Actions (#53890)
### What?

This implements Server Actions inside the new Turbopack next-api bundles.

### How?

Server Actions requires:
1. A `.next/server/server-reference-manifest.json` manifest describing what loader module to import to invoke a server action
2. A "loader" entry point that then imports server actions from our internal chunk items
3. Importing the bundled `react-experimental` module instead of regular `react`
4. A little 🪄 pixie dust
5. A small change in the magic comment generated in modules that export server actions

I had to change the magic `__next_internal_action_entry_do_not_use__` comment generated by the server actions transformer. When I traverse the module graph to find all exported actions _after chunking_ has been performed, we no longer have access to the original file name needed to generate the server action's id hash. Adding the filename to comment allows me to recover this without overcomplicating our output pipeline.

Closes WEB-1279
Depends on https://github.com/vercel/turbo/pull/5705

Co-authored-by: Tim Neutkens <6324199+timneutkens@users.noreply.github.com>
Co-authored-by: Jiachi Liu <4800338+huozhi@users.noreply.github.com>
2023-10-04 23:33:21 +00:00
Josh Story
65b0bb24af
Separate RSC and SSR jsx-runtime modules (#56438)
There should be no shared react packages in our server runtime. rsc should always be separate from ssr.

This update reconfigures the runtiem to eliminate shared react modules. the jsx runtime will now be separate for RSC and SSR. this is necessary because the implementations for the jsx runtime rely on React and they need to see the right versions.

Additionally I fixed an alias so that the shared subset react is used when using react-server condition.

I also fixed a bug in 2 tests related to class/className.

Note: this PR blocks upgrading React canary due to internal changes in how React state is managed in when using the `react-server` condition
2023-10-04 20:29:10 +00:00
JJ Kasper
af04ef353b
Ensure loader generated export default has name (#56388)
When the function name is omitted webpack generates a name from the loader config which can be really long un-necessarily. Providing a name for the default function alleviates this. cc @shuding who found this
2023-10-04 09:28:07 +00:00
Josh Story
09b0ca42fb
App Router - preinitialize chunks during SSR (#54752)
Today when we hydrate an SSR'd RSC response on the client we encounter import chunks which initiate code loading for client components. However we only start fetching these chunks after hydration has begun which is necessarily after the initial chunks for the entrypoint have loaded.

React has upstream changes that need to land which will preinitialize the rendered chunks for all client components used during the SSR pass. This will cause a `<script async="" src... />` tag to be emitted in the head for each chunk we need to load during hydration which allows the browser to start fetching these resources even before the entrypoint has started to execute.

Additionally the implementation for webpack and turbopack is different enough that there will be a new `react-server-dom-turbopack` package in the React repo which should be used when using Turbopack with Next.

This PR also removes a number of patches to React src that proxy loading (`__next_chunk_load__`) and bundler requires (`__next_require__`) through the `globalThis` object. Now the react packages can be fully responsible for implementing chunk loading and all Next needs to do is supply the necessary information such as chunk prefix and crossOrigin attributes necessary for this loading. This information is produced as part of the client-manifest by either a Webpack plugin or Turbopack.

Additionally any modifications to the chunk filename that were previously done at runtime need to be made in the manifest itself now. This means we need to encode the deployment id for skew protection and encode the filename to make it match our static path matching (and resolutions on s3) when using `[` and `]` segment characters.

There are a few followup items to consider in later PRs
1. we currently bundle a node and edge version of react-server-dom-webpack/client. The node version has an implementation for busboy whereas the edge version does not. Next is currently configured to use busboy when handling a fetch action sent as multipart with a node runtime. Ideally we'd only bundle the one platform we are buliding for but some additional refactoring to support better forking is possibly required here

This PR also updates react from 09285d5a7 to d900fadbf.

### React upstream changes

- https://github.com/facebook/react/pull/27439
- https://github.com/facebook/react/pull/26763
- https://github.com/facebook/react/pull/27434
- https://github.com/facebook/react/pull/27433
- https://github.com/facebook/react/pull/27424
- https://github.com/facebook/react/pull/27428
- https://github.com/facebook/react/pull/27427
- https://github.com/facebook/react/pull/27315
- https://github.com/facebook/react/pull/27314
- https://github.com/facebook/react/pull/27400
- https://github.com/facebook/react/pull/27421
- https://github.com/facebook/react/pull/27419
- https://github.com/facebook/react/pull/27418
2023-10-03 21:40:25 +00:00
Leah
515784c277
chore: pass defineEnv from next.js to rust directly (#56216)
### What?

Deduplicates our env var injection between the JS and rust side

Closes WEB-937

---------

Co-authored-by: Tim Neutkens <tim@timneutkens.nl>
Co-authored-by: Zack Tanner <zacktanner@gmail.com>
2023-10-03 22:43:21 +02:00
Shu Ding
8469d0ac27
Add test case for the permalink option of useFormState (#56329)
Ref: https://github.com/facebook/react/pull/27372.

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2023-10-03 13:47:03 +02:00
Tim Neutkens
b79a11f6ad
Fix mjs import for Turbopack test (#56354)
Turbopack currently supports fully-specified `.mjs` imports. Double
check with @sokra to verify if this is correct.

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

-->
2023-10-03 13:33:04 +02:00
Jiachi Liu
7df92b868a
test: add flaky turbopack integration tests to manifest (#56309) 2023-10-03 00:53:09 +02:00
Omar McIver
3172cfedc8
fix: support both decoded and encoded url requests of conventioned files (#56187)
Co-authored-by: Omar McIver <omar.mciver@mode3cloud.com>
Co-authored-by: Jiachi Liu <inbox@huozhi.im>
2023-10-03 00:02:49 +02:00
Boris Besemer
a2f9ef5a34
fix(next/client): keep hash when navigating from app to pages router (#56223)
### What?

Fixes the pages router not receiving a hash when being linked from the
app router.

### Why?

The hash being removed breaks sites that rely on it for client side
features.

### How?

The hash gets omitted from the URL when used as a key for the
preflightCache. Once it's clear that it's an external URL and that it's
not empty we can use the initial href to send the hash as well.

Not completely sure if there's an edge case that might break, I added an
extra check for when the hash is only used to scroll the page.

This might need an additional test case just for
`navigate-reducer.test.tsx`.

Fixes #56212

---------

Co-authored-by: Zack Tanner <zacktanner@gmail.com>
Co-authored-by: JJ Kasper <jj@jjsweb.site>
2023-10-02 14:43:04 -07:00
Tim Neutkens
98432a4630
Remove buildId test as it's no longer relevant (#56316)
Follow-up to #56310.
2023-10-02 18:20:47 +00:00
Sukka
86274e68aa
fix(#53190): add missing crossOrigin to assetsPrefix resources (#56311)
Fixes #53190.

Next.js App Router comprises two categories of resources, same-origin ones (RSC payload, in the form of inline `<script />`) and possibly third-party ones (chunks that respect the `assetPrefix`). The latter should also respect the `crossOrigin` option from `next.config.js`.

Co-authored-by: Jiachi Liu <4800338+huozhi@users.noreply.github.com>
2023-10-02 17:21:49 +00:00
Zack Tanner
e970e050a9
Reland static prefetches & fix prefetch bailout behavior (#56228)
Reland #54403

Also modifies the implementation of #55950 to not change the prefetch behavior when there is flight router state - we should only check the entire loader tree in the static prefetch case, otherwise we're inadvertently rendering the component tree for prefetches that match the current flight router state segment. ([slack x-ref](https://vercel.slack.com/archives/C03S8ED1DKM/p1695862974745849))

This includes a few other misc fixes for static prefetch generation:
- `next start` was not serving them (which also meant tests weren't catching a few small bugs)
- the router cache key casing can differ between build and runtime, resulting in a bad cache lookup which results suspending indefinitely during navigation
- We cannot generate static prefetches for pages that opt into `searchParams`, as the prefetch response won't have the right cache key in the RSC payload
- Layouts that use headers/cookies shouldn't use a static prefetch because it can result in unexpected behavior (ie, being redirected to a login page, if the prefetch contains redirect logic for unauthed users)

Closes NEXT-1665
Closes NEXT-1643
2023-10-02 17:12:55 +00:00
Tim Neutkens
7f60cc8b0f
Support serverRuntimeConfig and publicRuntimeConfig in Turbopack (#56310)
Allows `publicRuntimeConfig` / `serverRuntimeConfig` to be set.
2023-10-02 16:40:58 +00:00
Jiachi Liu
ac95a20276
Fix flaky test for size output (#56303)
x-ref: https://github.com/vercel/next.js/actions/runs/6380869104/job/17316148085?pr=56187

Tune the regex that match the correct number but without leading zero
2023-10-02 15:47:09 +00:00
Tim Neutkens
59bda2d818
More Turbopack fixes (#56299)
Skips additional production-only tests.

Follow-up to #56089.

In this PR I went through all of `test/integration` looking for `nextBuild(` and added the skipping logic.
2023-10-02 13:55:23 +00:00
Tobias Koppers
488fc1c003
clear require cache only when needed (#56198)
### What?

clear require cache only when there has been changes

Before we cleared the require.cache after every ensurePage call. This is
too much. The new approach compares the hashes of all emitted files with
the previous hashes and only clears require.cache when they differ.

### Why?

reloading a page and client navigation is slow due the re-requiring
server files


Closes WEB-1686
2023-10-02 10:57:35 +02:00
Tim Neutkens
2cf8e6c863
More Turbopack fixes (#56275)
Skips additional production-only tests.

Follow-up to https://github.com/vercel/next.js/pull/56089

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

-->
2023-10-02 09:42:32 +02:00
Tobias Koppers
b8a63f44dd
update test mainfest (#56214)
Closes WEB-1687
2023-10-02 08:45:50 +02:00
Tim Neutkens
5f7faac1e6
More Turbopack test fixes (#56248)
Skips additional production tests.

Follow-up to #56089

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

-->
2023-10-01 17:50:03 +02:00
JJ Kasper
e78eee25c5
Add additional handling for experimental-compile (#56224)
This ensures we properly set the `isReady` flag when building with `experimental-compile` and enables our main app dir test suite to ensure we don't regress on it.
2023-09-29 22:11:45 +00:00
Tim Neutkens
2e36e7d85d
Fix middleware-general test for Turbopack (#56211)
This test failed for Turbopack because of the rename from `i18n` to `__i18n` to not use that config. Turbopack does checking of config options to ensure it doesn't run when an option is not implemented, so that caused the test run to bail out.
2023-09-29 15:46:14 +00:00
Jiachi Liu
48093b87a9
Allow jest to run with use server directive (#56148)
Disable server components and server actions SWC transform when it's running jest. You can only do basic DOM testing like what we described in #54891 instead the server action itself.

Closes #53065 
Closes NEXT-1473
2023-09-28 14:15:51 +00:00
Jimmy Lai
8f0f8236ab
perf: add option to bundle pages externals (#56162)
This PR adds an option to forcefully bundle node_modules packages in `pages` on the server. This should benefit cold boots for projects that uses pages, at the cost of build time increase.
2023-09-28 14:01:42 +00:00
Tim Neutkens
711fa2133d
More test updates (#56146)
Follow-up to #56089

<!-- Thanks for opening a PR! Your contribution is much appreciated.i
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 #

-->
2023-09-28 13:11:11 +02:00
Tobias Koppers
cd70065bad
Fixes performance problems due to TaskScopes (#55721)
### What?

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

### Turobopack changes

* https://github.com/vercel/turbo/pull/6009 <!-- OJ Kwon - ci(workflow):
update test filter -->
* https://github.com/vercel/turbo/pull/6026 <!-- Will Binns-Smith -
Remove next-dev references and benchmarks -->
* https://github.com/vercel/turbo/pull/6038 <!-- Tim Neutkens - Remove
test-prod action -->
* https://github.com/vercel/turbo/pull/6039 <!-- Tim Neutkens - Fix
action dependency -->
* ~https://github.com/vercel/turbo/pull/6036~ <!-- Will Binns-Smith -
Turbopack: add support for an asset prefix (and basePath in Next.js) -->
* https://github.com/vercel/turbo/pull/5992 <!-- Tobias Koppers -
refactor TaskScopes to use an aggregation tree -->


Closes WEB-1622
2023-09-28 09:40:21 +02:00
Tobias Koppers
b689f84600
Turbopack: update test manifest (#56133)
Closes WEB-1672
2023-09-28 08:23:26 +02:00
JJ Kasper
2820b2bf4a
special case timeout on windows (#56120)
windows is slower so need to increase the timeout for that one
2023-09-28 03:46:04 +00:00
Leah
293de45acf
feat(turbopack): port bloom filter to nexturbo (#55678)
Closes WEB-1096
2023-09-28 01:00:49 +00:00
JJ Kasper
fb04b85bb6
Decrease default test timeouts (#56116)
When tests are timing out we shouldn't wait for 4 minutes before it officially fails so this brings down the default test timeouts
2023-09-27 23:55:20 +00:00
JJ Kasper
eba9fca3ff
Optimize build trace handling (#56048)
This consolidates our trace handling between turbotrace and the default
`nodeFileTrace` handling to prevent over-tracing. With node-file-trace
it's extremely more efficient to trace in a single `nodeFileTrace` run
so that all resolving/analysis etc can be efficiently cached.

Furthermore, this reduces the amount of chunks we need to trace by
waiting until post build since automatically statically optimized paths
don't need to be traced as they are rendered to purely HTML and never
re-rendered.

This reduces builds times by upwards of 4 - 5 minutes on larger
projects.
2023-09-27 16:07:57 -07:00
Jiachi Liu
7b48a1e2f0
fetching logging on edge (#56108)
Support fetching logging working with edge runtime. When you enable edge runtime and experimental logging config in `next.config.js` you should be able to see the data fetching logs like edge runtime

```
 GET /default-cache 200 in 4304ms
 │ GET https://next-data-api-endpoint.vercel.app/api/random?no-cache 200 in 373ms (cache: SKIP)
 │  │  Cache missed reason: (cache: no-cache)
 │  │ GET https://next-data-api-endpoint.vercel.app/api/random?force-cache 200 in 163ms (cache: SKIP)
 │  │  │  Cache missed reason: (cache-control: no-cache (hard refresh))
 │  │ GET https://next-data-api-endpoint.vercel.app/api/random?revalidate-0 200 in 196ms (cache: SKIP)
 ```

Closes #55495
Closes NEXT-1661
2023-09-27 22:39:42 +00:00
Zack Tanner
4cfb0acd72
Revert: "Generate prefetch RSC payload during build for SSR paths (#54403)" (#56059)
Investigating problems this is causing where incorrect flight data is being generated (potentially not correctly bailing on non-static data) causing navigation issues. 

Reverts #54403
2023-09-27 21:38:49 +00:00
Tim Neutkens
c59de31a9b
Ensure unique name for app dir css tests (#56088)
Ensures this and the other describe block in the codebase have unique
names so that they're reported separately.

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

-->
2023-09-27 18:38:01 +02:00
Tim Neutkens
633719e8cf
Skip Babel tests for Turbopack (#56091)
Follow-up to #56089, skips the Babel tests.

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

-->
2023-09-27 16:12:43 +02:00
Tim Neutkens
cbe8238ebd
Skip production tests for Turbopack (#56089)
Follow-up to #56045. Found there was a group of tests for production
called `server mode` instead of `production mode`, those are skipped too
now.

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

-->
2023-09-27 15:19:42 +02:00
Tim Neutkens
3eadfe925b
Skip experimental.nextScriptWorkers test for Turbopack (#56086)
This option is not supported in Turbopack yet but it is not a priority
as it's experimental.

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

-->
2023-09-27 13:58:11 +02:00
Tim Neutkens
f2ad08e2c8
Ensure tests suites have unique names (#56085)
Currently these share the same name which makes it hard to track down
which failed.

I think this was accidental based on the previous `pnpm new-test`
workflow.

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

-->
2023-09-27 13:55:45 +02:00
Tim Neutkens
646ae98d8d
Skip more production tests for turbopack (#56084)
Follow-up to #56045.

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

-->
2023-09-27 13:45:39 +02:00
Tobias Koppers
ef4faa5f9c
add flakey test (#56080)
It's flakey for turbopack

Closes WEB-1671

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2023-09-27 13:24:35 +02:00
Tobias Koppers
49176dad6b
Skip next build test (#56079)
Skipping another production test

Closes WEB-1670
2023-09-27 13:14:38 +02:00
Vũ Văn Dũng
9fd5b96e1f
Make permanentRedirect return 308 in route handlers (#56065)
### Why?

`permanentRedirect` currently still returns a 307 response if called inside a route handler

<img width="465" alt="image" src="https://github.com/vercel/next.js/assets/44609036/e0cddd37-0292-4865-a423-7bf11ad6beae">

This PR tries to fix that.

### How?

Make `handleTemporaryRedirectResponse` (now renamed `handleRedirectResponse`) accept a status value, then `getRedirectStatusCodeFromError` is used to retrieve that status (307 or 308).
2023-09-27 10:28:30 +00:00
Tobias Koppers
80635d8a60
fix reporting of illegal segments when directory only contains irrelevant files (#56076)
### What?

fixes

```
[Error: Invalid segment components, catch all segment must be the last segment

Debug info:
- Execution of directory_tree_to_entrypoints_internal failed
- Invalid segment components, catch all segment must be the last segment] {
  code: 'GenericFailure'
}
```


Closes WEB-1668
2023-09-27 10:04:10 +00:00
Justin Ridgewell
00d9080da5
turbopack: Add more skipped tests (#56052)
Adds more flakey tests to the skipped turbopack list.

Closes WEB-1662
2023-09-26 22:45:44 +00:00
JJ Kasper
b596de89d3
Fix invalid build-and-test workflow (#56053)
x-ref: https://vercel.slack.com/archives/C04KC8A53T7/p1695763819725649
2023-09-26 14:45:49 -07:00
Tim Neutkens
a961ec0d5f
Skip production tests for Turbopack (#56045)
As Turbopack is only focusing on dev currently. 

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

-->
2023-09-26 22:30:04 +02:00
Tobias Koppers
493036dfb9
turbopack: improve turbopack/test stability (#56024)
### What?

a few cherry picked fixes to test execution, issue reporting and hmr
behavior

### Why?

### How?


Closes WEB-1657
2023-09-26 20:32:54 +02:00
Jiachi Liu
4a6319cd86
Respect the original exported route segment config for sitemap (#56007)
Re-export the original route segment config in metadata routes loader, so they can be picked up by app route module wrapper

Closes #54057
Closes NEXT-1645
2023-09-26 17:04:58 +00:00
Tobias Koppers
ec9a87afd8
fix test case (#56034)
### What?

moving the production test case broke it


Closes WEB-1660

Co-authored-by: Jiachi Liu <inbox@huozhi.im>
2023-09-26 18:41:46 +02:00
Tobias Koppers
89c5fdf1e9
Turbopack: update test manifest (#56026)
Update from daily test run

also enabled a lot more tests

marked some tests flakey

Closes WEB-1658
2023-09-26 18:28:48 +02:00
Shu Ding
ed38f03e46
Fix barrel optimizer conflicts with client entry module (#56020)
The barrel optimization loader creates a virtual module to re-export
from the original file, which causes the situation that now there are 2
modules with the same resource but only one of them is the actual code.

When the code contains `"use client"`, the Flight plugin has to collect
its `buildInfo` and generate the manifest and client entry module.
However, we currently deduplicate module by resource in the traversal
logic to avoid unnecessary loops. To make it work together with the
virtual barrel module, we'll need to prefix the resource path to make it
different from the original module.

Closes #54967.
Closes #55609.
Closes #55566.
2023-09-26 18:03:51 +02:00
Shu Ding
4e44598249
Progressive enhancement for form state (#55584)
This PR implements progressive enhancement for `useFormState`:
1. Inline the form state in `__next_f` and use it for hydration.
2. Encode the new form state based on the action return value, and pass
it to Flight/Fizz.

Also fixed a problem caused by inconsistent React tree structure between
static-generation and non-static-generation.
2023-09-26 18:03:31 +02:00
Justin Ridgewell
efd6b682b8
turbopack: only skip known flakey test cases (#55976)
### What?

A follow up to https://github.com/vercel/next.js/pull/55975, this will
list every flakey test in the turbopack suite so that we can run the
remaining passing tests.

### Why?

More tests is more better.

### How?

Trial and error. Gonna let CI tell me what's flakey with a few runs.

Closes WEB-1651
2023-09-26 16:58:34 +02:00
Tim Neutkens
73a6374de2
Move test/integration/production to test/production (#55981)
Moves `test/integration/production` to
`test/production/pages-dir/production` to leverage test isolation,
useful for when Turbopack runs for the test.

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

-->
2023-09-26 15:38:50 +02:00
Tim Neutkens
5f03a7129a
Move SRI test into separate suite (#56015)
Moves the experimental.sri config test into a separate test suite.

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

-->
2023-09-26 15:34:34 +02:00
Zack Tanner
df12508be2
use experimentalHttpsServer flag when determining image optimizer protocol (#55988)
Inferring the protocol from the request meta is not reliable when the next server is running over `http` but sitting behind an https proxy. This instead plumbs the experimental https flag through to the optimizer so we can more reliably determine the protocol

Fixes #55971
2023-09-26 05:35:06 +00:00
OJ Kwon
123811719f
fix(turbopack): coerce importsource for emotion (#55986)
### What?

This PR fixes import source for turbopack's compiler.emotion config, mimics the current webpack configuration behavior.

Unfortunately this does not fixes the whole emotion transform with appdir yet, it looks like there are additional problems with server components.

Closes WEB-1655
2023-09-26 01:29:32 +00:00
JJ Kasper
57bb52d37d
Fix stale revalidate stream handling (#55978)
This ensures we don't block sending the stream down when handling stale revalidates, in edge runtime we leverage the existing `waitUntil` handling and in node.js runtime we couple this into our pipe readable handling to wait to close the writable until after the promise resolves. 

x-ref: https://github.com/vercel/next.js/issues/54193
2023-09-25 20:50:00 +00:00
Tim Neutkens
60af1969c5
Remove .test.js from dist (#55946)
Noticed a couple of directories had unit tests in `dist` which are being
run and reported during the Turbopack runs. These are generally quite
small so I'm not expecting this to have much effect on the package size
or CI runs, just making sure the data is correct.
<!-- 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 #

-->
2023-09-25 19:05:07 +02:00
Jimmy Lai
ca57258dbd
app router: ensure static prefetch renders loading.js (#55950)
Should fix the problem surfaced in https://github.com/vercel/next.js/issues/43548#issuecomment-1732416492 

The scenario in which this breaks is when we're asking the app renderer to generate a prefetch payload statically. The renderer was not checking if there were loading.js below the current rendering level, which is the root when statically rendering, so it would always render null, which was incorrect.

Tested out with the original repro  https://next-instant-loading-8nv6psqod-feedthejim.vercel.app
2023-09-25 12:59:31 +00:00
Tim Neutkens
cae7833af4
Ensure Turbopack passing test list is sorted (#55948)
I noticed that running the script to pull in the results wasn't
deterministic between test runs, this ensures the list, passing,
pending, and errors are all sorted, which makes the diff only include
what actually changed between runs.

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

-->
2023-09-25 12:59:26 +02:00
Jiachi Liu
a63b89b140
Loose types of app routes return value (#55849)
### What

#51394 introduced a pretty strict type of return value of route type
that causing failure with `next build`.
There're few ways of writing a app route, it could contain few return
values based on the usage:

* return a `Response` or promise of it
* return `NextResponse` of promise of it, since it's extended from
`Response`, same type
* use `redirect()` or `notFound(), since it returns `never`, and the
below code is not reached, the handler itself could still return void.
e.g. using `redirect` in a `GET` route

We loosed the type so `redirect()` can be still allowed without
specifying the return value there.
Related typescript issue:
https://github.com/microsoft/TypeScript/issues/16608#issuecomment-309327984

### How
* Re-enable the bail on types / build error in the app-routes tests
* Separate the tests, move runtime erroring ones to
`test/e2e/app-dir/app-routes-errors`
* Add new case to app-routes tests of mixed return value

Closes #55623 
Related #55604
2023-09-25 11:34:21 +02:00
Tim Neutkens
ea148f3581
Move client-navigation test to test/development (#55888)
Moves the client-navigation test suite to be isolated as part of
test/development.
Tried to make the minimal amount of changes neccesary to ensure the
tests pass first before using the newer `NextInstance` methods.

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

-->
2023-09-24 11:38:53 +02:00
Jiachi Liu
2248cfc044
test: re-enabled the disabled manifest test (#55810)
Re-enable the disabled test
2023-09-23 17:57:08 +00:00
Zack Tanner
c2e0213fa5
fix bugs pertaining to server actions + navigation (#55853)
This fixes some scenarios where executing a server action after navigation can cause the action to behave incorrectly (double submitting, not resolving). There are two separate issues:

- `canonicalUrl` and `pendingNavigatePath` were not constructed using the same function (`createHrefFromUrl`) so in certain situations they'd be comparing different values
- a fulfilled inFlightServerAction should not be invoked again

Closes NEXT-1655
Closes NEXT-1654
Fixes #55845
Fixes #55814
Fixes #55805
2023-09-23 01:42:39 +00:00
Justin Ridgewell
b0aecccaa2
Allow filtering individual test cases inside test files (#55786)
### What?

Updates `run-test.js` to allow running individual test cases inside a test file.

### Why?

So that we can dramatically increase Turbopack's test coverage. Turbopack has implemented most (but not all) necessary features from the webpack bundles. But a single failing test case would prevent us from running any case inside a test file. With case filtering, we're able to run the cases we know will pass and prevent regressions on those.

### How?

Case filtering is only exposed via the `NEXT_EXTERNAL_TESTS_FILTERS` ENV, which points to a JSON file containing a map of test files with the test cases inside those files that are known to pass.

The known-passing test cases can be updated after Turbopack's daily integration test run by running `test/build-turbopack-tests-manifest.js`, which will update the `test/turbopack-tests-manifest.json` manifest.

Closes WEB-1640

Co-authored-by: Tobias Koppers <1365881+sokra@users.noreply.github.com>
2023-09-22 21:37:48 +00:00
JJ Kasper
2cc30fc87a
Update flakey next-image tests (#55838)
x-ref: https://github.com/vercel/next.js/actions/runs/6277156082/job/17048498592
x-ref: https://github.com/vercel/next.js/actions/runs/6277508886/job/17049437197
2023-09-22 18:29:51 +00:00
OJ Kwon
2df7cf6020
feat(turbopack): construct output path with distDir next.js config (#55613)
### What?

This PR enables basic support for next.config.js's `distDir` config. PR have two main pieces, one for honoring distDir and construct output path other than `.next`, and secondly assign `process.env.__NEXT_DIST_DIR` to client / edge. The latter increased size of PR bit as had to downstream to the compile_define calls.

Corresponding tests are enabled to verify its behavior.

Closes WEB-1610
2023-09-22 18:07:03 +00:00
Tim Neutkens
dca5e22384
Remove legacy checks for unstable_getXProps (#55813)
These methods have been landed for multiple years now, it's fine to remove the legacy checks for `unstable_`.
2023-09-22 17:22:06 +00:00
Tim Neutkens
6177f9f9c3
Move DefineEnv to separate file (#55811)
Narrowing down the webpack config a bit.

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

-->
2023-09-22 19:07:52 +02:00
Zack Tanner
f20728ac3d
fix Image when used with --experimental-https (#55775)
The IPC request to `imageOptimizer` assumed the server was listening on http, so this updates it to pull the protocol from `getRequestMeta` instead. This also adds the option to pass in a path to the CA Root so that the dev server can add it to `NODE_EXTRA_CA_CERTS`


Closes NEXT-1646
Fixes #55706
2023-09-22 14:26:20 +00:00
OJ Kwon
4484ef1106
test(turbopack): explicitly clean up instance for turbopack (#55772)
### What?

Minor improvement to test fixture to clean up the instance if explicitly specified to continue test. This is required to run turbopack related tests.

Closes WEB-1634
2023-09-21 23:50:13 +00:00
OJ Kwon
4e877c01ba
test(fixture): prevent start failure teardowns whole process (#55760)
### What?

In some test failures we've been observing test result is not written at
all like


```
Failed to load test output [Error: ENOENT: no such file or directory, open 'test/e2e/app-dir/edge-runtime-node-compatibility/edge-runtime-node-compatibility.test.ts.results.json'] {
  errno: -2,
  code: 'ENOENT',
  syscall: 'open',
  path: 'test/e2e/app-dir/edge-runtime-node-compatibility/edge-runtime-node-compatibility.test.ts.results.json'
}
```

scrolling up, it was due to whole test process was taken down by calling
process.exit explicitly.

We want to collect test results for the failures still, so the PR amends
it for the cases if it's specified to continue on error.


Closes WEB-1628
2023-09-21 21:46:15 +02:00
Vũ Văn Dũng
a680571d04
Remove the left padding in next info output (#55704)
## Why?

Although the left padding makes the output looks good in the terminal, it causes this weird alignment in almost all bug reports:

```yaml
Operating System:
      Platform: win32
      Arch: x64
      Version: Windows 10 Pro
    Binaries:
      Node: 18.12.0
      npm: N/A
      Yarn: N/A
      pnpm: N/A
    Relevant Packages:
      next: 13.5.2-canary.2
      eslint-config-next: 13.5.2
      react: 18.2.0
      react-dom: 18.2.0
      typescript: 5.2.2
    Next.js Config:
      output: N/A
```

If I want it to look nice in the bug report

```yaml
Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 23.0.0: Thu Aug 17 21:23:02 PDT 2023; root:xnu-10002.1.11~3/RELEASE_ARM64_T8112
Binaries:
  Node: 20.3.1
  npm: 9.6.7
  Yarn: 1.22.19
  pnpm: 8.6.12
Relevant Packages:
  next: 13.5.2
  eslint-config-next: N/A
  react: 18.2.0
  react-dom: 18.2.0
  typescript: 5.2.2
Next.js Config:
  output: N/A
```

I have to paste this to a text editor and manually remove the first four spaces on every lines.

### How?

This PR removes that four-space padding to make future bug reports look a bit nicer.
2023-09-21 18:26:43 +00:00
Balázs Orbán
bca6ff77f9
fix(cna): separate dependencies/devDependencies (#55730)
### What?

As [discussed](https://vercel.slack.com/archives/C04DUD7EB1B/p1692183798097169), we should follow the ecosystem standard separation of dependencies and dev dependencies.

### Why?

This is a common issue/misunderstanding that we always have to explain separately, while there is no real benefit.

One counter-argument was that install times would be increased when we had to run install for `dependencies` and `devDependencies` separately, but that's easy to work around as explained below.

### How?

Instead of passing the `dependencies` array to the package manager in the CLI, we write these to the `package.json` file and then run the package manager's install command without the dependency arguments.

This will also reduce the number of writes to the `package.json` file from two to just one.

Ref: https://github.com/vercel/next.js/pull/42218, https://github.com/vercel/next.js/pull/48076, https://github.com/vercel/next.js/issues/54105, https://github.com/vercel/next.js/pull/42012, and more

[Slack thread](https://vercel.slack.com/archives/C04DUD7EB1B/p1692183798097169)


Co-authored-by: Steven <229881+styfle@users.noreply.github.com>
2023-09-21 15:30:37 +00:00
OJ Kwon
b811240602
ci(tests): enable turbopack /e2e tests (#55681)
### What?

Closes WEB-1615

I thought I couldn't grab the correct count of test suite in the datadog
as I was seeing huge count mismatches. Actually, it was because we were
not running all of the tests.

PR amends

- run all the tests under manifests
- ensure all the test list in the manifest actually exists

lastly and sadly
- disable few tests too flaky
2023-09-21 08:14:29 +02:00
Wyatt Johnson
a88e9953b9
Split prerending by route kind (#55622)
In order to support updates to the prerendering pipelines, this breaks out some of the prerendering
code into discrete chunks importable for each route kind rather than them all sharing the same
function.

Some small optimizations were made, namely some matcher memoization (only the last one) that should
help with large builds locally.
2023-09-20 21:25:21 +00:00
Jiachi Liu
f5bef049f5
Polish error icon for error log (#55618)
### After 💅 

<img width="109" alt="image" src="https://github.com/vercel/next.js/assets/4800338/f90d15a1-ac6e-4fe1-8241-d9e40e9d2e0e">

 ### Before 

<img width="143" alt="image" src="https://github.com/vercel/next.js/assets/4800338/fbc09a29-cac2-459d-8a96-d1a5948947cc">
2023-09-20 14:56:34 +00:00
Jiachi Liu
d97af317a3
Fix header resent when error occured (#55619)
When errors are thrown in middleware it could re-send headers for the same response

```
Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
    at __node_internal_captureLargerStackTrace (node:internal/errors:490:5)
    at new NodeError (node:internal/errors:399:5)
    at ServerResponse.setHeader (node:_http_outgoing:645:11)
    at origSetHeader (/next.js/packages/next/src/server/base-server.ts:777:16)
    at ServerResponse._res.setHeader (/next.js/packages/next/src/server/base-s
erver.ts:777:16)
    at setHeader (/next.js/packages/next/src/server/base-http/node.ts:84:15)
    at renderErrorImpl (/next.js/packages/next/src/server/base-server.ts:2790:
11)
    at <anonymous> (/next.js/packages/next/src/server/base-server.ts:2777:19)
    at trace (/next.js/packages/next/src/server/lib/trace/tracer.ts:213:14)
    at DevServer.renderError (/next.js/packages/next/src/server/base-server.ts
:2776:24)
    at DevServer.renderError (/next.js/packages/next/src/server/next-server.ts
:1299:18)
    at DevServer.handleRequestImpl (/next.js/packages/next/src/server/base-ser
ver.ts:1185:23) {
  code: 'ERR_HTTP_HEADERS_SENT'
}
```

Migrate middleware-errors test to e2e test to avoid flaky assertion due to duplicated logging collected in integration test.

Closes NEXT-1629
2023-09-20 13:22:16 +00:00
OJ Kwon
a429e04fec
test(turbopack) migrate api tests, few image tests (#55552)
### What?

PR migrates next-dev's api tests to use next.js integration tests, as well as enabling few more image tests.

Closes WEB-1599
2023-09-19 20:14:53 +00:00
Jiachi Liu
063154918c
Fix react packages are not bundled for metadata routes (#55579)
`isAppLayer` condition was missing `app-metadata-route` layer, made it
as a util now like other webpack layer utils, add metadata route layer
to the group. Then `React.cache` can be available there.

Also update regex to be compatible across platform

Fixes #55561 
Closes NEXT-1635
2023-09-19 15:45:59 +02:00
Zack Tanner
33c561b21d
Consolidate experimental React opt-in & add ppr flag (#55560)
This consolidates how we're evaluating when to opt into `react@experimental` since it's sprinkled in a lot of spots. Also adds a new flag to opt into the experimental channel

Closes NEXT-1632
2023-09-19 10:45:25 +00:00
Jiachi Liu
7fe01bb639
Disable client-only for middleware and pages api layer (#55541)
We need to disable the default treat `middleware` and `pages/api` as
server-only, unless users explictly import "server-only" to poison it.

This will avoid the case that when a library is mixing "client-only" API
and shared components API in one bundle, and the shared API is used in
middleware or `pages/api` that might cause error. See the test case
added.

Follow up for #55394
2023-09-18 14:59:54 -05:00
JJ Kasper
9697bcd3c8
Fix notFound status code with ISR in app (#55542)
This ensures we properly set/restore the status code with ISR paths in
app router so that when we set the 404 status code with `notFound` it is
persisted properly.

Fixes: https://github.com/vercel/next.js/issues/43831
Closes: https://github.com/vercel/next.js/issues/48342
x-ref:
https://github.com/vercel/next.js/issues/49387#issuecomment-1722575969
2023-09-18 14:35:00 -05:00
OJ Kwon
4cc51d7d2f
test(turbopack): enable async storage tests (#55413)
### What?

Minor PR updates additional tests.


Closes WEB-1572
2023-09-18 18:10:10 +00:00
JJ Kasper
c628076e91
Disable flakey middleware-dev-error test (#55539)
x-ref: [slack
thread](https://vercel.slack.com/archives/C04DUD7EB1B/p1695039655548129)
2023-09-18 12:48:00 -05:00
OJ Kwon
1105501287
test(integration): fix --turbo tests fixture setup (#55293)
### What?

Update few test fixture setup doesn't invoke --turbo based on the conditions.

Closes WEB-1543
2023-09-18 17:46:07 +00:00
OJ Kwon
f393f55678
fix(next-core): enable image extensions (#55460)
### What?

Enables the image extensions supported by turbopack.

Also fixes test fixture to assert error overlay header.


Closes WEB-1587
2023-09-18 17:30:27 +00:00
Jiachi Liu
ff3668499a
Make useSearchParams and useParams compatible between app and pages router (#55280)
### `useSearchParams`

server router's query includes both search params and path params, this PR eliminate the path params from `useSearchParams` to make it aligned between app router and pages router

### `useParams`

For pages, we extract the params keys with `getRouteRegex`, and pick them out from `router.query`

Fixes #54242 
Closes NEXT-1536
2023-09-18 12:42:20 +00:00
Jiachi Liu
ffc0e54102
Allow server-only in server targets and client-only in client components targets to be available (#55394)
Users want to use `server-only` to restrict the middleware / app routes / pages api, but now it's failing as we're treating them as different webpack layers, but validating the `server-only` only with server components layers.

Here we modify the rules a bit to let everyone can use "server-only" for the bundles that targeting server-side.

For next-swc transformer, we introduce the new option `bundleType` which only has `"server" | "client" | "default"` 3 values:
* - `server`  for server-side targets, like server components, app routes, pages api, middleware
* - `client`   for client components targets such as client components app pages, or page routes under pages directory.
* - `default` for environment like jest, we don't validate module graph with swc, replaced the `disable_checks` introduced  [#54891](https://github.com/vercel/next.js/pull/54891).

Refactor a bit webpack-config to adapt to the new rules, after that `server-only` will be able to used in the server-side targets conventions like middleware and `pages/api`

Fixes #43700
Fixes #54549
Fixes #52833

Closes NEXT-1616
Closes NEXT-1607
Closes NEXT-1385
2023-09-18 12:27:45 +00:00
JJ Kasper
d1dabe4208
Remove esm loader (#55509)
Now that we are bundling the react runtime for app router we can remove
the esm loader as that was the reason it was added when bringing the
server back into a single process.

x-ref: https://github.com/vercel/next.js/pull/55362

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2023-09-18 11:22:01 +02:00
Andrew Clark
0bfd4801e4
Restrict useFormState in Server Components (#55417)
I based my changes on #49331, which did this for useFormStatus.

While I was editing the file, I noticed that useOptimistic was incorrectly categorized as a `react-dom` package export, but it's actually exported from `react`. So I fixed that, too.

Co-authored-by: Zack Tanner <1939140+ztanner@users.noreply.github.com>
2023-09-16 16:53:51 +00:00
Tim Neutkens
16886136f2
Skip JSON.parse in loadClientReferenceManifest (#55457)
While investigating the `next start` CPU profile noticed that this
function was called many times and that the JSON.parse happened for each
of them. This replaces that to no longer be needed and leverages the
require cache instead. The reason I didn't go for memoizing this
function is that it would add further complexity and potential for
leaking memory compared to the approach implemented in this PR.

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

-->
2023-09-16 12:33:34 +02:00
Jimmy Lai
bd705537a3
server: bundle vendored react (#55362)
## What

This PR changes Next.js to bundle its vendored React libraries so that the App Router pages can use those built-in versions.

## Why

Next.js supports both Pages and App Router and we've gone through a lot of iteration to make sure that Next.js stays flexible wrt to the version of React used: in Pages, we want to use the React provided by the user and in the App Router, to be able to use it, we need to use the canary version of React, which we've built into Next.js for convenience.

The problem stems from the fact that you can't run two different instances of React (by design).

Previously we have a dual worker setup, where we would separate completely each Next.js versions (App and Pages) so that they would not overlap with each other, however this approach was not great performance and memory wise.

We've recently tried using an ESM loader and a single process, but this change would still opt you into the React canary version if you had an app page, which breaks some assumptions.

## How

A list of the changes in this PR:

### New versions of the Next.js runtime

Since we now compile a runtime per type of page (app/route/api/pages), in order to bundle the two versions of React that we vendored, we introduced a new type of bundle suffixed by `-experimental`. This bundle will have the bleeding edge React needed for Server Actions and Next.js will opt you in into that runtime automatically.

For internal contributors, it means that we now run a compiler for 10 subparts of Next.js:
- next_bundle_server
- next_bundle_pages_prod
- next_bundle_pages_turbo
- next_bundle_pages_dev
- next_bundle_app_turbo_experimental
- next_bundle_app_prod
- next_bundle_app_prod_experimental
- next_bundle_app_turbo
- next_bundle_app_dev_experimental
- next_bundle_app_dev

![image](https://github.com/vercel/next.js/assets/11064311/f340417d-845e-45b9-8e86-5b287a295c82)

### Simplified require-hook

Since the versions of React are correctly re-routed at build time for app pages, we don't need the require hook anymore

### Turbopack changes

The bundling logic in Turbopack has been addressed to properly follow the new logic

### Changes to the shared contexts system

Some context files need to have a shared instance between the rendering runtime and the user code, like the one that powers the `next/image` component. In general, the aliasing setup takes care of that but we need the require hook for code that is not compiled to reroute to the correct runtime. This only happens for pages node_modules.

A new Turbopack resolving plugin has been added to handle that logic in Turbopack.

### Misc changes

- `runtime-config` (that powers `next/config`) has been converted to an `.external` file, as it should have been
- there are some rules that have been added to the aliases to support the usage of `react-dom/server` in a server-components. We can do that now since the runtime takes care of separating the versions of React.



Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
2023-09-15 19:49:39 +00:00
Leah
e191ae3a02
add test for turbopack refresh error (#55447)
Closes WEB-1584
2023-09-15 17:09:59 +00:00
Tobias Koppers
b3a916cab4
fix server-side changes events (#55437)
### What?

fix the problems that caused sideSideChanges to be emitted for client
side changes

### Why?

### How?


Closes WEB-1578
2023-09-15 17:57:01 +02:00
Zack Tanner
1e332532c7
fix manifest load errors when using assetPrefix (#55416)
### What?
`_devPagesManifest.json` and `_devMiddlewareManifest.json` will fail to load when using an asset prefix. In conjunction with i18n, this causes the app to get caught in an infinite load loop. 

### Why?
We're expecting these paths to be exact matches but when there's an assetPrefix specified, they won't be matched. 

### How?
This copies similar behavior to how we handle [`webpack-hmr`](2e2211d27b/packages/next/src/server/lib/router-server.ts (L681)) by doing a partial match on the URL when serving it

Closes NEXT-1618
Fixes #55389
2023-09-15 01:11:03 +00:00
Zack Tanner
a73abad609
fix: server actions initiated from static pages (#51534)
### What?
Pages marked with `generateStaticParams` don't currently support server actions, and instead return a 405 Method Not Allowed, with no action being taken on the client. Additionally, pages that are marked static & use server actions are opted into dynamic rendering.

### Why?
The page that has `generateStaticParams` is marked as `isSSG` [here](ee2ec3dd1d/packages/next/src/server/base-server.ts (L1337)).

As a result, the request is short-circuited because a POST request isn't supported on static pages. Upon detecting a server action on a page marked SSG, we bypass the static cache and go straight to the lambda. 

This PR introduces an experimental option to the prerender manifest that will allow for selectively bypassing the static cache

This also removes the need to bail out of static generation

Closes NEXT-1167
Closes NEXT-1453
Fixes #49408
Fixes #52840
Fixes #50932
2023-09-14 21:22:19 +00:00
Tim Neutkens
4385efac3b
Remove setLazyProp from the hot path of all requests (#55391)
Removes setLazyProp from the hot path when handling requests. Noticed in
the CPU profile that `Object.defineProperty` is not ideal so this
ensures it's only called where it's needed, which is in `pages`
rendering and `pages/api`.

Also added a test for `getServerSideProps` reading cookies, which is
supported but a test was missing.

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

-->
2023-09-14 22:34:51 +02:00
Andrew Clark
6f2e9aec21
Update React from dd480ef92 to d6dcad6a8. (#55399)
### React upstream changes:

- https://github.com/facebook/react/pull/27374
- https://github.com/facebook/react/pull/27369
- https://github.com/facebook/react/pull/27372
- https://github.com/facebook/react/pull/27371
- https://github.com/facebook/react/pull/27370
- https://github.com/facebook/react/pull/27321
- https://github.com/facebook/react/pull/27368
- https://github.com/facebook/react/pull/27367
- https://github.com/facebook/react/pull/27366
- https://github.com/facebook/react/pull/27360
- https://github.com/facebook/react/pull/27361
- https://github.com/facebook/react/pull/27357
- https://github.com/facebook/react/pull/27359
- https://github.com/facebook/react/pull/27358
- https://github.com/facebook/react/pull/27330
- https://github.com/facebook/react/pull/27347
- https://github.com/facebook/react/pull/27307
- https://github.com/facebook/react/pull/27346
- https://github.com/facebook/react/pull/27342
- https://github.com/facebook/react/pull/27340
- https://github.com/facebook/react/pull/27328
- https://github.com/facebook/react/pull/27327
- https://github.com/facebook/react/pull/27325
- https://github.com/facebook/react/pull/27337
- https://github.com/facebook/react/pull/27336
- https://github.com/facebook/react/pull/27323
- https://github.com/facebook/react/pull/27320
- https://github.com/facebook/react/pull/27317
- https://github.com/facebook/react/pull/27318
- https://github.com/facebook/react/pull/27316
- https://github.com/facebook/react/pull/27313
- https://github.com/facebook/react/pull/27309
- https://github.com/facebook/react/pull/27302
- https://github.com/facebook/react/pull/27297
- https://github.com/facebook/react/pull/27295
- https://github.com/facebook/react/pull/27305
- https://github.com/facebook/react/pull/27215
- https://github.com/facebook/react/pull/27304
- https://github.com/facebook/react/pull/27067
- https://github.com/facebook/react/pull/27179
- https://github.com/facebook/react/pull/27278
- https://github.com/facebook/react/pull/27277
- https://github.com/facebook/react/pull/27282
- https://github.com/facebook/react/pull/27230
- https://github.com/facebook/react/pull/27260
- https://github.com/facebook/react/pull/27270
- https://github.com/facebook/react/pull/27273
- https://github.com/facebook/react/pull/27268
- https://github.com/facebook/react/pull/27269
2023-09-14 17:42:33 +00:00
Wyatt Johnson
e23dac0cbf
fix: added support for tests to add resolutions for deps (#55398)
Some tests may depend on `latest` to help us catch problems earlier. This adds support for the `resolutions` field for tests to allow pinning of deps that may be problematic upstream.
2023-09-14 17:35:13 +00:00
Tobias Koppers
67bc262b67
Revert "Revert "feat(turbopack): support next.js specific node polyfills"" (#55392)
Reverts vercel/next.js#55385

Closes WEB-1565
2023-09-14 17:32:29 +02:00
Tobias Koppers
129f56d3e7
more turbopack HMR fixes and test case (#55368)
### What?

improve test case to check HMR
reenable deduplication for server side hmr events
add aggregation of client side HMR events

### Turbopack Changes

* https://github.com/vercel/turbo/pull/5936 <!-- Will Binns-Smith -
Update http mock and clap -->
* https://github.com/vercel/turbo/pull/5948 <!-- Tobias Koppers - CSS
HMR fixes -->



Closes WEB-1557

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2023-09-14 15:50:59 +02:00
Tobias Koppers
9953db4a30
Revert "feat(turbopack): support next.js specific node polyfills" (#55385)
Reverts vercel/next.js#55343

Closes WEB-1562

it fails CI with:

```
  ● node builtins › should support node.js builtins in server component
  
      SyntaxError: Unexpected end of JSON input
          at JSON.parse (<anonymous>)
  
        124 |
        125 |       const data = $('#node-browser-polyfills').text()
      > 126 |       const parsedData = JSON.parse(data)
            |                               ^
        127 |
        128 |       expect(parsedData.vm).toBe(105)
        129 |       expect(parsedData.hash).toBe(
  
        at Object.<anonymous> (development/basic/node-builtins.test.ts:126:31)
  
    ● node builtins › should support node.js builtins prefixed by node: in server component
  
      SyntaxError: Unexpected end of JSON input
          at JSON.parse (<anonymous>)
  
        149 |
        150 |       const data = $('#node-browser-polyfills').text()
      > 151 |       const parsedData = JSON.parse(data)
            |                               ^
        152 |
        153 |       expect(parsedData.vm).toBe(105)
        154 |       expect(parsedData.hash).toBe(
  
        at Object.<anonymous> (development/basic/node-builtins.test.ts:151:31)
  
  ```
  
  @kwonoj
2023-09-14 15:16:33 +02:00
OJ Kwon
e8adcd8527
feat(turbopack): support next.js specific node polyfills (#55343)
- feat(turbopack): support next.js specific node polyfills
- test(turbopack): migrate polyfill tests

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



### Why?

### How?

Closes NEXT-
Fixes #

-->

### What?

This PR fulfills gap for the node.js polyfill between next.js to
turbopack, then enable corresponding integration tests.


Closes WEB-1552
2023-09-14 14:52:16 +02:00
Ngô Đức Anh
f2f582c17f
Fix network URL logging in start-server (#55260)
### What?
Follow-up of #54926.
While that PR's main fix is no longer necessary due to the removal of render workers, I figure that some changes are nice-to-have and have isolated them into this PR. This includes fixing `appUrl` and `networkUrl` in `start-server`, fixing docs and removing some unnecessary template literals in `turbopack-warning`.

### How?
`appUrl` now tries to use `hostname` instead of `actualHostname` (an address like `example.com` seems to be more useful here than an IP like `xxx.xxx.xxx.xxx`), and `networkUrl` is now prefixed with `http://`.

Other simple changes include fixing docs.



Co-authored-by: Zack Tanner <1939140+ztanner@users.noreply.github.com>
2023-09-14 02:01:26 +00:00
Jiachi Liu
b3e95edab4
Warn experimental.appDir option can be removed (#55346)
We have dropped `experimental.appDir` option, to share the insights that can be removed, add a warning `"App router is enabled by default now, <experimental.appDir> option can be safely removed.'" `
2023-09-13 23:38:17 +00:00
Jiachi Liu
14e94e69c5
fix duplicated error logging when start server (#55328)
There're few places calling `loadConfig` to access nextjs config for different purpose, and every of them will do validation of next config scheme and could log the warnings potentially to cause duplicated warnings. To address that issue this PR limit the places when should the warnings be logged in certain places, mainly the `next` command entry. Refactor the API here to make it more explicit

Previous logging redeisgn also might trigger duplicated compilation, for instance you compiled page A but then editing another component it might still displaying page A is recompiled. Now we always display `"Compiled .."` message when there's a recompilation but avoid the unnecessary ones such as initial edge compilor ready but there's no modules inside. Then when it recompiles or recovers from error nextjs server will tell "Compiled .." instead of the specific page which might be not related.

Also refactors a minor issue: When `silent` option is set to `true`, auto recorrect next config option from `loadConfig` API like `traillingSlash` is not working

Closes NEXT-1610

Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
2023-09-13 22:25:41 +00:00
Michael Novotny
fe797c1074
Updates Mozilla links to not include language preference (#55326)
Internal suggestion to remove `en-US` from Mozilla urls since MDN is
available in multiple languages nowadays it will automatically redirect
to the viewer’s language preference.

Closes
[DX-2076](https://linear.app/vercel/issue/DX-2076/make-external-mozilla-links-language-agnostic-in-nextjs-docs)
2023-09-13 11:06:29 -05:00
Jiachi Liu
083f49c247
Logging improvements (#55298)
## Logging Improvements

* Delay server start logging
Post start logging after request handler is created, so when error
occurred like missing "app" or "pages" directory it won't log start
server message, instead it will only show error message.

* Fix jsconfig hmr case
Previously the `jsconfig.json` is patched too early that didn't trigger
the hmr reload, this PR enables it to show on the

* Adding timestamp for "ready" event
Display a timesmap after "ready" message, so we can monitor how long
does it take, and keep perfing on it

* Polish logging format
  * Starts with captital letter
  * align the indentation


![image](https://github.com/vercel/next.js/assets/4800338/fb87e0c4-3965-48da-86ef-a178e77d83f2)
2023-09-13 15:27:02 +02:00
Jiachi Liu
85d30b62db
Remove unused option and unified ready message into start server (#55289)
Remove the `logReady` optional option introduced in #52492, never being passdown but alwasy `true` by default.
2023-09-12 20:29:32 +00:00
OJ Kwon
0bf5cbb901
feat(next-dev): reenable turbopack beta message (#55116)
### What?
Minor PR brings back turbopack beta message. We'll need to improve the actual checks per progress, but that might need auditing what's working vs not later.


Closes WEB-1517
2023-09-12 16:39:26 +00:00
Jimmy Lai
f4e6dea1f2
build: fix externals resolution when importing from next/dist (#55269)
This fixes a "bug" where Sentry was trying to access some of the internal async storages and it would fail because their imports would be compiled as-is instead of using the special rules for Next externals as we are short-cutting it for `next/dist` requests for some reason.

Not a bug per se because this is technically an undocumented API but I think it's a reasonable fix since we don't provide an API for that. The alternative for them would be to try to play around with the bundling, which is not a good use of anyone's time.
2023-09-12 10:26:34 +00:00
Nick Olinger
3afba0d12d
feat: add reserved port validation (#55237)
### Fixing a bug

- [x] Related issues linked using `fixes #number`
- [x] Tests added. See: https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- [x] Errors have a helpful link attached, see https://github.com/vercel/next.js/blob/canary/contributing.md

Closes NEXT-
Fixes #55050 


Co-authored-by: Steven <229881+styfle@users.noreply.github.com>
Co-authored-by: Tim Neutkens <6324199+timneutkens@users.noreply.github.com>
2023-09-12 07:31:35 +00:00
OJ Kwon
92e1b3fef9
test(fixture): improve finding ports to reduce flaky (#55151)
### What

Found a flaky test like https://github.com/vercel/next.js/actions/runs/6125719281/job/16628276301?pr=55118#step:29:174, `get-port` throws by port is not available. Peeking bit, there seems an upstream fix hope to improve the situation but unfortunately it happened after get-port switched to native esm only, so bumping is non trivial work. Instead adapting get-port-please as a replacwement but leave get-port as fallback for a while to verify its stability. Once we are certain, we can remove old get-port entirely.
2023-09-11 21:48:29 +00:00
OJ Kwon
ddc26c9904
test(turbopack): migrate 404-related tests from next-dev (#55243)
Closes WEB-1535
2023-09-11 21:16:51 +00:00
JJ Kasper
7d93808c43
Remove render workers in favor of esm loader (#54813)
Currently we create separate workers to isolate `pages` and `app`
routers due to differing react versions being used between the two. This
adds overhead and complexity in the rendering process which we can avoid
by leveraging an `esm-loader` similar to our `require-hook` to properly
alias `pages` router to the bundled react version to match `app` router
when both are leveraged together.

This aims to seamlessly inject the `esm-loader` by restarting the
process with the loader arg added whenever `next` is imported so that
this also works with custom-servers and fixes the issue with custom
req/res fields not working after upgrading.


x-ref: https://github.com/vercel/next.js/issues/53883
x-ref: https://github.com/vercel/next.js/issues/54288
x-ref: https://github.com/vercel/next.js/issues/54129
x-ref: https://github.com/vercel/next.js/issues/54435
closes: https://github.com/vercel/next.js/issues/54440
closes: https://github.com/vercel/next.js/issues/52702
x-ref: [slack
thread](https://vercel.slack.com/archives/C03KAR5DCKC/p1693348443932499?thread_ts=1693275196.347509&cid=C03KAR5DCKC)

---------

Co-authored-by: Tim Neutkens <tim@timneutkens.nl>
Co-authored-by: Zack Tanner <zacktanner@gmail.com>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2023-09-11 22:17:52 +02:00
OJ Kwon
360142d409
tests(next-dev): migrate basic tailwind tests for turbopack (#55118)
Closes WEB-1518

### What?

This PR refactors test cases from next-dev, tests basic tailwind rendering with turbopack. It still runs against plain next.js too. While checking, noticed there's a stub fixture (css-fixture/with-tailwindcss) but those fixture seems not being used in the test. Moved those and utilized. Since this test runs against next.js / turbopack both anyway, moving fixture should not be a huge regression I believe.
2023-09-11 15:44:39 +00:00
OJ Kwon
40da1aeb92
test(nexttestsetup): teardown nextinstance gracefully (#55144)
### What?

https://vercel.slack.com/archives/C04KC8A53T7/p1694190462958199

I realized we throws an error attempt to destory against undefined instance when `beforeAll` fails in any reason. This is quite redundant error since if next instance doesn't exist, likely there's an upstream test failures already and destory against undefined error is not useful to debug anyway.

PR replaces `nextTestSetup`'s teardown first, for the remaining places calling `next.destory` explicitly will be amended later.
2023-09-11 15:29:49 +00:00
Leah
6e3ef5b01c
feat: support expanding urls in nexturbo (and fix static files) (#55147)
Closes WEB-1525
2023-09-08 21:35:33 +00:00
Will Binns-Smith
8f30255922
Revert swc versions to one that doesn't use lightningcss (#55148)
Using lightningcss results in a breaking change to Next.js, so let's revert swc for now.


Closes WEB-1526
2023-09-08 20:02:51 +00:00
Tobias Koppers
f569cb1316
enable all passing turbopack tests for CI (#55100)
Closes WEB-1514

Co-authored-by: OJ Kwon <1210596+kwonoj@users.noreply.github.com>
2023-09-08 17:30:07 +00:00
Jimmy Lai
5217e7eb06
server: re-land bundled runtimes (#55139)
see https://github.com/vercel/next.js/pull/52997

also added a fix by @jridgewell to fix turbopack





Co-authored-by: Justin Ridgewell <112982+jridgewell@users.noreply.github.com>
2023-09-08 16:05:29 +00:00