Commit graph

16784 commits

Author SHA1 Message Date
Cheol-Won
82efdfe877
docs : fix typo in React cache example (#52787)
### Description
This PR fix typo in the description of Caching Data

### Changes
- Added types to React `cache()` exercise

File: `docs/02-app/01-building-your-application/03-data-fetching/02-caching.mdx`
2023-07-17 15:46:30 +00:00
vinay
503677c099
(Docs) add missing js version for generateMetadata. (#52763)
There was no JS version for `generateMetadata` function.

fixes #52759 

Co-authored-by: Steven <229881+styfle@users.noreply.github.com>
2023-07-17 15:23:54 +00:00
Tim Neutkens
f5f79e7a8c
Update mention of route handlers for forms (#52781)
Route handlers are not specifically different from API Routes in terms of forms or other usage, the only difference is how you write them (Request) => Response. Initially this mention was supposed to be removed when server actions are marked stable, but it's leading to some confusion so I've updated the mention to clarify that there will be a more integrated solution for React.
2023-07-17 14:11:42 +00:00
Balázs Orbán
539ae6c1fc
fix(output): do not slice pathname unless ends with .txt (#52640)
### What?

When using `output: "export"`, all URL pathnames are sliced.

### Why?

A regression was introduced at
https://github.com/vercel/next.js/pull/50974/files#diff-7b6239af735eba0c401e1a0db1a04dd4575c19a031934f02d128cf3ac813757bR76-R80

### How?

Check if a pathname ends with `.txt` before slicing the end.

Fixes #52381
2023-07-17 11:29:24 +02:00
Jeffrey Zutt
6b2aed12d7
fix: forward NavigateOptions in adaptForAppRouterInstance (#52498)
### Fixing a bug

### What?

App-router now supports the
[`scroll`-option](https://github.com/vercel/next.js/pull/51869/files).
Thank you for that!
We're in the midst of migrating towards the app-router meaning that some
pages use the `adaptForAppRouterInstance`-adapter.

We noticed that the adaptForAppRouterInstance does not forward any
options given to either `push` or `replace`, while in theory `{ scroll?:
boolean }` perfectly overlaps and could be forwarded.

### Why?

When using `{ scroll: false }` and using `adaptForAppRouterInstance` the
options are not being forwarded.
Meaning that when calling either `push` or `replace`, the page is
scrolled to the top regardless.

### How?

By forwarding the options that perfectly overlap between
`NavigateOptions` (app-router) and `TransitionOptions` (next-router)

```
// Added NavigateOptions, and forward `{ scroll }`

push(href: string, { scroll }:NavigateOptions = {}): void {
      void router.push(href, undefined, { scroll }) // 
},
replace(href: string, { scroll }:NavigateOptions = {}): void {
      void router.replace(href, undefined, { scroll })
},
```

Please let me know if I need to change anything!

Co-authored-by: Jeffrey <jeffrey@jeffreyzutt.nl>
Co-authored-by: Jimmy Lai <laijimmy0@gmail.com>
2023-07-17 10:04:57 +02:00
JJ Kasper
dc6c22c991
Fix runtime edge not-found handling (#52754)
This ensures we properly detect `not-found` as `runtime = 'edge'` and treat it as such instead of attempting to render it like normal. 

x-ref: https://github.com/vercel/next.js/issues/52648
2023-07-16 22:21:29 +00:00
Alex Kirszenberg
5964b289e1
Turbopack: Vc<T> and Turbo Engine type system improvements (#51792)
This is the Next.js side of https://github.com/vercel/turbo/pull/4587, which makes changes to Turbo Engine to allow expressing value cells as `Vc<Type>` instead of `TypeVc`, leveraging the type system to bring a slew of other improvements to writing Turbo Engine code.

## Turbopack updates

* https://github.com/vercel/turbo/pull/4587
2023-07-16 13:56:20 +00:00
OJ Kwon
7ce663ed52
feat(next-swc): try to fallback native bindings with MODULE_NOT_FOUND (#52667)
### What?

closes WEB-1287.

This PR is a stopgap workaround for https://github.com/npm/cli/issues/4828. There is ongoing discussion & RFC, but it is unclear when we can have those. Until then, PR tries to attempt to load native bindings by manually downloading binaries if original attempt fails with MODULE_NOT_FOUND.

The implementation basically reuses most piece of existing wasm fallback; differences are it tries to all possible triples instead, and also try only for MODULE_NOT_FOUND. Other errors are treated as legit error from installed binary, do not attempt to re-download.
2023-07-15 00:46:34 +00:00
Balázs Orbán
81dd7f8077
chore: add "please simplify reproduction" comment (#52631)
### What?

Adding a new label comment for "please simplify reproduction".

### Why?

During triaging, a lot of time is gone into trying to isolate the actual bug being reported. Reproductions sometimes contain unrelated code - that sometimes can be the actual cause of an issue, reported as a bug in Next.js, or require third-party services, secrets, setting up databases, and other tasks that take up much of the resources before the issue can even be verified.

### How?

Similar to the `please add a complete reproduction` and `please verify canary` labels, if a maintainer adds the `please simplify reproduction` label, an automatic comment will appear on the issue, asking for a minimal reproduction

[Slack thread](https://vercel.slack.com/archives/C04DUD7EB1B/p1685527818400339)
2023-07-14 23:30:42 +00:00
Jiachi Liu
a28ae633e4
Support metadata exports for server components not-found (#52678)
### What?

Support metadata exports for `not-found.js` conventions

### Why?

We want to define metadata such as title or description basic properties for error pages, including 404 and 500 which referrs to `error.js` and `not-found.js` convention. See more requests in #45620 

Did some research around metadata support for not-found and error convention. It's possible to support in `not-found.js` when it's server components as currently metadata is only available but for `error.js` it has to be client components for now so it's hard to support it for now as it's a boundary.

### How?

We determine the convention if we're going to render is page or `not-found` boundary then we traverse the loader tree based on the convention type. One special case is for redirection the temporary metadata is not generated yet, we leave it as default now.

Fixes #52636
2023-07-14 22:33:47 +00:00
Steven
c3ca17cf02
fix: add missing <preload> for next/image in App Router (#52425)
- Depends on https://github.com/facebook/react/pull/27096
- Fixes #43134 
- Closes NEXT-811
- Closes NEXT-846
2023-07-14 15:36:35 +00:00
Jiachi Liu
d10f105b74
Fix icons metadata missing from layout (#52673)
### What

This was an issue introduced in #52416 when we check the images and icons property while merging with static file conventions. Where we should check if the properties are present but we only checked if they value is falsy. So when you're using `icons` with array value it breaks.

Now we properly check all the possible case of `metadata.icons` value, so then decide if we are using the static file convention or the icons property of defined metadata.

Also add few more tests cases to cover icons resolving.
2023-07-14 12:04:31 +00:00
Shu Ding
3763f4fbe1
Avoid verifying TS setup in render workers (#52676)
The router worker already verified TS setup, and there's no need to do it again in the other processes.

This saves ~110 ms dev startup time and 16.7 MB memory (59.9 MB → 43.2 MB) for the render worker when the project is using TS.
2023-07-14 11:30:08 +00:00
vercel-release-bot
c2a54aaecb v13.4.10 2023-07-14 09:14:17 +00:00
vercel-release-bot
62aa2d221c v13.4.10-canary.8 2023-07-14 01:51:38 +00:00
Shu Ding
b957f52be3
Fix per-entry client reference manifest for grouped and named segments (#52664)
References for Client Components need to be aggregated to the page entry level, and emitted as files in the correct directory for the SSR server to read from. For normal routes (e.g. `app/foo/bar/page`), we can go through and collect all entries (layout, loading, error, ...) from the current and parent segments, to aggregate all necessary client references.

However, for routes with special conventions like `app/(group)/@named/foo/bar/page`, it needs to be normalized (remove the named slot and group segments) so it can be grouped together with `app/(group)/@named2/foo/bar/loading`.
2023-07-14 01:18:37 +00:00
Jiachi Liu
79227ee74a
Catch layout error in global-error (#52654)
When there's a runtime error showing in root layout (server components), it should be able to catch by `global-error`.

For server components, we caught it and gonna render the error fallback components (either not-found or error page), and the response status is `200`, and since we'll display error dev overlay in developmenet mode so we only render `global-error` for production.

So that you can catch more errors with `global-error` and maybe do potential error tracking on client side.

Follow up of #52573
Closes NEXT-1442

minor refactor: move `appUsingSizeAdjust` into `Metadata` component so that we can just tune the flag as prop
2023-07-14 00:43:40 +00:00
vercel-release-bot
3cde104d64 v13.4.10-canary.7 2023-07-13 19:40:00 +00:00
Shu Ding
8822630dd6
Clean up promises after resolving (#52656)
Long-hanging promises are retaining the closure context where it's being
`await`'ed even it's resolved already. You can tell it from this
screenshot:

<img width="1822" alt="CleanShot 2023-07-13 at 18 09 11@2x"
src="https://github.com/vercel/next.js/assets/3676859/1d6210b0-16ba-440e-a8b6-c8c4343f4850">

In some cases, the entire `req` object is retained because of that. This
increases the memory usage a bit.

So this PR changes these promises to be cleaned up after they got
resolved.

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2023-07-13 19:41:04 +02:00
Tobias Koppers
ca1129c463
Turobpack: Next.rs API (part 1) (#52259)
### What?

Creates a NAPI api for Next.rs to be used in Next.js

### Why?

### How?



Co-authored-by: Alex Kirszenberg <1621758+alexkirsz@users.noreply.github.com>
2023-07-13 17:17:38 +00:00
Shu Ding
88084e6b7a
Fix bundle path normalization for /index routes (#52650)
We have some special bundle path handling logic for `/index` routes in
`normalizePagePath`, which is missing in the new
`AppBundlePathNormalizer`. This already broke `/index/page.js` in dev in
the past, and now become noticeable in prod as well because of the
manifest change.


b98469c86b/packages/next/src/shared/lib/page-path/normalize-page-path.ts (L5-L14)

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2023-07-13 17:36:43 +02:00
Jiachi Liu
9313c51bc4
Ensure root layout only render once per request (#52589)
Introduce a new way to search for `not-found` component that based on
the request pathname and current loader tree of that route. And we
search the proper not-found in the finall catch closure of app
rendering, so that we don't have to pass down the root layout to
app-router to create the extra error boundary.

This ensures the root layout doesn't have duplicated rendering for
normal requests

Fixes NEXT-1220
Fixes #49115
2023-07-13 17:34:31 +02:00
Steven
76cb8cf361
chore(deps): bump react@18.3.0-canary-9377e1010-20230712 (#52649)
### React upstream changes

- https://github.com/facebook/react/pull/27096
- https://github.com/facebook/react/pull/27069
- https://github.com/facebook/react/pull/27033
- https://github.com/facebook/react/pull/27061
- https://github.com/facebook/react/pull/27030
- https://github.com/facebook/react/pull/27056
2023-07-13 11:19:01 -04:00
Tobias Koppers
ee28f947fb
Turbopack: OutputAsset trait (#52606)
### What?

refactoring for cleaner typing of assets

see https://github.com/vercel/turbo/pull/5507
2023-07-13 13:26:15 +00:00
vercel-release-bot
c56915842a v13.4.10-canary.6 2023-07-13 02:16:14 +00:00
Jiachi Liu
76eec86a6b
Set sizes prop to any for svg icons (#52609)
For `link` tag's `sizes` property, the property is defined as:

> This attribute defines the sizes of the icons for visual media contained in the resource. It must be present only if the [rel](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link#rel) contains a value of icon or a non-standard type such as Apple's apple-touch-icon. It may have the following values:
`any`, meaning that the icon can be scaled to any size as it is in a vector format, like image/svg+xml.

x-ref: https://html.spec.whatwg.org/#attr-link-sizes
x-ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link (`sizes` property definition section) 

Closes #52002
Closes NEXT-133
2023-07-13 00:33:27 +00:00
su
4c4bee7112
Remove unnecessary body-parser (#52580)
Since the `body-parser`  middleware is already built-in `express.js` after v4.16.0, so we can clean some code
2023-07-12 23:11:20 +00:00
Anthony Shew
b89424e461
docs: Add missing closing tag for react hydration error message. (#52607) 2023-07-13 00:22:10 +02:00
Balázs Orbán
82cf9a670e
docs: move MUI to supported list (#52584)
fixes #52575

---------

Co-authored-by: Lee Robinson <me@leerob.io>
Co-authored-by: Alexandre Fauquette <45398769+alexfauquette@users.noreply.github.com>
Co-authored-by: Steven <steven@ceriously.com>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2023-07-12 12:50:20 -07:00
OJ Kwon
e1baffcec2
feat(turbopack): support native webp (#52285)
### What?

Closes WEB-1157. PR enables turbopack to support native webp encode / decode. There is one platform we can't support this (aarch64-linux-gnu) which disables those.
2023-07-12 19:42:41 +00:00
Wyatt Johnson
bb0fecc68f
Move App Pages rendering into bundle (#52290)
Transitions the App Pages renderer into the entrypoint bundle.

- Adjusts the static path detection to handle route module's with App Pages
- Fixes bug in font manifest loading on Edge
2023-07-12 18:28:06 +00:00
ilyamed
f321864c5e
docs: Fix typo in generate-static-params.mdx (#52595) 2023-07-12 17:11:16 +00:00
Cheol-Won
967c501c7b
docs: fix typo in CSS Modules Description (#52599)
## Description
Remove unnecessary type in the JSX file. Additionally, this change helps maintain consistency with the examples below

## References
[CSS Modules Description page link](https://nextjs.org/docs/app/building-your-application/styling/css-modules)
2023-07-12 16:59:49 +00:00
vercel-release-bot
22cb1bf027 v13.4.10-canary.5 2023-07-12 16:38:56 +00:00
OJ Kwon
d93231eb19
feat(next-swc): report native bindings load err code (#52570)
Related: https://github.com/vercel/next-telemetry/pull/106

We collect wasm fallback reason (`enabled`, `fallback`, ..) but it is bit unclear why we came to reach `fallback` state for the wasm. This PR expands current reporting to include native bindings error code if node.js returns it to understand categories better. Mostly this would be in between ERR_DLOPEN or ERR_MODULE_NOT_FOUND, but worth to confirm if the guess is correct. For the targets have multiple triples (gnu / musl), we collect only the last attempt's error code.

There are 2 custom variants of the string value other than err code itself: if thrown error doesn't have code (unlikely, but) it'll be `unknown`. for the targets we falls back to wasm immediately (freebsd, for example) it'll be marked as unsupported_target.

One thing to note is this does not collect if wasm binding fails to load: this is strictly for native bindings load error.
2023-07-12 16:30:20 +00:00
Fernand
1989f4943d
Fixed grammar in 03-react-essentials.mdx (#52597)
"will eventually be should be placed" was changed to "will eventually be placed".
2023-07-12 15:51:33 +00:00
Starunaway
3c3f50ddde
Update examples: counter.tsx - Don't need empty space (#52576)
Don't need empty space
2023-07-12 15:41:04 +00:00
Karl Horky
2b98f77887
Add more extensions to next-types-plugin for Node16/NodeNext (#52562)
### What? Why? How?

Similar to https://github.com/vercel/next.js/pull/47571, add `.js` extensions to generated imports to avoid problems with TypeScript `Node16` / `NodeNext` module resolution

Without this change, there are confusing errors with `{ experimental: { typedRoutes: true } }` in `next.config.js`, such as:

```
Property 'refresh' does not exist on type 'AppRouterInstance'.ts(2339)
```

<img width="490" alt="Screenshot 2023-07-11 at 19 12 21" src="https://github.com/vercel/next.js/assets/1935696/399265e6-223d-4386-bc85-6136d98e436a">

cc @shuding
2023-07-12 15:23:55 +00:00
Shu Ding
b7e2627422
Avoid loading Next.js config again in render workers (#52587)
This PR ensures that both Webpack and the config won't be initiated in render workers. This is great for performance but also avoids potential issues (e.g. Next.js plugin with side effects). Instead, we pass a serialized config from the router worker to the render workers.

Closes #52366.
2023-07-12 11:21:05 +00:00
Alex Kirszenberg
38dafa1609
Turbopack: App Router build POC (#52036)
This PR adds proof-of-concept support for the App Router to `next build
--experimental-turbo`.

It introduces a new way to generate Next.js manifests in Turbopack.
Currently, in dev, we pass proxy objects in lieu of manifests, and rely
on the entries to know which chunks they need loaded on the client.
However, this can't work for builds because it requires control over
Next.js rendering, which is not compatible with a Next->Turbo approach.
We would need to modify Next.js to support these "lazy" entries. So for
now, we add well-known assets (`NextDynamicAsset`,
`NextServerComponentAsset`, `NextClientReferenceAsset`, etc.) to the
graph, which will get picked up when walking it during asset processing.
This lets us collect all possible entries before chunking.

This two-step process (collecting all entries, then chunking them) is
also a good first step towards production chunking.

## Turbopack updates

* https://github.com/vercel/turbo/pull/5494 <!-- Tobias Koppers - add
reporting of console messages -->
* https://github.com/vercel/turbo/pull/5448 <!-- Alex Kirszenberg -
Misc. changes to support App Router build -->
2023-07-12 11:26:48 +02:00
Damien Simonin Feugas
4a14671fa6
fix(next/jest): jest can not load server-only code (#52393)
### 🧐 What's in there?

At the moment, it is not possible to test code with `import 'server-only'` in app directory.
When trying to load such file in jest (even with `testEnvironment: node`), the error will be:
```
      ● Test suite failed to run··
          x NEXT_RSC_ERR_CLIENT_IMPORT: server-only
           ,-[lib/util.js:1:1]
         1 | /** @jest-environment node */·
         2 |         import 'server-only'
           :         ^^^^^^^^^^^^^^^^^^^^
         3 |         export const PI = 3.14;
           `----·
          at Object.transformSync (node_modules/next/src/build/swc/index.ts:443:25)
          at transformSync (node_modules/next/src/build/swc/index.ts:629:19)
          at Object.process (node_modules/next/src/build/swc/jest-transformer.ts:117:25)
          at ScriptTransformer.transformSource (node_modules/@jest/transform/build/ScriptTransformer.js:619:31)
          at ScriptTransformer._transformAndBuildScript (node_modules/@jest/transform/build/ScriptTransformer.js:765:40)
          at ScriptTransformer.transform (node_modules/@jest/transform/build/ScriptTransformer.js:822:19)·
```

In a nutshell:
- next/swc is looking for ‘server-only’ [text in the source](https://github.com/vercel/next.js/blob/canary/packages/next-swc/crates/core/src/react_server_components.rs#L576), and throw if not configured for server
- next's jest-transformer will only configure next/swc for server [if the environment is node](https://github.com/vercel/next.js/blob/canary/packages/next/src/build/swc/jest-transformer.ts#L88)
- when testing Next.js apps, your jest testEnvironment is most likely jsdom. But you can configure it [per file with docBlock](https://jestjs.io/docs/configuration#testenvironment-string), which jest-transformer ignores because it only reads the top-level configuration.

This PR fixes this, by 
1. reading the docblock to configure next/swc accordingly and bypass its hardcoded guard
2. mocking `server-only` so [it does not throw](https://github.com/vercel/next.js/blob/canary/packages/next/src/compiled/server-only/index.js) when loaded (jest does not read `react-server` export from package.json)

Users would still have to annotate their `server-only` files with `/** @jest-environment node */` in order to test them.

### 🧪 How to test?

There's a full test available: `pnpm testheadless --testPathPattern jest/server-only`

Here is also a minimal reproduction:

<details>
    <summary>app/layout.tsx</summary>

```typescript
export default function RootLayout({ children }: { children: React.ReactNode }) {
  return (<html lang="en"><body>{children}</body></html>)
}
```
</details>

<details>
    <summary>app/page.tsx</summary>

```typescript
import { PI } from '@/lib/utils'

export default function Home() {
    return <h1>{PI}</h1>
}
```
</details>

<details>
    <summary>lib/utils.ts</summary>

```typescript
import 'server-only'

export const PI = 3.14
```
</details>

<details>
    <summary>lib/utils.test.ts</summary>

```typescript
import { PI } from './utils'

it('works', () => expect(PI).toEqual(3.14))
```
</details>

<details>
    <summary>jest.config.js</summary>

```typescript
const nextJest = require('next/jest')

module.exports = nextJest({ dir: './' })({ testEnvironment: 'jsdom' })
```
</details>

###  Notes to reviewers

[jest-docblock](https://packagephobia.com/result?p=jest-docblock) with dependencies is only 12.5 kB.


Fixes #47448
2023-07-12 08:51:29 +00:00
vercel-release-bot
2441ad4760 v13.4.10-canary.4 2023-07-12 06:45:31 +00:00
JJ Kasper
0600293b03
Fix ISR case with bot requests (#52581)
This ensures we don't bail from static generation unexpectedly due to a
bot request as this shouldn't affect ISR handling.

Test deployment with patch can be seen here
https://test-app-isr-fallback-dwn2neok6-vtest314-ijjk-testing.vercel.app/new

Fixes: https://github.com/vercel/next.js/issues/47805
2023-07-11 23:39:50 -07:00
Jiachi Liu
b9760b2910
Support global-error for ssr fallback (#52573)
Previously `global-error` only caught the error on client side, this PR adds the support for catching the errors thrown during client components SSR or server components RSC rendering.

Closes #46572
Closes #50119
Closes #50723
2023-07-12 01:54:07 +00:00
Jiachi Liu
bcd9136b98
ci: skip build-native for docs only change (#52571) 2023-07-12 00:08:22 +00:00
Josh Story
6839ef379b
use npm pack instead of yarn pack (#52563)
`yarn pack` does not pack the same way that `npm pack` does. There is at least one bug with how files are treated where node_modules are ignored even inside folders defined by the files config. While this is not currently used in next.js an upcoming change will rely on it. The reason this change makes sense otherwise is we use npm to publish next and during a publish the pack from npm is used. For consistency we should use the same pack for our actions and other code that does repo setup such as `create-next-install` which is used for tests

The implementation is slightly more complicated than just replacing the pack command however. `npm pack` respects gitignore files whereas `yarn pack` does not (or at least not nested ones). For some packages the `"files"` property in package.json is set which overrides any gitignore rules however the `@next/swc` package uses a gitignore to prevent the committing of native binaries but does not use files and thus npm pack does not includes native binaries when yarn pack does. To address this the PR adds a temporary rename of the `next-swc/native/.gitignore` file which allows npm pack to mimic the yarn pack behavior. The reason I did not just add `"files"` is that this package actually publishes to many different package names on npm for each architecture and I was unsure about making changes to the package.json that would potentially affect this codepath.

In addition to those changes there are 2 `.gitignore` files that appear to be outdated and unnecessary. I removed them.
2023-07-11 23:36:07 +00:00
OJ Kwon
9b932cc135
feat(babel-loader): provide migration help message for babel config (#52565)
### What?
Attempt to close WEB-1074.

PR tries to validate custom babel config: if it only contains options supported by latest next.js compiler features, trying to suggest to migrate / enable native compiler instead of babel.
2023-07-11 23:01:09 +00:00
OJ Kwon
09ef9b48d7
feat(turbopack): support swc transform plugins (#50401)
### What?
WEB-998

This PR enables experimental swc transform plugin support in turbopack.
2023-07-11 22:19:36 +00:00
Daryll J. Reillo
3338df187c
docs: fix grammar on Server Actions (#52556) 2023-07-11 11:11:58 -07:00
JJ Kasper
fab164dcc8
Update id handling for fonts (#52559)
We don't need to apply the ID here as these assets should always be available across deploys. 

x-ref: [slack thread](https://vercel.slack.com/archives/C03KAR5DCKC/p1689035592272659)
2023-07-11 17:14:25 +00:00