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
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.
* 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`
### 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>
## 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.
### What?
incjects the script tag for CSS reloading
### Why?
### How?
Closes WEB-1851
---------
Co-authored-by: Will Binns-Smith <wbinnssmith@gmail.com>
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.
### 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
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 #
-->
### 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
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`.
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
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.
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>
### 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
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)).
### 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>
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.
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.
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
}
}
```