Commit graph

17126 commits

Author SHA1 Message Date
Steven
0621171f0b
chore(ci): add socket.yaml (#54446)
This config file will prevent Socket from scanning unnecessary directories and should speed it up.

See https://docs.socket.dev/docs/socket-yml
2023-08-23 18:12:51 +00:00
Lee Robinson
ed3aea924d
docs: Remove unneeded word in caching docs (#54451) 2023-08-23 16:24:31 +00:00
Tim Neutkens
00106b7ef4
Optimize webpack memory cache garbage collection (#54397)
## What

Adds a reworked version of webpack's [built-in memory cache garbage
collection
plugin](853bfda35a/lib/cache/MemoryWithGcCachePlugin.js (L15))
that is more aggressive in cleaning up unused modules than the default.

The default marks 1/5th of the modules as "up for potentially being
garbage collected". The new plugin always checks all modules. In my
testing this does not cause much overhead compared to the current
approach which leverages writing to two separate maps. The change also
makes the memory cache eviction more predictable: when an item has not
been accessed for 5 compilations it is evicted from the memory cache, it
could still be in the disk cache.


In order to test this change I had to spin up the benchmarks but these
were a bit outdated so I've cleaned up the benchmark applications.

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2023-08-23 15:46:32 +02:00
vercel-release-bot
93e4e6d438 v13.4.20-canary.3 2023-08-23 13:13:36 +00:00
Jiachi Liu
9834ab7e15
Fix not found css not being preloaded while navigation (#53906)
### Problem

One style of `not-found` has `precendence` property with "undefined" value, which can't be handled by React Float, then during navigation the style could not load properly, lead to the style missing in issue #53210.

### Solution

Always enable `precendence` for all links, so all the css styles of page and convention components can be hoist by react properly. Float will decide which one should be handled. Previously this change only applies to template, actually we can apply it to all components so that they can all be handled properly especially during client navigation.

Related react change: https://github.com/facebook/react/pull/27265
Fixes #53210
2023-08-23 13:07:30 +00:00
Delba de Oliveira
06be3c6cf5
Docs: Remove runtime configuration from /app docs (#54336)
Remove runtime configuration from app docs as it's not available. 

Fixes: https://vercel.slack.com/archives/C03S9JCH2Q5/p1692029581031809
2023-08-23 12:42:50 +00:00
Jiachi Liu
db72cb12d9
refactor: Use swc AST to determine use client and server directives (#54358)
Follow up for #54202, use swc AST to determine the directives. Also add server actions directives for extendibility here in case we might need it in the future

Closes NEXT-1538
2023-08-23 12:28:20 +00:00
Shu Ding
ad556aee1b
Fix compilation of next/dynamic with ssr: false in App Router (#54411)
For the server compilation, we currently transpile the dynamic import
expression to `null` if `ssr` is disabled. However to make the Server
Actions layer work (as it can be created again from a Client Component),
we can't do that optimization.

This PR changes it to always keep that import expression when
`react_server_components` (App Router) is enabled, no matter which layer
it's on.

Closes #52672.
2023-08-23 14:15:31 +02:00
Jiachi Liu
1e3920c3dd
Upgrade precompiled ua-parser-js (#54404)
Upgrade `ua-parser-js` which is used by `userAgentFromString` to latest version

Closes NEXT-1552
2023-08-22 23:56:05 +00:00
Shu Ding
ee6c3690ef
Code clean up (#54405)
Refactored some small places.
2023-08-22 22:41:27 +00:00
Jiachi Liu
6d769d0eb8
Upgrade vendored react (#54399)
### React upstream changes

- https://github.com/facebook/react/pull/27265
- https://github.com/facebook/react/pull/27259
- https://github.com/facebook/react/pull/27264
- https://github.com/facebook/react/pull/27257
- https://github.com/facebook/react/pull/27258
- https://github.com/facebook/react/pull/27187
- https://github.com/facebook/react/pull/27243
- https://github.com/facebook/react/pull/27205
- https://github.com/facebook/react/pull/27220
- https://github.com/facebook/react/pull/27238
- https://github.com/facebook/react/pull/27234
- https://github.com/facebook/react/pull/27224
- https://github.com/facebook/react/pull/27223
- https://github.com/facebook/react/pull/27222

This will help unblock https://github.com/vercel/next.js/pull/53906
2023-08-22 22:27:54 +00:00
Donny/강동윤
c792baa7ce
Update swc_core to v0.79.70 (#54368)
### What?

Update swc_core to `v0.79.70`

### Why?

To apply https://github.com/swc-project/swc/pull/7839

### How?

Closes WEB-1420
Fixes #54192
2023-08-22 20:46:00 +00:00
Jiachi Liu
0277ef0931
Fix swc compiling of client components when directive appears later than exports (#54392)
When `"use client"` directive appears after other statements, it should
be ignored instead of treat as client components. There's a bug inside
swc transform that we should mark the directives detection is "finished"
after other non string literals directives AST nodes are detected before
the first directive

x-ref:
https://github.com/vercel/next.js/pull/54358#discussion_r1300740950
2023-08-22 20:40:11 +02:00
Balázs Orbán
96a59344e8
fix(app): enable React Strict Mode by default (#53375)
### What?

Let Next.js enable React Strict Mode by default for the App Router.

This caught a bug with the `AppRouterAnnouncer` added in #47018 which
should be fixed as well.

### Why?

This logic:


a0d1d728b9/packages/next/src/build/webpack-config.ts (L326-L333)

assumes that the default value of `reactStrictMode` is `null`, but it
was set to `false` in #46656.

### How?

This PR reverts the default value to `null`.


Closes NEXT-1484
Fixes #53315

---------

Co-authored-by: Tim Neutkens <tim@timneutkens.nl>
2023-08-22 20:17:17 +02:00
JJ Kasper
c89f97ea56
Fix data route ordering in dev (#54364)
Previously we were appending the data routes to the dynamic routes array
which didn't ensure the data routes come before the normal dynamic
routes allowing a catch-all to override the data route.

Fixes: https://github.com/vercel/next.js/issues/53887
2023-08-22 10:19:54 -07:00
Delba de Oliveira
705b2ef2d4
Docs: Refer users to IDE or MDN for manifest object options (#54385)
Based on feedback here:
https://vercel.slack.com/archives/C03S9JCH2Q5/p1692712555316389?thread_ts=1692710113.742499&cid=C03S9JCH2Q5
2023-08-22 09:50:53 -05:00
Delba de Oliveira
83394b900b
Docs: Document manifest metadata file (#54380)
Add missing docs for `manifest` metadata file. 

Fixes: https://github.com/vercel/next.js/issues/54296
2023-08-22 14:35:41 +00:00
Delba de Oliveira
9ca82f68ed
Docs: Clarify status codes w/ streaming (#54374)
Clarify what status code is returned when streaming, and in relation to `redirect` and `not-found`. 

Relates to: https://github.com/vercel/next.js/pull/54361

Co-authored-by: Lee Robinson <9113740+leerob@users.noreply.github.com>
2023-08-22 14:03:56 +00:00
vercel-release-bot
8bbf674a4d v13.4.20-canary.2 2023-08-22 12:43:03 +00:00
Shu Ding
5584e5743a
Merge app renderer process (#54143)
This PR merges the app renderer worker into the router process. This
improves the memory overhead mostly.

There're future work to do to get rid of the IPC server for router and
app renderer, as they're now merged in one process.

Fixes NEXT-1492
2023-08-22 14:38:42 +02:00
Delba de Oliveira
f0ff3c468c
Docs: Update template.js section (#54370)
Fixes: https://vercel.slack.com/archives/C03S9JCH2Q5/p1692619927373449

- Updates wording on nesting, to say it's not the actual output, but rather how `template.js` nests between `layout.js` and its children.
- Remove mention of animations, needs further clarification.
2023-08-22 09:05:38 +00:00
Steven
f6d2aa09de
fix: minimum node version 16.14.0 (#54331)
- Fixes https://github.com/vercel/next.js/issues/54269
- Related to https://github.com/vercel/next.js/pull/54285
2023-08-22 08:58:53 +00:00
JJ Kasper
ca2785743c
Update timeout for release stats (#54363)
x-ref:
https://github.com/vercel/next.js/actions/runs/5932197432/job/16085712916
2023-08-21 17:21:04 -07:00
vercel-release-bot
1a56fb9483 v13.4.20-canary.1 2023-08-21 22:41:53 +00:00
JJ Kasper
d54ed07b3c
Fix missing locale info for middleware data request (#54357)
This ensures we properly populate locale information with `skipMiddlewareUrlNormalize` enabled as we shouldn't provide incorrect values even if we are skipping normalizing. 

Fixes: https://github.com/vercel/next.js/issues/53646
2023-08-21 22:34:42 +00:00
Sloane Sturzenegger
ffe2d0400b
Polyfill Array.prototype.at (#44436)
fixes issue #44141 , discussion #44148

This is missing and has caused me issues in production. Seems like a great polyfill to have, given that Next already polyfills so many adjacent Array methods.

## Bug

- [x] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [x] Related issues linked using `fixes #number`
- [ ] [e2e](https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs) tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm build && pnpm lint`
- [ ] The "examples guidelines" are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)


Co-authored-by: Eyas Valdez <37156127+spiltbeans@users.noreply.github.com>
Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
2023-08-21 22:09:14 +00:00
Dima Voytenko
895f104b3a
Testmode: intercept rewrite fetches (#54259)
The test mode should allow interception of all fetches made by the
server, including rewrites.

---------

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2023-08-21 15:01:49 -07:00
Delba de Oliveira
0c85f8aad3
Docs: Add notes that revalidation is not available in the Edge runtime / only Node.js (#54338)
Fixes: https://vercel.slack.com/archives/C03S9JCH2Q5/p1692261964220369
2023-08-21 22:00:40 +00:00
Dima Voytenko
1f999b6f4d
OpenTel: ensure that exceptions are recorded on an active span (#54131)
Examples of the output with this change:

<img width="346" alt="image" src="https://github.com/vercel/next.js/assets/726049/6f8b94ea-5890-401a-9760-15af38ea4f0c">
2023-08-21 21:47:40 +00:00
JJ Kasper
06e7e76cff
Skip getStaticPaths check for non-dynamic app routes (#54351)
We don't need to apply this check for non-dynamic app routes so this
adds a check to skip it when not necessary.

x-ref: [slack
thread](https://vercel.slack.com/archives/C04DUD7EB1B/p1692366432958709)

---------

Co-authored-by: Zack Tanner <zacktanner@gmail.com>
2023-08-21 14:33:45 -07:00
Jiachi Liu
70231ef7cd
test: add case for marking _document with edge runtime (#54316)
Can't repro anymore, add a test case for issue 45189

Closes #45189
Closes NEXT-1396
2023-08-21 20:56:46 +00:00
JJ Kasper
0e91c79f57
Fix windows next-swc builds (#54353)
Fixes this build error on windows due to invalid path:

```sh
 Error: error: invalid path 'test/e2e/app-dir/app/app/bootstrap/[[...*]]/ClientComponent.js'
 Error: The process 'C:\Program Files\Git\cmd\git.exe' failed with exit code 128
```

x-ref:
https://github.com/vercel/next.js/actions/runs/5930602201/job/16080672888#step:7:62
2023-08-21 13:35:12 -07:00
Zack Tanner
892839ff83
fix: server actions blocking navigation events (#54307)
A long-running server action shouldn't block page navigation. This makes use of a global mutable to detect when a navigation event occurs -- this change will unblock other reducers (such as navigation).

If we bailed on the action, we trigger a `router.refresh()` to ensure any side effects from the action are refetched.

Closes NEXT-1131
Fixes #49425
2023-08-21 20:34:42 +00:00
OJ Kwon
36c14da3d5
ci(trace): allow to opt in to upload full trace (#54347)
### What?
 
Came to realize it might be useful to upload full trace. This is avoided by default as trace might grow excessively, however might be useful to audit individual trace if it can be uploaded.

Closes WEB-1416
2023-08-21 19:25:16 +00:00
Josh Story
3370022ac2
add test case for CSP with bootstrap scripts and preinit modules (#54348)
in #54059 the nonce attribute was added to preinitialized scripts to when using this CSP directive. The test added asserts there is at least one script that has the nonce attribute. I've changed this to 2 because currently our builds produce at least two "main" scripts, the main chunk and the webpack runtime. The way we bootstrap there is always exactly one bootstrap script which means if we only assert that there is one script with a nonce we might not be asserting anything about the preinit script path. If we ever update our webpack config to produce a single main script this test will fail but we should never do that (it's bad for caching) and so it shouldn't happen and if it does it will hopefully force us to consider if we're making a mistake

Additionally I've added another test that is more e2e. it asserts that the page bootstraps even when using CSP (in prod). In Dev it asserts the CSP attributes but it expects the bootstrap to fail because our dev mode violates the CSP directive with eval.
2023-08-21 18:49:21 +00:00
Mohamed A. Salah
b7eb6d43b9
set hostname to 0.0.0.0 (#54342)
When I try to deploy to Google Cloud Run it fails after some
investigation I saw this line in

.next/standalone/server.js
```javascript
const hostname = process.env.HOSTNAME || 'localhost'
``` 
This some how make this log when i run docker 
```shell
- ready started server on 172.17.0.2:3000, url: http://172.17.0.2:3000
``` 
I don't know why it's logging this address even if the server running on
localhost.

So this my fix
Set hostname to 0.0.0.0 to avoid deployment failing on Google cloud run.
2023-08-21 19:05:57 +02:00
Delba de Oliveira
3bce82e807
Docs: Fix broken links (#54340)
Fix broken links picked up by crawl-analysis: https://vercel.slack.com/archives/C03S9JCH2Q5/p1692621216597749
2023-08-21 16:33:38 +00:00
Tooooooooon
5d758c7ec0
update readme in nextjs testing (#54322)
Co-authored-by: Michael Novotny <446260+manovotny@users.noreply.github.com>
2023-08-21 15:32:13 +00:00
Steven
6773ea8636
fix: improve error message when output: export in app router (#54202)
There are a few cases that are not handled by App Router when using `output: export` config.

A few of them are expected, but some are yet to be implemented. Regardless of the intent of the future, this PR ensures the error messages match what was documented to be [unsupported](https://nextjs.org/docs/app/building-your-application/deploying/static-exports#unsupported-features).

- Documentation: https://github.com/vercel/next.js/pull/53592
- Issue: #48022
2023-08-21 14:45:00 +00:00
Lee Robinson
0718aec93b
Update Contentful example for App Router. (#54205)
This PR updates the `cms-contentful` example to use:

- App Router
- TypeScript
- Draft Mode (previously Preview Mode)
- ISR / Data Cache (revalidations through `revalidateTag`)

Further, it combines many separate files into more manageable single files, and tries to better bucket provider-specific logic into the `lib/` folder. I'm hoping this can be the foundation for re-writing the rest of the `cms-*` examples to use App Router.

Overall, the code is much easier to reason about IMO. Pretty happy with the change. I sprinkled some `any`'s throughout here, but if someone wants to make it better, go for it! 

https://app-router-contentful.vercel.app/
2023-08-21 13:21:37 +00:00
Laurent Thiebault
71d424e804
docs: update a small typo in 02-app/01-building-your-application/06-optimizing/01-images.mdx (#54311)
Hello,

I just make this PR because the `/me.png` example is not in "remote images" section but in "local images", that's why I propose to edit this :)

Thank you!

### Improving Documentation

- [x] Run `pnpm prettier-fix` to fix formatting issues before opening the PR.
- [x] Read the Docs Contribution Guide to ensure your contribution follows the docs guidelines: https://nextjs.org/docs/community/contribution-guide
2023-08-20 18:33:16 +00:00
Shu Ding
a47d92f55e
Fix default export of server action utility aliases (#54254)
Similar to #54004, this PR changes `private-next-rsc-action-validate`
and `private-next-rsc-action-client-wrapper` to export named values
instead of default values. In #54230 (currently broken), the Server
Action file was bundled via Vite/Rollup as an external dependency so
we're not doing the ESM interoperation correctly.

Closes #54230.
2023-08-20 18:09:38 +02:00
Nikhil Bhargava
24cd55c09f
Adds nonce to preinit scripts (#54059)
Fixes #54055.

A bug recently introduced in https://github.com/vercel/next.js/pull/53705 made it so that we were now preinitializing some of our scripts slightly better, but in doing so, we failed to pass in a nonce. This broke nonce-based CSP usage. The fix was to add the `nonce` to our `ReactDOM.preinit` calls.

Manual testing shows that this change fixes the error and the nonce is now passed in as expected.


Co-authored-by: Dan Ott <360261+danieltott@users.noreply.github.com>
2023-08-20 13:55:02 +00:00
vercel-release-bot
f1c286fff2 v13.4.20-canary.0 2023-08-20 12:56:16 +00:00
Jimmy Lai
6aa07fb999
app-router: tweak prefetch cache status heuristics (#53864)
This PR changes the heuristic in the client cache to only check and show the prefetched data when it was prefetched or last read 30s ago vs keeping it around as long as it was accessed within 30s.
2023-08-20 11:25:48 +00:00
Tim Neutkens
86fc1697d5
Remove unused array in router-server (#54278)
Noticed these arrays don't actually do anything specific, removed them.

Update: After the multi-zone test failed it seems this was added to ensure you can run multiple Next.js instances in the same process, this simplifies it a bit and adds a comment explaining why it's called.
2023-08-20 11:09:12 +00:00
Donny/강동윤
d2a8d4fa2d
Update swc_core to v0.79.69 (#54190)
### What?

Update swc crates to becea47a2d

### Why?

x-ref: https://vercel.slack.com/archives/C02HY34AKME/p1692293544442219

### How?

Closes WEB-1410
2023-08-20 10:55:41 +00:00
Jiachi Liu
f2a3fd9fc3
Handle basePath for redirect() (#54277)
### What & Why
Add base path handling for the url in redirect error if the `basePath` is configured.

This is only break for server rendering case as the `basePath` is missing in the `Location` header. When running `next build`, everything is managed well with app router and base path on client side so it didn't break.

### How

Adding `basePath` if it's presented for `Location` header.
Update the `RenderOpts` type as basePath is already passed down in it, also update them for turbopack entries

Fixes #54163
Closes NEXT-1529
2023-08-20 03:32:52 +00:00
Jiachi Liu
311eea4c6a
Fix emotion-js transform for server components (#54284)
### What & Why

emotion-js has its own [jsx transform](https://emotion.sh/docs/typescript#emotionreact) which is being applied when `compiler.emotion` is enabled in `next.config.js`.

Thanks to emotion-js team that provided an emotion-js example setup with app router [here](https://github.com/emotion-js/emotion/issues/2928#issuecomment-1319792703), so that we can use it as test example with app router. Based on the setup, we create a test case working with emotion js but failed with error mentioned in #41994 that some client hooks appearing in server components. That is because the emotion-js jsx factory includes some client hooks.

### How

For server components, css-in-js is not recommended to apply so we disabled the transform before, the emotion jsx factory is a separate config that should also not be applied in server components. So in this case we still use react jsx factory instead of the emotion-js one for server components then it won't error. The test case can also be used as an example for basic emotion-js use case with app router.


Fixes #41994
Closes NEXT-1368
2023-08-20 03:14:16 +00:00
Joseph
76997cc053
docs: Bump minimum Node.js version to 16.14 (#54285)
### What?

Docs change.

### Why?

- https://github.com/vercel/next.js/issues/54269

### How?

Bump the Node.js version shown at: https://nextjs.org/docs/app/building-your-application/upgrading/app-router-migration#nodejs-version 

Fixes #54269
2023-08-20 03:03:02 +00:00