Commit graph

16486 commits

Author SHA1 Message Date
JJ Kasper
dd0a9d033c
Revert "Update eslint-plugin-react-hooks to 5.0.0-canary-7118f5dd7-20230705" (#52272)
Reverts vercel/next.js#52268

x-ref: [slack
thread](https://vercel.slack.com/archives/C04DUD7EB1B/p1688573457803739)
2023-07-05 10:21:19 -07:00
Justin Ridgewell
ff1f75a873
Fix stream cancellation in RenderResult.pipe() and sendResponse() (#52157)
### What?

I've found 2 more spots that didn't properly cancel the streaming response when the client disconnects. This fixes `RenderResult.pipe()` (called during dynamic render results) and `sendResponse()` (used during Route Handlers using `nodejs` runtime).

It also (finally) adds tests for all the cases I'm aware of.

### Why?

To allow disconnecting from an AI service when a client disconnects. $$$

### How?

Just checks for `response.closed`, which will be closed when the client's connection disconnects.
2023-07-05 17:15:48 +00:00
Andrew Clark
9049c0f275
Update eslint-plugin-react-hooks to 5.0.0-canary-7118f5dd7-20230705 (#52268)
5.0.0-canary-7118f5dd7-20230705 includes a new [lint error for hook calls inside an async component](7118f5dd7b), a common mistake when refactoring Server Components to Client Components, or vice versa.

This updates the dependency in eslint-config-next.
2023-07-05 16:07:22 +00:00
Shu Ding
a8d09d73c1
Fix small memory leaks (#52257)
Fix a few KBs (depending on the tree state size) of leaked memory caused by closures. All the marked objects below are caused by `serverActionDispatcher` which are not cleaned up after SSR:

![CleanShot 2023-07-05 at 15 15 17@2x](https://github.com/vercel/next.js/assets/3676859/d6731830-146e-4433-9ab7-19ea878472cf)
2023-07-05 15:40:12 +00:00
OJ Kwon
6885b98d35
feat(turbopack): add crypto polyfill (#51622)
### What?

PR attempts to fix WEB-1214, provides a polyfill to globalThis.crypto.
2023-07-05 14:38:34 +00:00
Delba de Oliveira
44d1a1cb15
docs: Migrate error messages to MDX and App Router. (#52038)
This PR is part of a larger effort to migrate error messages to MDX and
use App Router: https://github.com/vercel/front/pull/23459
2023-07-05 06:11:16 -07:00
Jan Nicklas
394533ff88
next-flight-css-loader - fix !=! support (#51115)
<!-- 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

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

- Use a `cssModules` option to configure the `next-flight-css-loader.ts`
based on the match resource.
- Added types
- Ran prettier

### Why?

NextJs supports css modules and global css files.
The `next-flight-css-loader.ts` is capable of dealing with both formats.

However under the hood the loader shares almost no code for css modules
and global css files.
To branch into the correct behaviour the `next-flight-css-loader.ts`
checks the extension of the file using
`this.resourcePath.match(/\.module\.(css|sass|scss)$/)`.

`this.resourcePath` does not include the information from webpacks `!=!`
import syntax.

One solution would be to use `this._module.matchResource` instead of
`this.resourcePath`.
But imho passing it from the webpack.config.js instead of duplicating
the css module file regexp felt cleaner.

### Further questions

- Should we update the loader banner comment?
- Can we drop `this.data.__checksum` in the pitch loader function for
css modules? (it would speed up css modules and for me it looks like it
isn't needed anymore for css modules because of
2eeb0c7f49
(4. April by @shuding)
- Should we split the loader into two loaders?

Fixes #52208

---------

Co-authored-by: Shu Ding <g@shud.in>
2023-07-05 14:37:20 +02:00
Shu Ding
13e769a301
Improve error message when using per function "use server" in Client Components (#52214)
The current message isn't very clear about `"use server" function` and
`"use server" file`, and there's no link to docs to explain it further:

```
"use server" functions are not allowed in client components. 
You can import them from a "use server" file instead.
```

This PR makes it a bit more verbose:

```
It is not allowed to define inline "use server" annotated Server Actions in Client Components.
You can either mark the entire file by putting "use server" at the top, or pass them down through props from a Server Component.

Read more: https://nextjs.org/docs/app/building-your-application/data-fetching/server-actions#with-client-components
```
2023-07-05 14:34:36 +02:00
Shu Ding
ef89890f56
Ensure Webpack isn't loaded in render workers (#52241)
There's no need to require the HotLoader module as well as Webpack in render workers, as we are not running compilation there. This reduces 10 MB memory in total and some time from `require`ing Webpack.

Before:

<img width="1639" alt="CleanShot 2023-07-05 at 11 33 39@2x" src="https://github.com/vercel/next.js/assets/3676859/48f31051-7a27-4cf6-94aa-1b2ddf313f20">

After:

<img width="1639" alt="CleanShot 2023-07-05 at 12 02 04@2x" src="https://github.com/vercel/next.js/assets/3676859/4c717d75-c0cd-458f-a6c9-6f967ae6df90">
2023-07-05 12:09:25 +00:00
Jiachi Liu
baf3d2fa8a
Fix title crashing while post processing metadata (#52196)
Fixes #52191

Resolved `twitter?.title` could be `null`, adding optional chain to access it
2023-07-05 11:05:33 +00:00
vercel-release-bot
0b470753b7 v13.4.9-canary.2 2023-07-05 10:26:56 +00:00
Tim Neutkens
b2bf446762
Optimize watch ignore (#52238)
## What?

Uses a pre-created regex instead of having webpack run path-to-regexp on the list of patterns. Saves a few milliseconds.
Adds `node_modules` to ignored in order to skip a lot of stat calls at the end of the compilation.

This will likely have a big impact on applications using Yarn PnP as each stat call causes a lookup through `.pnp.cjs`.
2023-07-05 10:18:13 +00:00
Simon Vrachliotis
972d29b6d5
Update generate-image-metadata.mdx (#52230)
I read the PR checklist, but this is such a small PR that I feel it's
self-explanatory.

I believe the wrong function name (`generateMetadata`) is used on this
page, and it was meant to be `generateImageMetadata`.

If not... apologies 😅
2023-07-05 09:23:14 +02:00
Jiachi Liu
003f7dd6f8
Remove zod from require-hook (#52197)
Remove the unnecessary added require hook
2023-07-05 04:22:28 +00:00
Tobias Koppers
fd508b086c
fix env reloading for turbopack (#52194)
### What?

fixes WEB-1258
2023-07-04 19:28:34 +00:00
Shu Ding
8aa9a52c36
Fix tree shaking for image generation module (#51950)
### Issue

When the og module is a shared module being imported in both page and metadata image routes, it will be shared in the module graph. Especially in the edge runtime, since the `default` export is being used in the metadata image routes, then it can't be easily tree-shaked out.

### Solution

Separate the image route to a separate layer which won't share modules with the page, so that image route is always bundling separately and the `@vercel/og` module only stays inside in that layer, when import image metadata named exports (size / alt / etc..) it can be still tree shaked.

Co-authored-by: Jiachi Liu <4800338+huozhi@users.noreply.github.com>
2023-07-04 18:19:08 +00:00
Shu Ding
9bd5169dcd
Fix dynamicParams check in TS plugin (#52211)
Add the missing `isValid` check.

Fix NEXT-1214, fix #49489.
2023-07-04 17:31:01 +00:00
Shu Ding
220377e381
Use base36 for the RSC query (#52204)
By using a larger base we can have a shorter parameter with almost the same result space.
2023-07-04 16:27:48 +00:00
Alex Kirszenberg
3406e13ab0
Update Turbopack (#52198)
## Turbopack updates

* https://github.com/vercel/turbo/pull/5457 
* https://github.com/vercel/turbo/pull/5458
2023-07-04 15:56:09 +00:00
Shu Ding
cd66e765e0
Skip build-time dynamic code checks for specific polyfills in the Edge runtime (#52009)
As discussed in https://vercel.slack.com/archives/C03ENM5HB4K/p1687999628589119 and #51910, it makes sense to have a known list for packages (mostly polyfills) that we know are having dynamic code (`eval`, `new Function`) but are safe to run in the Edge Runtime because that dynamic code will never be executed.
2023-07-04 14:18:02 +00:00
Tobias Koppers
6cb6092e17
fix workflow needs (#52180)
### What?

I forgot to update the `needs` in the workflow
2023-07-04 15:01:33 +02:00
Alex Kirszenberg
13cfc2bf4d
Update CustomModuleType import (#52133)
https://github.com/vercel/turbo/pull/5397

## Turbopack updates

* https://github.com/vercel/turbo/pull/5419 
* https://github.com/vercel/turbo/pull/5397
2023-07-04 12:39:41 +00:00
Tobias Koppers
532f779782
update turbopack (#52186)
* https://github.com/vercel/turbo/pull/5395 
* https://github.com/vercel/turbo/pull/5452
2023-07-04 11:54:40 +00:00
Tobias Koppers
12f2a66ff0
Revert "chore(deps): bump react 18.3.0-canary-1fdacbefd-20230630" (#52192)
Reverts vercel/next.js#52005
2023-07-04 12:59:14 +02:00
Tobias Koppers
df82f1ac8a
disable flaky test cases (#52184)
### What?

These test cases are too unreliable

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2023-07-04 12:50:18 +02:00
Zack Tanner
0b87ba29c4
fix: infinite dev reloads when parallel route is treated a page entry (#52061)
### What?
When there's a parallel route adjacent to a tree that has no page
component, it's treated as an invalid entry in `handleAppPing` during
dev HMR, which causes an infinite refresh cycle

### Why?
In #51413, an update was made to `next-app-loader` to support layout
files in parallel routes. Part of this change updated the parallel
segment matching logic to mark the parallel page entry as `[
'@parallel', [ 'page$' ] ]` rather than `[ '@parallel', 'page$' ]`.

This resulted in `handleAppPing` looking for the corresponding page
entry at `client@app@/@parallel/page$/page` (note the `PAGE_SEGMENT`
marker) rather than `client@app@/@parallel/page`, causing the path to be
marked invalid on HMR pings, and triggering an endless fastRefresh.

### How?
A simple patch to fix this would fix this is to update `getEntryKey` to
replace any `PAGE_SEGMENT`'s that leak into the entry which I did in
59a972f53339cf6e444e3bf5be45bf115a24c31a.

The other option that's currently implemented here is to only insert
PAGE_SEGMENT as an array in the scenario where there isn't a page
adjacent to the parallel segment. This is to ensure that the
`parallelKey` is `children` rather than the `@parallel` slot when in
[`createSubtreePropsFromSegmentPath`](59a972f533/packages/next/src/build/webpack/loaders/next-app-loader.ts (L298)).
This seems to not cause any regressions with the issue being fixed in
51413, and also solves this case, but I'm just not 100% sure if this
might break another scenario that I'm not thinking of.

Closes NEXT-1337
Fixes #51951
2023-07-04 12:37:00 +02:00
Steven
9e4b87d502
chore(deps): bump react 18.3.0-canary-1fdacbefd-20230630 (#52005)
This PR updates the vendored react dependencies using `pnpm sync-react`

### React upstream changes

- https://github.com/facebook/react/pull/27028
- https://github.com/facebook/react/pull/27027
- https://github.com/facebook/react/pull/27019
- https://github.com/facebook/react/pull/26954
- https://github.com/facebook/react/pull/26987
- https://github.com/facebook/react/pull/26985
- https://github.com/facebook/react/pull/26933
- https://github.com/facebook/react/pull/26625
- https://github.com/facebook/react/pull/27011
- https://github.com/facebook/react/pull/27008
- https://github.com/facebook/react/pull/26997
- https://github.com/facebook/react/pull/26989
- https://github.com/facebook/react/pull/26955
- https://github.com/facebook/react/pull/26963
- https://github.com/facebook/react/pull/26983
- https://github.com/facebook/react/pull/26914
- https://github.com/facebook/react/pull/26951
- https://github.com/facebook/react/pull/26977
- https://github.com/facebook/react/pull/26958
- https://github.com/facebook/react/pull/26940
- https://github.com/facebook/react/pull/26939
- https://github.com/facebook/react/pull/26887
- https://github.com/facebook/react/pull/26947
- https://github.com/facebook/react/pull/26945
- https://github.com/facebook/react/pull/26942
- https://github.com/facebook/react/pull/26938
- https://github.com/facebook/react/pull/26844
- https://github.com/facebook/react/pull/25510
- https://github.com/facebook/react/pull/26932
- https://github.com/facebook/react/pull/26896
- https://github.com/facebook/react/pull/26913
- https://github.com/facebook/react/pull/26888
- https://github.com/facebook/react/pull/26827
- https://github.com/facebook/react/pull/26889
- https://github.com/facebook/react/pull/26877
- https://github.com/facebook/react/pull/26873
- https://github.com/facebook/react/pull/26880
- https://github.com/facebook/react/pull/26842
- https://github.com/facebook/react/pull/26858
- https://github.com/facebook/react/pull/26754
- https://github.com/facebook/react/pull/26753
- https://github.com/facebook/react/pull/26881

### Related

Closes #49409 (by https://github.com/facebook/react/pull/26977)
fix NEXT-1189

Co-authored-by: Shu Ding <g@shud.in>
2023-07-04 11:32:31 +02:00
Tim Neutkens
ae3db7ce6b
Memoize useRouter from next/navigation when used in Pages Router (#52177)
## What?

Ensures the router instance passed for `next/navigation` in Pages Router is a stable reference. For App Router the router instance is already a stable reference, so making this one stable too would fix #18127.


## How?

Added `React.useMemo` around `adaptForAppRouterInstance`, previously it was recreated each render but that's not needed for this particular case. The searchParamsContext and pathnameContext do need a new value each render in order to ensure they get the latest value.


Fixes #18127
Fixes NEXT-1375
2023-07-04 09:11:21 +00:00
vercel-release-bot
4f75c79938 v13.4.9-canary.1 2023-07-04 08:30:06 +00:00
Tim Neutkens
5d06b79e92
Support scroll: false for Link component for app router (#51869)
### What

Support `scroll={false}` for Link component in app router. This can be
used when you don't need to scroll back to top again when route url
changes. For instance hash query changes, if you want to keep the
scrolling as it is, you can use this option.

### How

Handling the `scroll` option in navigation reducer on client side.  

Fixes #50105
Fixes NEXT-1377

---------

Co-authored-by: Jiachi Liu <inbox@huozhi.im>
2023-07-04 10:25:25 +02:00
Tobias Koppers
b8ae8d210a
update tests list to include all passing tests (#52026)
### What?

Add all passing tests

### Why?

We enforced that they all run turbopack and these are passing.
If any of these tests would become red, that indicated a problem.
2023-07-04 07:40:50 +00:00
vercel-release-bot
f60b5621ac v13.4.9-canary.0 2023-07-04 00:05:08 +00:00
Steven
e17218fcba
fix: next.config.js with unstable_getImgProps() (#52153)
- Fixes #52116
2023-07-03 23:56:36 +00:00
JJ Kasper
b4b98e84d9
Update result job condition (#52155)
Ensures when the cancelled status occurs we don't mark it as passed.
2023-07-03 16:33:22 -07:00
JJ Kasper
e477e01dbe
Update test result step (#52154)
Removes usage of custom runner on final step as it's not necessary
2023-07-03 23:07:28 +00:00
Shu Ding
d8ad0d3cbf
Fix modularizeImports transform of antd (#52148)
`antd` should be using `kebabCase`:
https://unpkg.com/browse/antd@5.6.4/es/index.js

This addresses the problem below as I tested locally:

<img width="397" alt="CleanShot 2023-07-03 at 20 45 48@2x"
src="https://github.com/vercel/next.js/assets/3676859/73ae99b9-0f3b-49ef-9675-9f45322b708d">
2023-07-03 22:48:32 +02:00
Shu Ding
3a87f0005e
Change the Server Actions feature flag to be validated at compile time (#52147)
Currently we are validating the `experimental.serverActions` flag when creating the actual entries for Server Actions, this causes two problems. One is that syntax errors caught at compilation time are still shown, even if you don't have this flag enabled. Another problem is we still traverse the client graph to collect these action modules even if the flag isn't enabled.

This PR moves that check to be happening at compilation time, which addresses the two above but also brings the extra benefit of showing the exact span and module trace that errors:

<img width="974" alt="CleanShot 2023-07-03 at 20 26 34@2x" src="https://github.com/vercel/next.js/assets/3676859/1676b1f6-e205-4963-bce4-5b515a698e9c">
2023-07-03 20:29:57 +00:00
Jiachi Liu
cd9372c175
Reland "ReverseTopological -> AdjacencyMap"" (#52142)
Reverts vercel/next.js#52139
2023-07-03 19:13:50 +00:00
vercel-release-bot
b4a875eb57 v13.4.8 2023-07-03 17:00:28 +00:00
Jiachi Liu
4b4731dfbe
Revert "ReverseTopological -> AdjacencyMap" (#52139)
Reverts vercel/next.js#52032

Will reland after the release
2023-07-03 16:33:24 +00:00
Chris Yang
11bd7725b5
Add missing url hash (#52123)
<!-- 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: JJ Kasper <jj@jjsweb.site>
2023-07-03 08:36:09 -07:00
Alex Kirszenberg
f6a152287a
ReverseTopological -> AdjacencyMap (#52032)
See https://github.com/vercel/turbo/pull/5430

## Turbopack changes

* https://github.com/vercel/turbo/pull/5430 <!-- Alex Kirszenberg -
ReverseTopological -> AdjacencyMap -->
2023-07-03 14:40:41 +02:00
vercel-release-bot
eca315308a v13.4.8-canary.15 2023-07-03 10:21:27 +00:00
Jiachi Liu
c87a1b12c3
fix: env hot reload for RSC pages (#51930)
### Issue
When you edit .env* files, the pages under app dir that using env vars are not triggering hot reload

### Fix
Triggering serverComponentChanges hot reload action when we detect env or tsconfig related change. There's a time period that we need to wait before the compilation is finished. First we save a flag `reloadOnDone` if we need to reload when after compilation is done, by determining if `envChange` is `true` (we already know this in dev server). Then in the compilation hooks, we refresh RSC page once it's finished.

### Extra change 

since we're checking `event.action` in client hot reloader, and throwing error for unknown action, filter devPagesManifestUpdate out from unexpected action as it sometimes triggered as error in console. Introduced in #51516
Fixes NEXT-1261
2023-07-03 10:11:28 +00:00
Jiachi Liu
10605a15c1
Renable flaky tests disabled before (#51680)
As we moved to new CI runner in `#50436`, try to re-enable few flaky tests we disabled before
2023-07-03 09:29:28 +00:00
Alex Kirszenberg
805bfa45e0
Remove EnvironmentIntention (#51965)
See https://github.com/vercel/turbo/pull/5420

# Turbopack changes

* https://github.com/vercel/turbo/pull/5420 
* https://github.com/vercel/turbo/pull/5387
2023-07-03 09:03:37 +00:00
Shu Ding
8eb9730607
Avoid unnecessary resolveExternal calls (#52053) 2023-07-03 10:34:46 +02:00
Tyler Lutz
967b876f6b
docs: Fix broken link (#52092)
Fix a broken link in optimizing index.mdx.
2023-07-02 18:20:27 +00:00
Tim Neutkens
ce69574c24
Add default modularizeImports for antd / ant-design/icons / ahooks (#52031)
Follow up to #50900.

Based on https://github.com/vercel/next.js/issues/48748#issuecomment-1608783867
2023-07-02 17:32:25 +00:00
Shu Ding
bd24a8eb24
Delegate static analyzation task to the router worker (#52104)
In the dev server, we need to call `getStaticInfoIncludingLayouts` for the middleware file to extract its `matchers` field. However, that's currently executed in both app and pages workers. This method is expensive as it depends on the SWC binary to be loaded.

This PR changes it to invoke it as an IPC method, so only the router worker (which runs the compilation) loads SWC, instead of all 3 of them.

This also fixes duplicated console messages of:

```
Using locally built binary of @next/swc
```

For our test app, I'm seeing a 150~250ms improvement:

![CleanShot 2023-07-02 at 18 29 22@2x](https://github.com/vercel/next.js/assets/3676859/be78b79b-2eb4-4f04-92dc-3640e12cde23)

Haven't measured about the memory impact yet, but it should be a lot.
2023-07-02 17:04:57 +00:00