Commit graph

10257 commits

Author SHA1 Message Date
Jiachi Liu
9c87ea5a3d
Fix logging removed experiments in start logs (#57373)
Do not log the removed experiments in the start server logs, for instance `experimental.appDir` should get warned as unexpected option but it's not the valid experiment anymore
2023-10-25 16:08:14 +00:00
Tim Neutkens
d8160e0541
Ensure unstable_cache revalidate option enables ISR (#57390)
Noticed that if you use `unstable_cache` it did not opt-in to ISR even though fetch() does opt-in. This ensures the prerender-manifest holds the revalidate value.
2023-10-25 15:31:08 +00:00
Jiachi Liu
305bb01506
Refactor swc options (#57369)
* Rename swc option `is_server` to `is_server_compiler`
* Rename swc plugin `config.is_server` to `config.is_react_server_layer`
* Remove unused `bundle_target`, which could be covered by composing `is_server_compiler` and `is_react_server_layer`
2023-10-25 06:51:17 +00:00
Justin Ridgewell
656202fe0c
turbopack: Implement Server Actions from Client Components (#57391)
### What?

This completes Turbopack's Server Actions implementation!

It also cleans up several things:
- Removes `server_actions` configuration, it's enabled by default now.
- Fixes the transform that runs in the SSR layer (it actually needs to
use the client transform)
- Generates a new encryption key

### Why?

### How?

It crawls the client layer modules for additional Server Actions
imports, and adds them to our generated `actions.js` entry point.

Closes NEXT-
Fixes #


Closes WEB-1854

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2023-10-24 23:16:59 -07:00
Tom Occhino
1038fd53ef
Add websocket to server-external-packages (#57389)
Ensures websocket does not get bundled by Webpack/Turbopack.
2023-10-25 05:39:38 +00:00
Jiachi Liu
a301eb6a9f
Viewport exports (#57302)
## Story Time

Metadata API introduced two exports `metadata` and `generateMetadata` to the pages and layouts under app router, as partial prerendering work is going on and people are desiring to render the metadata asynchronizly, this change will be the preparation for moving to the dynamic & asynchronized land. In short, if we can render the metadata asynchronizedly, it will benefit the performance of the initial page loading and client page transiation a lot. Any slow data fetching can be handled while the essential page "shell" is rendered. 

For meta tags, there're few ones will visually affect your web page, such as `<meta name="viewport">`, `<meta name="theme color">` and `<meta name="color-scheme">`, rendering them lately after the page frame is ready might bring flickering to the page such as revreting whole page's theme color or shaking due to viewport updates. Those meta are not majorly the "metadata" for SEO, but more for user experience when opening the page. If we're rendering everything as async meta tags, it won't be ideal due to the flickering on your web pages.

## Solution Preparation 

We'll want to render the meta tags separately to make sure the visual ones are rendered as blocking along with web page, and then the ones for SEO or bots can be flushed later by later, like a suspense boundary keeps emitting them into the head of html. 

We optionally picked up 3 meta tag "viewport", "theme-color" and "color-scheme" to be render first into the web page with html "shell", to guarantee the layout viewport and basic styling are rendered first.

This PR introduced two module export in the page and layout files: `viewport` and `generateViewport`, in order to separate the visual meta tags from the SEO metadata.

### API

```ts
// page.js | layout.js
export const viewport = {
  // viewport meta tag
  width: 'device-width',
  initialScale: 1,
  maximumScale: 1,
  interactiveWidget: 'resizes-visual',
  // visual meta tags
  colorScheme: 'dark',
  themeColor: { color: 'cyan', media: '(prefers-color-scheme: dark)' },
}
```

There's also a dynamic API like what we did for metadata API

```ts
// page.js | layout.js
export function generateViewport() {
   return { ... }
}
```

## Notice 

This PR won't get SEO metadata rendered asyncronizedly, instead it's a preparation for the later work in partial prerendering and async metadata. We'll encourage the Next.js community moving to the new metadata viewport API if you're customzing those 3 meta tags. Usually you don't have to change viewport itself, so mostly like only theme-color and color-scheme could relate to it.
2023-10-25 05:20:23 +00:00
Tobias Koppers
18fe1eb4e9
Turbopack: inject chunk group list file into the page for server component CSS (#57376)
### What?

incjects the script tag for CSS reloading

### Why?

### How?


Closes WEB-1851

---------

Co-authored-by: Will Binns-Smith <wbinnssmith@gmail.com>
2023-10-24 20:06:46 -07:00
Shu Ding
59ebfbea9e
Fix request body hanging when middleware is preset (#57381)
Instead of `Readable.toWeb` we're gonna manually convert the Node.js stream to a Web stream. `toWeb` is either having a bug, or not compatible with middleware-cloned `PassThrough` streams.

Closes #56286. The case should be already covered with existing tests.
2023-10-25 02:44:10 +00:00
Shu Ding
8158262960
Refactor code (#57382)
The conditions are not used and the function can be simplified.
2023-10-25 02:35:14 +00:00
vercel-release-bot
1d8764cd1b v13.5.7-canary.25 2023-10-24 23:22:49 +00:00
vercel-release-bot
2b2ad9c7c4 v13.5.7-canary.24 2023-10-24 22:05:40 +00:00
OJ Kwon
8b083c30dd
fix(next-core): apply correct jsx transform context for ssr (#57300)
### What

Running `test/e2e/app-dir/emotion-js/index.test.ts` fails with turbopack as emotion skips necessary runtime transforms for the styles. Digging further, it was due to not applying correct importSource for the transform (`@emotion/react`) against ssr component when running with turbopack. Peeking next-dev, we apply `client` side context if issuer layer origin is either ssr or pages for the browser while turbopack doesn't.

PR uses `type` for the module context as equivalent to the issuer layer, and then apply client context for the transform for those modules.

`test/e2e/app-dir/emotion-js/index.test.ts` is passing with this PR.

Closes WEB-1834
2023-10-24 21:38:20 +00:00
Jimmy Lai
1d185c0707
perf: avoid using raw-body for server actions (#57358)
This PR removes the usage of `raw-body` for App Router pages by parsing
the body for an action ourselves whilst assuming that it is encoded with
UTF-8. This is already what we do for the Edge Runtime version of Server
Actions and will only break if your page overrides the page encoding,
which should not happen and that we don't need to support.

This should remove a third of a serverless function zip size 


<!-- 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-24 14:15:04 -07:00
OJ Kwon
cad1200131
fix(next_core): align remove trailing slash (#57344)
### What

minor fix to match behavior to ae10b5c82b/packages/next/src/shared/lib/router/utils/remove-trailing-slash.ts (L2C4-L9)

as we're seeing a panic when route is /

```
Panic: PanicInfo { payload: Any { .. }, message: Some(byte index 1 is out of bounds of ``), location: Location { file: "packages/next-swc/crates/next-core/src/next_edge/route_regex.rs", line: 202, col: 59 }, can_unwind: true, force_no_backtrace: false }
Backtrace:    0: backtrace::backtrace::libunwind::trace
```

Closes WEB-1841
2023-10-24 19:56:55 +00:00
Shu Ding
7aef93dd14
Get rid of semver from the server bundle (#57321)
This is a 6.6kB (gzipped) win for the Node.js worker size baseline. `jsonwebtoken` uses semver to ensure that the Node.js version is larger than `16.9.0` (which is always true with Next.js) so we can just alias it to be a noop function that returns `true`.
2023-10-24 18:05:56 +00:00
Jiachi Liu
8734a03ff5
fix metadata url resolving with path posix (#57343)
x-ref: [https://dev.azure.com/nextjs/next.js/_build/results?buildId=71881&view=logs&jobId=8[…]-584d-6f5c-57bad8880974&t=7ae70e63-3625-50f4-6764-5b3e72b4bd7a](https://dev.azure.com/nextjs/next.js/_build/results?buildId=71881&view=logs&jobId=8af7cf9c-43a1-584d-6f5c-57bad8880974&j=8af7cf9c-43a1-584d-6f5c-57bad8880974&t=7ae70e63-3625-50f4-6764-5b3e72b4bd7a)

Follow up for: https://github.com/vercel/next.js/pull/57265
2023-10-24 17:16:25 +00:00
JJ Kasper
ae10b5c82b
Fix app ISR error handling (#57332)
This ensures when an error occurs during a revalidate in app router that
properly throw the error fully and don't store the error page in the
cache which matches the expected behavior for full route ISR as errors
are not meant to update the cache so that the last successful cache
entry can continue being served.

Fix was tested against the provided reproduction here
https://app-dir-example-ghl01cxtn-basement.vercel.app/

Fixes: https://github.com/vercel/next.js/issues/53195
2023-10-24 09:38:30 -07:00
Zack Tanner
63aa0fe8ac
taint flag should enable experimental react in turbopack (#57315)
Matches behavior here: https://github.com/vercel/next.js/blob/canary/packages/next/src/lib/needs-experimental-react.ts#L4
2023-10-24 16:37:37 +00:00
Wyatt Johnson
741a08bc25
fix: ensure generateStaticParams isn't required for PPR (#57333) 2023-10-24 14:18:11 +00:00
Wyatt Johnson
06b9fb7bb8
PPR Support (#57319) 2023-10-24 09:23:52 +00:00
vercel-release-bot
2fc2a52652 v13.5.7-canary.23 2023-10-24 08:22:51 +00:00
JJ Kasper
5428e5a7a1
Fix trace ignores (#57331)
Fixes some of the ignores that were moved around in
https://github.com/vercel/next.js/pull/57280

x-ref:
https://github.com/vercel/vercel/actions/runs/6620930801/job/17989126942?pr=10756
2023-10-24 00:43:34 -07:00
Donny/강동윤
2b16a745ae
feat: Add __nextjs_pure back (#57328)
### What?

Add a magic to next-swc, agina.


### Why?

It's required, but it causes some issues with build process.

### How?



Closes WEB-1838
2023-10-24 07:29:24 +00:00
Wyatt Johnson
c05a11924d
PPR Fetch Fix (#57327) 2023-10-24 06:48:26 +00:00
Zack Tanner
56d74f42f4
bundle analyzer artifacts (#57307)
This uploads bundle analyzer artifacts during CI
2023-10-24 05:48:41 +00:00
vercel-release-bot
c77fec827f v13.5.7-canary.22 2023-10-24 05:34:15 +00:00
JJ Kasper
2275bf1a22
Revert "Add __nextjs_pure helper " (#57318)
This seems to be causing our Windows x86_64 next-swc build to stall for
some reason so reverting so we can unblock canaries while we investigate
further

Reverts vercel/next.js#57286

x-ref:
https://github.com/vercel/next.js/actions/runs/6620707993/job/17986458061
x-ref:
https://github.com/vercel/next.js/actions/runs/6620707993/job/17986458061
2023-10-23 22:06:36 -07:00
JJ Kasper
8b01e2578e
Fix nested unstable_cache revalidating (#57316)
This ensures when we call `revalidateTag` and there are nested `unstable_cache` entries we properly revalidate.
2023-10-24 05:01:00 +00:00
Tobias Koppers
a929bf7c04
update turbopack and add HMR test case (#57304)
### What?

adds a test case for HMR, which is fixed by the turbopack update

### Why?

### How?

### Turbopack Changes

* https://github.com/vercel/turbo/pull/6245 
* https://github.com/vercel/turbo/pull/6212 
* https://github.com/vercel/turbo/pull/6255 
* https://github.com/vercel/turbo/pull/6259 
* https://github.com/vercel/turbo/pull/6261 
* https://github.com/vercel/turbo/pull/6260 

Closes WEB-1836
2023-10-24 04:38:05 +00:00
vercel-release-bot
96337342e4 v13.5.7-canary.21 2023-10-24 03:58:21 +00:00
JJ Kasper
ec4e32c764
Fix no-store/revalidate 0 inside of unstable_cache (#57313)
This ensures we don't unexpectedly error when a fetch attempts to cache
inside of `unstable_cache`, this also ensures `only-on-store` doesn't
unexpectedly error when `revalidate: 0` is set.
2023-10-23 20:52:56 -07:00
Jimmy Lai
cb5d075758
misc: fix bundling of experimental (#57311)
this removes the call to experimental static react when not using the experimental build
2023-10-24 03:30:08 +00:00
Shu Ding
4eaefbab66
Optimize server bundle size (#57305)
These are not used by the Next.js server and can save up to 15% size of the base Edge worker by ignoring them.
2023-10-24 02:18:27 +00:00
Wyatt Johnson
69388a52fe
Partial Prerendering (#57287)
This PR introduces a build optimization to create a "partial prerender" of the page.

1. During compilation, we create a static shell for the page using your existing Suspense boundaries. Components that can be static will be included in this static shell, leaving holes for the dynamic components.
1. Using `<Suspense />`, we can define fallbacks to be included in the partial prerender, as well as the holes for the dynamic components to stream into.

This means Next.js can initially serve a static loading skeleton, kicking off the dynamic parts in parallel. Then, the dynamic components stream in on demand. Dynamic components can use `cookies()`, `headers()`, `'cache': 'no-store'`, or `unstable_noStore()` to opt-into dynamic rendering.

Co-authored-by: Zack Tanner <1939140+ztanner@users.noreply.github.com>
2023-10-24 01:13:05 +00:00
Leah
679a398e49
fix(turbopack): write manifests for edge app pages and use proper edge entry (#56675)
### Description

- We previously didn't write to the shared `middleware-manifest.json` for edge app pages
- We also need to manually write to the `_ENTRIES` object in turbopack entries because it currently doesn't have a way to change the output type like webpack: https://webpack.js.org/configuration/output/#type-assign-properties
- Also need to write a bunch of manifests as JS files to be able to load them from the edge runtime.
- Some import map fixes were needed as well.

This only fixes dev, build will need more work.

Closes WEB-1698
2023-10-24 00:47:55 +00:00
vercel-release-bot
dc7b5d806e v13.5.7-canary.20 2023-10-24 00:35:28 +00:00
Shu Ding
78ffea42ee
Fix client reference proxies (#57301)
Each individual exported component should be a proxied reference. Not sure why it's been broken for so long and it didn't trigger any error.
2023-10-24 00:24:22 +00:00
Jimmy Lai
ce085b56dd
revert "React Aliases (#57283)" (#57299)
This reverts commit 9f512f1cca.

<!-- 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: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2023-10-23 16:59:55 -07:00
Zack Tanner
b1d1ed6087
only log export-no-custom-routes warning if unsupported (#57298)
This doesn't need to error, we can instead warn that the functionality will not work as expected out of the box. Support can be added for outside of Next for this to behave as expected. 

These are supported when deployed via the Nextjs builder ([x-ref](https://github.com/vercel/vercel/blob/main/packages/next/src/index.ts#L851-L855)).
2023-10-23 23:58:41 +00:00
Donny/강동윤
4bbf9b6c70
Add __nextjs_pure helper (#57286)
### What?

Safely drop `__nextjs_pure` from next internals in transform

```js
import {__nextjs_pure} from 'next/dist/build/swc/helpers'

__nextjs_pure(console.log("test!"))


```

becomes


```js
/*#__PURE__*/ console.log("test!");

```

so it will be dropped by the minifier - terser and swc minifier will
both work.

### Why?

Adding pure comments from JS world with swc transform is complex. This
would be a helper for the case if we want to create "pure" expressions.


### How?



Closes WEB-1829

---------

Co-authored-by: Jiachi Liu <inbox@huozhi.im>
2023-10-23 16:44:44 -07:00
vercel-release-bot
7c803a762e v13.5.7-canary.19 2023-10-23 23:24:21 +00:00
Shu Ding
661c598a21
Improve encryption of Server Actions bound values (#57297)
Removes the constant prefix and action ID from the IV value and makes it a fully random string. Then, we prefix the actual payload with the action ID to avoid submitting the payload from a different action, as well as using it as the checksum of the encryption data to ensure it's not damaged.
2023-10-23 23:18:49 +00:00
Andrew Clark
a77acd22ad
Update React from d803f519e to b8e47d988 (#57296)
React upstream changes:

- https://github.com/facebook/react/pull/27570
- https://github.com/facebook/react/pull/27569
- https://github.com/facebook/react/pull/27550
- https://github.com/facebook/react/pull/27559
- https://github.com/facebook/react/pull/27552
- https://github.com/facebook/react/pull/27504
- https://github.com/facebook/react/pull/27522




Co-authored-by: Josh Story <2716369+gnoff@users.noreply.github.com>
2023-10-23 22:58:50 +00:00
vercel-release-bot
8fb5c8517f v13.5.7-canary.18 2023-10-23 22:17:01 +00:00
Jimmy Lai
9e050fba94
perf: remove parse-body from the server runtime (#57280)
This PR removes the `raw-body` dependency from the server runtime. It
still is used in the pages runtime but at least if you're only using
app, you won't bundle your server function with it.

<!-- 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-23 15:11:09 -07:00
Wyatt Johnson
9f512f1cca
React Aliases (#57283)
This adds aliases to the new react packages being used by Next.js.
2023-10-23 21:04:26 +00:00
Wyatt Johnson
4661764621
Enhance Buffered Transform Stream (#57267)
This adds some better handling around the buffered transform streams to handle error cases a bit better.
2023-10-23 20:05:57 +00:00
Wyatt Johnson
f154bb8313
Revalidate Header Updates (#57162)
Update the revalidate handling to perform the revalidate option coalescing in the render function closer to the render result output. This helps reduce the amount of scope leak from the render.
2023-10-23 19:37:46 +00:00
Jiachi Liu
cc4cceb4f0
Polish compiling and turbopack logging (#57270)
## Make server info log faster

Change to display the server info earlier before server handler is ready

## Make "compiling" message less laggy.

Change to log the compiling logs as previous timer which trying to skip the logging short-time compiling message makes it bit laggy, so we're removing it for now. Reduce the timer from 3s to 500ms

<img width="360" alt="image" src="https://github.com/vercel/next.js/assets/4800338/19afb2d6-ec42-4a67-b664-60f8c36b5287">


## Remove the turbopack

### Now
<img width="398" alt="image" src="https://github.com/vercel/next.js/assets/4800338/fb24d83f-66d0-4383-a42b-fdeff4fe223a">

### Before

<img width="398" alt="image" src="https://github.com/vercel/next.js/assets/4800338/59d6a6f2-32d6-41d1-a80d-12c599165e6a">
2023-10-23 19:28:36 +00:00
Jiachi Liu
4e1429182f
Move logging option to stable (#56791)
We introduced a data fetching logging before, and the control option was under experimental. After a bit experiments turns out users really loves it. We decide to move it to a stable option.

### Changes
We're going to move the `logging` option outside of `experimental`, and scope the `fetches` related config under `logging.fetches`.

```js
// next.config.js
logging?: {
    fetches?: {
      fullUrl?: boolean
    }
}
```
2023-10-23 18:45:00 +00:00