Commit graph

7891 commits

Author SHA1 Message Date
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
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
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
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
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
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
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
vercel-release-bot
63a6cdaf53 v13.4.10-canary.3 2023-07-10 23:02:55 +00:00
Florentin / 珞辰
0648a109eb
add version to function config manifest (#52507)
Adds `version` to function config manifest as suggested in https://github.com/vercel/vercel/pull/10069#discussion_r1255021336
2023-07-10 20:28:59 +00:00
Shu Ding
d175aea210
perf: Refactor recursiveReadDirSync (#52517)
- Use `opendirSync` instead of `readdirSync`
- Use `.slice` instead of `.replace` as the rootDir

Before (1.54ms):

![CleanShot 2023-07-10 at 18 33 23@2x](https://github.com/vercel/next.js/assets/3676859/829e0a49-35da-4754-bc3f-6fe243e815f4)

With the change (0.88ms):

![CleanShot 2023-07-10 at 18 47 43@2x](https://github.com/vercel/next.js/assets/3676859/cabe1fdd-5861-49ba-8c8d-b505c16fbf7a)

This scales when public/ folder grows.
2023-07-10 17:51:42 +00:00
SleeplessOne1917
0ce55e3f09
Chore: Remove redundant intersection type (#52453)
### What?
The type definition of `ImgProps` is the following:
```typescript
export type ImgProps = Omit<ImageProps, 'src' | 'alt' | 'loader'> & {
  loading: LoadingValue
  width: number | undefined
  height: number | undefined
  style: NonNullable<JSX.IntrinsicElements['img']['style']>
  sizes: string | undefined
  srcSet: string | undefined
  src: string
}
```

`ImgProps` is then used as part of the definition of the `ImageElementProps` type. For the latter, `Omit<ImageProps, 'src' | 'alt' | 'loader'>` is intersected with `ImgProps` even though the intersection with that type is already part `ImgProps`'s definition. This PR removes the redundancy.

### Why?
I was looking at how Next.js implemented it's optimized image component to create something similar for a WASM framework when I noticed this typing and got confused. I figured making a PR would be the polite thing to do.

### How?
Removed redundant part of type definition.
2023-07-10 16:48:02 +00:00
Jimmy Lai
810f0e8710
perf: create an experimental bundled version of the next server (#52206)
This PR:
- adds a minified bundled server for Next with some optimisations applied
- a test server in minimal-server.js
- misc changes:
   - makes some polyfills lazy
   - adds a cached version of node-html-parser
   -
2023-07-10 15:40:06 +00:00
vercel-release-bot
4e710645f8 v13.4.10-canary.2 2023-07-10 14:44:00 +00:00
Shu Ding
0fe6e850fe
Fix tracking of client reference manifest (#52505)
The problem was introduced in #52450, that the client reference manifest isn't being tracked and included in the function.

Verified that this fixes the issue.
2023-07-10 14:27:08 +00:00
Tim Neutkens
73e2979cb8
Ensure useParams return array for catch-all routes (#52494)
## What?

Ensures `useParams` matches `params` passed to the page, also matches the docs.

Fixes #50856
Fixes NEXT-1419
2023-07-10 12:04:44 +00:00
Yagiz Nizipli
85bca2e778
refactor: avoid unnecessary async scopes in eslint (#52418)
This pull request:
- removes unnecessary object copying in `hasEslintConfiguration`
- returns always `null` on `runLintCheck`, and make sure it does not return undefined.
- removes unnecessary async scope creation on `isDirectory`
2023-07-10 10:52:20 +00:00
Balázs Orbán
a06775cdf3
fix: add aws packages to default serverComponentsExternalPackages (#52388)
Related #51969

[Slack thread](https://vercel.slack.com/archives/C04DUD7EB1B/p1688734253149379?thread_ts=1688734176.782469&cid=C04DUD7EB1B)
2023-07-10 10:24:03 +00:00
Ngô Đức Anh
98cc99df46
fix(standalone): fixed output: "standalone" crashing build when there is no app/ page (#51993)
### What?
This PR fixes build crashing when `output: 'standalone'` and `experimental.appDir` is enabled but there is no app pages.

### How?
It does that by checking whether `.next/server/app` exists before copying the folder to `.next/standalone/...`

Closes #51828
Fixes #44442
Fixes #44120
2023-07-10 08:40:02 +00:00
vercel-release-bot
62c2c5abc2 v13.4.10-canary.1 2023-07-10 08:01:26 +00:00
Shu Ding
990c58c5ef
Split the client reference manifest file to be generated per-entry (#52450)
This PR changes client manifest generation process. Instead of one big
manifest file that contains client references for the entire app, we're
now generating one manifest file per entry which only covers client
components that can be reached in the module graph.
2023-07-10 09:48:03 +02:00
Jiachi Liu
85033e3add
Override file based images with social images property (#52416)
Metadata API should provide a way to override the filebased metadata
images. As usually for child routes, if there's new social images or
icons are provided, the ones from parent routes should be overridden /
skipped.

The `metadata` object export or `generateMetadata` should be able to do
that. Sometimes users still add other og info (besides images) to
metadata export (both object and `generateMetadata`).
I think we should check if they really have returned images property,
then decide to override.

- For the same level of routes:
- If there's no `openGraph.images` in the returned value, merge with
file based images
- If there's any `openGraph.images` in the returned value, ignore file
based ones

- For child level of routes:
Always override the parent level, ignoring parent level file based
images unless they use `generateMetadata` to merge from
`resolvingParentMetadata` value, then the parent level's file based ones
will present there


Closes NEXT-1418
2023-07-10 09:09:01 +02:00
Jiachi Liu
632a582807
Fix metadata layer webpack rule for server-only (#52403)
After we separating the metadata routes to a separate layer, we didn't apply the webpack alias rules properly to it as it's should still be treated as pure "server" side

This PR fixes the aliasing for that new metadata layer and make it working properly with "server-only"

Fixes #52390
2023-07-09 18:23:51 +00:00
Shu Ding
e50c9180a3
Cache concurrent ensurePage requests for the same page (#52360)
This should resolve part of the `MaxListenersExceededWarning` problem mentioned in #50909. When there are too many concurrent requests sent to the dev server, we only need to handle the first.

Co-authored-by: Tim Neutkens <6324199+timneutkens@users.noreply.github.com>
2023-07-07 23:08:55 +00:00
Wyatt Johnson
f45a7fce9a
Temporarily revert change to pages render (#52407)
This reverts the change to the pages render until a more substantial refactor can ensure that using the custom `app.render` method will attach a match to the request metadata.

- Fixes #52384
2023-07-07 17:58:36 +00:00
Yagiz Nizipli
d5f355adea
perf: improve URL validation performance (#52353)
The performance of the current implementation can be improved by using
`URL.canParse` which is pending for backport to Node 18 right now. This
pull request also reduces the usage of try/catch in the happy path.
2023-07-07 14:22:41 +02:00
vercel-release-bot
b2c6bc4572 v13.4.10-canary.0 2023-07-07 11:14:32 +00:00
Jiachi Liu
89bccd05de
Refactor metadata og and twitter title to be always presented (#52320)
Follow up for #52196 

The og title should be always resolved as `AbsoluteTemplate`. Move all the title resolving inside the og metadata resolving, so that it's aligned with type. And we don't have to check title everywhere, when og/twitter metadata is resolved, `title` is always presented as a property with `AbsoluteTemplate` type

Closes NEXT-1399
2023-07-07 11:07:52 +00:00
Tobias Koppers
a3d5a855eb
add incremental cache for node.js app rendering (#52172)
### What?

adds `incrementalCache` to app rendering to add support for
`unstable_cache`
2023-07-07 11:33:51 +02:00
Zack Tanner
412992ad6e
fix: prevent infinite dev refresh on nested parallel routes (#52362)
### What?
HMR causes infinite reloads for parallel routes when the corresponding page component is nested

### Why?
In 4900fa21b078fd1ec1adc5d570fcfb560be8aeb6, code was added to remove `/@children` from the page path (if present) but in 59b36349eb86427ac7b679ac62fa6628c9fc4886, `normalizeParallelKey` removes the @ prefix from children, so this doesn't seem to be catching the scenario it was intended to prevent

### How?
This updates the existing replace logic to consider `/children/page` rather than `/@children/page` -- it doesn't seem like `/@children` is a valid scenario given the `normalizeParallelKey` behavior

Fixes #52342 and addresses the concerns in https://github.com/vercel/next.js/pull/52061#issuecomment-1619145129
2023-07-07 07:41:21 +00:00
Yagiz Nizipli
eb3d748759
perf: simplify getShortDynamicParamType on app-render (#52355)
Removes the unnecessary switch case statement and provide a fast path for `optional-catchall` edge case.
2023-07-07 00:35:55 +00:00
Steven
27217146cf
fix: metadatabase warning message (#52363)
This PR is a small grammar change to the warning message since "fallbacks to" is not grammatically correct.
2023-07-07 00:08:10 +00:00
Yagiz Nizipli
4b2eef4600
perf: use fs.opendir for better resource usage (#52341)
This pull request replaces `fs.readdir` with `fs.opendir` for better memory usage. `fs.readdir` consumes the path and only returns value when the iteration is finished, but `fs.opendir` both returns `fs.Dirent` which is better, since we are calling an additional `fs.stat` for each iteration, but also streams the output, so that we don't store the whole array of inputs in the memory.
2023-07-06 23:11:09 +00:00
Yagiz Nizipli
1fbb5138c8
perf: use fs.readdirSync with withFileTypes (#52340)
There is no need to make a `fs.statSync` call for each file while reading a directory, since `fs.readdirSync` supports `withFileTypes` property that returns a `fs.Dirent` which includes the necessary information for detecting if the particular item is directory or not.
2023-07-06 21:39:22 +00:00
JJ Kasper
f0fc83b40c
Fix trailing slash with locale domain (#52343)
This ensures we normalize the trailing slash with a locale domain href
correctly.

Reproduction with patch can be seen here
https://reproduction-link-inconsistency-96cg0lqc9-vtest314-ijjk-testing.vercel.app/dynamic/alpha/

Fixes: https://github.com/vercel/next.js/issues/47661
2023-07-06 13:56:30 -07:00
vercel-release-bot
1045644655 v13.4.9 2023-07-06 20:50:37 +00:00
vercel-release-bot
21392cb4e0 v13.4.9-canary.3 2023-07-06 17:07:58 +00:00
doinki
c878caa3bc
Fix to use keep-alive in standalone mode (#50221)
You can specify keepAliveTimeout as an environment variable in
standalone mode, but there is a problem with it not being properly
applied.

#46052 

#### before
<img width="574" alt="2023-05-24 12 49 12"
src="https://github.com/vercel/next.js/assets/90969158/9014252e-dcac-4b32-805a-68e844e853b1">
<img width="574" alt="2023-05-24 12 49 20"
src="https://github.com/vercel/next.js/assets/90969158/8c5672b2-8af8-4751-aa0c-7347428c3cbb">

#### after

<img width="574" alt="2023-05-24 1 19 12"
src="https://github.com/vercel/next.js/assets/90969158/96a83b0d-1dd1-45b7-b053-e0103185dd47">
2023-07-06 09:59:59 -07:00