Commit graph

8534 commits

Author SHA1 Message Date
Shu Ding
f12aa35b0d
Fix accessing strict of undefined in writeConfigurationDefaults (#48799)
Fixes the 

```
TypeError: Cannot read properties of undefined (reading 'strict')
    at writeConfigurationDefaults
```

error.

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2023-04-25 15:53:21 -05:00
Shu Ding
641d419ada
Add async context to server request handler (#48626)
This PR adds an `AsyncLocalStorage` wrapper to the action handler, so
underlying function calls can tell if it's running in that.
2023-04-25 18:45:10 +02:00
Shu Ding
ac8de9fae8
Polyfill FormData with edge-runtime primitives (#48826)
It makes more sense to use the `FormData` from `@edge-runtime/primitives` to ensure the version and implementation are aligned, and avoid importing extra modules (as we always import the Edge Runtime).
2023-04-25 15:55:31 +00:00
Tobias Koppers
8602bf35e0
fix query for app dir in turbopack (#48828)
### What?

Fix the query for app dir

### Why?

it's not correct in app dir
2023-04-25 15:31:07 +00:00
Shu Ding
287e379b92
Vendor react@experimental (#48697)
Part of #47759 (which had been reverted twice so here we only land a part of the change), relates to NEXT-926. Thanks to #48506 we can soon switch between these two channels during runtime.

Also fixes a problem of `renderKind` (only revealed after upgrading React), it should be also based on the `match` kind.
2023-04-25 14:29:02 +00:00
Shu Ding
f08cab3b0f
Only track client entry modules in the client reference manifest (#48814)
This is currently an overhead, that we check a module's layer (`mod.buildInfo.rsc?.type === RSC_MODULE_TYPES.client`) and put all client modules in the client reference manifest, but the manifest is only used for accessing these entry modules. So here we change the util to check if it's an client entry instead.

With this change the client manifest of a test app decreased from 177 KB to 70 KB.

Ref: 5b609e264f/packages/next/src/build/analysis/get-page-static-info.ts (L50-L64)
2023-04-25 12:27:53 +00:00
Jiachi Liu
0f6b357181
Improve typing of resolve metadata (#48670)
Improve array resolving in metadata, remove ts comments for errors
2023-04-25 10:17:54 +00:00
vercel-release-bot
9863935f44 v13.3.2-canary.6 2023-04-25 09:13:29 +00:00
Tim Neutkens
ee86ace5ce
Fix hash apply after server-patch action (#48813)
### What?

Mux reported that their website does not scroll to hash when clicking a search result. Found it's related to `server-patch` triggering and overriding the hashFragment. That should be preserved similarly to `apply`.

### How?

handleMutable had a default of `null` instead of using the existing value. It should use the existing value.
2023-04-25 09:05:44 +00:00
Donny/강동윤
a18f50a321
fix: Update @swc/helpers to v0.5.1 (#48808)
### What?

Update `@swc/helpers` to `v0.5.1`.

### Why?

Webpack merges `@swc/helpers@v0.4.x` and `@swc/helpers@v0.5.x`, due to `resolve.alias` config in 2f6ff0dab3/packages/next/src/build/webpack-config.ts (L1070-L1072)

To workaround it, `@swc/helpers@v0.5.1` reexports from entries just like `v0.4`.

### How?

Closes WEB-948
Fixes #48593
2023-04-25 04:32:27 +00:00
vercel-release-bot
79c73887cd v13.3.2-canary.5 2023-04-25 01:30:47 +00:00
vercel-release-bot
2f6ff0dab3 v13.3.2-canary.4 2023-04-24 22:21:45 +00:00
Steven
7e97dc5ebf
Add missing repository prop to package.json (#48803)
This should fix the following error:

```
npm ERR! 422 Unprocessable Entity - PUT https://registry.npmjs.org/@next%2fswc-darwin-x64 - Failed to validate repository information: package.json: "repository.url" is "undefined", expected to match "git+https://github.com/vercel/next.js" from provenance
```

https://github.com/vercel/next.js/actions/runs/4787411938/jobs/8512829488#step:10:74

- Related to https://github.com/vercel/next.js/pull/48757
2023-04-24 17:17:06 -05:00
Preston Landers
7fb4d27053
Fix Windows path in route join (#48603) (#48779)
A change here: (#48202) 958150d
Caused a URL to be joined with `path.join`, which on Windows inserts a backslash character. Changing to `path.posix.join` fixes this.

Breaks next build on Windows when paths like `favicon.ico` are in the source dir.

Fixes #48603
2023-04-24 19:12:25 +00:00
Jiachi Liu
5b609e264f
Error on legacy runtime config under app dir (#48774)
When you're using `config` object with `runtime` we'll show a warning and recomment you to move to `export const runtime = ...` for runtime property as it's documented as recommended. This PR adds a error for `next build` to avoid logs are truncated during multi-workers build and you're aware of the config which doesn't take effect with seeing the error

Follow up for #48630
link [NEXT-426](https://linear.app/vercel/issue/NEXT-426)
2023-04-24 18:33:29 +00:00
Shu Ding
03f34625e5
Polyfill FormData for Node.js < 18 (#48783)
We currently use `URLSearchParams` to represent `FormData` but it's not really the same thing. And in Node.js 16 there's no `FormData` available so we can polyfill it via Undici.
2023-04-24 15:48:10 +00:00
vercel-release-bot
2196cbe405 v13.3.2-canary.3 2023-04-24 14:16:49 +00:00
Jan Kaifer
8460373c26
Fix issue with instrumentation in a standalone build (#48615) 2023-04-24 13:49:46 +00:00
Shu Ding
39498d604c
Prefer realpathSync.native over realpathSync (#48698)
Interesting learning from
[this](https://sun0day.github.io/blog/vite/why-vite4_3-is-faster.html#fs-realpathsync-issue),
that `fs.realpathSync` is 70x slower than `fs.realpathSync.native`.
Kudos to the Vite team!
2023-04-24 15:00:06 +02:00
Jan Kaifer
db764c35e6
Add support for async instrumentation register (#48575) 2023-04-24 11:43:50 +00:00
Chris
2679ab672d
Update naming for Next.js Analytics (#48618)
Updates the name of Next.js Analytics to Next.js Speed Insights

closes ALY-579

---------

Co-authored-by: Steven <steven@ceriously.com>
Co-authored-by: Tim Neutkens <tim@timneutkens.nl>
2023-04-24 12:14:45 +02:00
Alex Kirszenberg
7fdcb172f9
Lazy DevHtmlAsset chunk generation (#48768)
This fixes a perf regression introduced in the chunking refactor, where
we would be eagerly generating all assets from the web entry and
fallback sources.

See https://github.com/vercel/turbo/pull/4679

This also brings the following updates from vercel/turbo:

* https://github.com/vercel/turbo/pull/4669 <!-- Tobias Koppers - make
the invalidation reason easier to read -->
* https://github.com/vercel/turbo/pull/4670 <!-- Tobias Koppers -
dev-server content might change any time, we can't cache them -->
* https://github.com/vercel/turbo/pull/4653 <!-- OJ Kwon -
fix(ecmascript): displayname for styled_components -->
* https://github.com/vercel/turbo/pull/4679 <!-- Alex Kirszenberg - Lazy
DevHtmlAsset chunk generation --> (this change)
2023-04-24 12:11:24 +02:00
vercel-release-bot
1e9d53ebae v13.3.2-canary.2 2023-04-24 09:23:39 +00:00
vercel-release-bot
e720a1efa4 v13.3.2-canary.1 2023-04-24 08:14:15 +00:00
Tim Neutkens
7e380e3967
Compile Next.js core client-side files using default target (#48750)
### What?

Compiles Next.js core files using the same default target as client-side
files, ensuring that `async`/`await` and such are not turned into
generators.

The client-side files are all opted into compilation during dev/build
already so if you create a browserslist config that will still apply in
the same way. This change only changes the output of the core files.

### How?

Moved the default we use in Next.js into a separate `.js` file so that
it can be imported from the taskfile-swc plugin, this way we're using
the same defaults.

<!-- 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 or adding/fixing 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-04-24 09:53:29 +02:00
vercel-release-bot
2bfde63b78 v13.3.2-canary.0 2023-04-23 21:57:48 +00:00
Steven
743a59dfab
Add support for draft mode (#48669)
Draft Mode is very similar to Preview Mode but doesn't include any
additional data.

This PR implements support for Draft Mode in `pages` and a future PR
will implement support in `app`.

fix NEXT-992
2023-04-23 21:33:34 +00:00
Sreetam Das
06700235dd
fix: TS plugin showing warning for global-error file's reset prop (#48756)
The TS plugin incorrectly gives a warning for the `reset` prop in the `global-error.tsx` file. This was previously reported and fixed for the `error.tsx` file.
- https://github.com/vercel/next.js/issues/46573
- https://github.com/vercel/next.js/pull/46898

---

You can see a reproduction on [CodeSandbox](https://codesandbox.io/p/sandbox/summer-dawn-b0gydg?file=%2Fapp%2Flayout.tsx&selection=%5B%7B%22endColumn%22%3A16%2C%22endLineNumber%22%3A18%2C%22startColumn%22%3A16%2C%22startLineNumber%22%3A18%7D%5D) — `global-error.tsx`'s `reset` prop has the following warning: 

```
Props must be serializable for components in the "use client" entry file, "reset" is invalid. ts(71007)
```

I haven't filed an issue for this yet since this was a simple enough fix, but happy to create one if needed :)
2023-04-23 18:04:20 +00:00
Jiachi Liu
7de1a4070d
Reland "app-router: new client-side cache semantics" (#48695)
Reverts vercel/next.js#48688
fix NEXT-1011
2023-04-22 10:41:08 +00:00
Shu Ding
485955bb36
Do not suggest adding "use client" if using next/router in app (#48680)
Feedback form @MaxLeiter, that we shouldn't tell the user to add "use client" in this case:

![image](https://user-images.githubusercontent.com/3676859/233697824-65e8013b-f292-4f77-bdff-d421269ba750.png)
2023-04-21 23:41:52 +00:00
Shu Ding
a875d5a4f5
Use decodeReplyFromBusboy in node runtime (#48686)
When sending a multipart form data, we currently wait until the entire update finishes before we decode it via `decodeReply`. This way is universal in both runtimes (as we don't have `decodeReplyFromBusboy` in Edge), but also not efficient.

This PR changes it to use `decodeReplyFromBusboy` in the Node runtime, which can decode the payload during streaming as well as file update support.
2023-04-21 23:20:43 +00:00
Shu Ding
b5f7f84485
Refactor require hooks (#48506)
Same purpose as #48297, but without the React channel branching logic to
make it easier to land. Since we have #48478 reverted, we only need to
consider `pages` and `app` inside the require hook.

> This PR aims to improve the current require hook by implementing two
key changes. Firstly, it ensures that the initialization occurs at the
top of the module level for correctness. Secondly, we now set the
NEXT_PREBUNDLED_REACT environment variable at the process level to
ensure that we don't mix the two types of rendering processes and we
always resolve the correct React package.
>
> These improvements are made possible by the changes introduced in PR
https://github.com/vercel/next.js/pull/47857.
> 
> Closes [NEXT-231](https://linear.app/vercel/issue/NEXT-231).

This will likely fix #45258 too.

---------

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2023-04-22 00:19:51 +02:00
vercel-release-bot
6423285451 v13.3.1 2023-04-21 22:04:41 +00:00
vercel-release-bot
455de08b30 v13.3.1-canary.19 2023-04-21 20:59:00 +00:00
Jiachi Liu
8089d0a3bb
Revert "Reland app-router: new client-side cache semantics" (#48688)
Reverts vercel/next.js#48685

Temporary Revert again to investigate the hang job
fix NEXT-1011
2023-04-21 22:36:28 +02:00
Jiachi Liu
b61305afcc
Reland app-router: new client-side cache semantics (#48685)
Reland vercel/next.js#48383
fix NEXT-1011
2023-04-21 19:39:06 +00:00
Leah
4354edadf4
fix snapshots broken by prettier (also fix .prettierignore) (#48586)
### What?
Fix snapshots that were no longer fulfilling the original purpose after
prettier had its way.

The `.prettierignore` also had the old `target/` directory (prior to the
`Cargo.toml` move in #48198) so running `pnpm prettier-fix` formatted
files in the `target/` directory
2023-04-21 18:52:08 +00:00
vercel-release-bot
a06fef0906 v13.3.1-canary.18 2023-04-21 17:50:15 +00:00
Jiachi Liu
52fcc59717
Revert "app-router: new client-side cache semantics" (#48678)
Reverts vercel/next.js#48383
fix NEXT-1011

revert and re-land later
2023-04-21 17:21:58 +00:00
Shu Ding
8fd9a39152
Fix writeConfigurationDefaults.ts to correctly suggest changes in monorepos (#48668)
Closes #48653. It should either modify the TS config to add the Next.js
plugin, or output a log if it can't (to avoid overriding the base
config).

<img width="920" alt="CleanShot-2023-04-21-Klqel8BO@2x"
src="https://user-images.githubusercontent.com/3676859/233642532-5eed8d5d-d2c5-41e9-99bf-d0eb95685206.png">
2023-04-21 11:51:27 -04:00
Sebastian Silbermann
680564c7b5
Ensure latest React types for experimental release channel are used (#48641)
That way users just have to just bump `@types/react` and `typescript`
once TS 5.1. is out to get TS to no longer reject async components.
2023-04-21 16:57:54 +02:00
Nabeel Sulieman
8050a6c8e0
Fix typo in fetchType annotation (#48646)
`fetch-get` and `fetch-set` were typos. They should be `cache-get` and
`cache-set`
2023-04-21 15:10:32 +02:00
Jimmy Lai
658c600534
app-router: new client-side cache semantics (#48383)
This PR implements new cache semantics for the app router on the client.

## Context

Currently, on the App Router, every Link navigation is prefetched and
kept forever in the cache. This means that once you visit it, you will
always see the same version of the page for the duration of your
navigation.

## This PR

This PR introduces new semantics for how the App Router will cache
during navigations. Here's a TL;DR of the changes:
- all navigations (prefetched/unprefetched) are cached for a maximum of
30s from the time it was last accessed or created (in this order).
- in addition to this, the App Router will cache differently depending
on the `prefetch` prop passed to a `<Link>` component:
  - `prefetch={undefined}`/default behaviour:
- the router will prefetch the full page for static pages/partially for
dynamic pages
    - if accessed within 30s, it will use the cache
- after that, if accessed within 5 mins, it will re-fetch and suspend
below the nearest loading.js
- after those 5 mins, it will re-fetch the full content (with a new
loading.js boundary)
  - `prefetch={false}`:
    - the router will not prefetch anything
    - if accessed within 30s again, it will re-use the page
    - after that, it will re-fetch fully
  - `prefetch={true}`
- this will prefetch the full content of your page, dynamic or static
    - if accessed within 5 mins, it will re-use the page

## Follow ups

- we may add another API to control the cache TTL at the page level
- a way to opt-in for prefetch on hover even with prefetch={false}


<!-- 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 or adding/fixing 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 #

-->

link NEXT-1011
2023-04-21 14:29:39 +02:00
Sebastian Silbermann
db0086703e
Upgrade @types/react to latest 18.x (#48645)
Required for  https://github.com/vercel/next.js/pull/48641

[React 18 types
changelog](https://github.com/DefinitelyTyped/DefinitelyTyped/pull/56210)

Revealed some bugs in `React.Children` typings that were hidden due to
`{}` being part of `ReactNode` before 18.x types.
The rest is mostly missing `children` props types.
2023-04-21 09:33:23 +00:00
Jiachi Liu
cc684d02bc
Add export runtime test for pages and fully remove experimental.runtime (#48630)
### What 

`export const runtime = 'experimental-edge'` also work for pages. This
PR add tests for that.

Closes NEXT-426

Follow up for #46631 that to fully remove all related code of the
`experimental.runtime`
2023-04-20 22:37:38 +00:00
vercel-release-bot
682fb27ab4 v13.3.1-canary.17 2023-04-20 22:14:05 +00:00
JJ Kasper
652ba8a0ec
Fix version bump 2023-04-20 17:47:31 -04:00
Tobias Koppers
a7b0ae3c3c
implement /_next/image for local requests (#48622)
### What?

Adds image optimization to the next/image api for local requests

### Why?

More similarity to production. Smaller image downloads from the browser

### How?

see also https://github.com/vercel/turbo/pull/4649

fixes WEB-935

### Turbopack updates

* https://github.com/vercel/turbo/pull/4650 <!-- Tobias Koppers - reduce
size of TypeType from 32bytes to 16bytes -->
* https://github.com/vercel/turbo/pull/4648 <!-- Tobias Koppers - handle
chunk register in the sync runtime.none correctly -->
* https://github.com/vercel/turbo/pull/4609 <!-- OJ Kwon -
fix(ecmascript): eval assignop to the ident -->
* https://github.com/vercel/turbo/pull/4652 <!-- Tobias Koppers - allow
to pass constant values to free var references -->
* https://github.com/vercel/turbo/pull/4649 <!-- Tobias Koppers - Image
processing improvements -->
2023-04-20 20:03:44 +02:00
Tobias Koppers
ec385decd3
replace defined values and add __NEXT_HAS_REWRITES define (#48628)
### What?

This fixes a problem when the router fails to load the correct JS file
from the page_loader and opts out to full refresh

### Why?

The router behaves incorrect when `__NEXT_HAS_REWRITES` is missing in
turbopack

### How?

see also https://github.com/vercel/turbo/pull/4652

### Turbopack changes

* https://github.com/vercel/turbo/pull/4650 <!-- Tobias Koppers - reduce
size of TypeType from 32bytes to 16bytes -->
* https://github.com/vercel/turbo/pull/4648 <!-- Tobias Koppers - handle
chunk register in the sync runtime.none correctly -->
* https://github.com/vercel/turbo/pull/4609 <!-- OJ Kwon -
fix(ecmascript): eval assignop to the ident -->
* https://github.com/vercel/turbo/pull/4652 <!-- Tobias Koppers - allow
to pass constant values to free var references -->
* https://github.com/vercel/turbo/pull/4649 <!-- Tobias Koppers - Image
processing improvements -->
2023-04-20 20:02:39 +02:00
Leah
8ab6c4ca92
Exclude app from _devPagesManifest.js in turbopack (#48633)
### What?
Seems I accidentally included the app root when I initially added it,
but apps never have a page loader, so they should be excluded

I also cleaned up the manifest a bit, and it now perfectly matches the
one in next.js


Fixes WEB-926
2023-04-20 18:23:07 +02:00