Commit graph

9113 commits

Author SHA1 Message Date
Zack Tanner
aec75c2f06
fix: build stats should properly report root page size in appDir (#51854)
### What?
`next build` is incorrectly reporting file size stats for the root path
when using the app dir

### Why?
In #50768, the denormalization logic was removed for appDir routes, but
`pagesManifest` has the root page keyed by `/` while the actual path
will be `/index`.

### How?
This re-adds a simpler denormalize function that just replaces `/index`
with `/`.

semi-related: #42819 

Fixes #51692

link NEXT-1306

---------

Co-authored-by: JJ Kasper <jj@jjsweb.site>
Co-authored-by: Jiachi Liu <inbox@huozhi.im>
2023-06-26 18:57:50 -07:00
Jiachi Liu
d06bc5e286
perf: only require nextjs-require-cache-hot-reloader related API in dev mode (#51834)
`nextjs-require-cache-hot-reloader` is only required in dev mode for plugin, we can skip these require in production mode

![image](https://github.com/vercel/next.js/assets/4800338/889f98db-7029-4aea-9d12-0e03547be606)
2023-06-27 00:27:35 +00:00
Shu Ding
300507baf0
Enable compression for Webpack's cache during dev (#51851)
This is already the default for production build, but we are also enabling it for development. It has small perf impact as gzip takes time, but it significantly improves the disk usage and time for reading and writing to the filesystem. This is especially the case when working on a large codebase and we are transpiling and bundling more modules now.
2023-06-26 23:16:43 +00:00
Steven
8b60fbc718
fix: webpack target should match node engines (#51852)
The webpack `target` was outdated so I updated to match `engines`. See related https://github.com/vercel/next.js/pull/48941
2023-06-26 22:15:44 +00:00
Ty Hopp
65f94baa83
feat: Introduce eslint rule for async client components (#51547)
The [React Server Component RFC on promise support](https://github.com/acdlite/rfcs/blob/first-class-promises/text/0000-first-class-support-for-promises.md) indicates that [client components cannot be async functions](https://github.com/acdlite/rfcs/blob/first-class-promises/text/0000-first-class-support-for-promises.md#why-cant-client-components-be-async-functions).

This PR introduces an eslint rule to enforce this.

Fixes #50898
2023-06-26 21:10:24 +00:00
Shu Ding
f1240b8efd
Refactor next-font-manifest-plugin (#51835)
## Background

Currently we're track all imported CSS modules by an entry, in the
client manifest:

```js
// client manifest
{
  entryCSSFiles: {
    'app/entry_name': {
      modules: ['app/foo.css', ...]
    }
  }
}
```

And then, in the font manifest we track all emitted assets (fonts) by
each CSS module:

```js
// font manifest
{
  app: {
    'app/foo.css': [
      'static/font/abc.woff', ...
    ]
  }
}
```

These two fields are only used together by `get-preloadable-fonts.tsx`,
so it can know which font files need to be preloaded for this entry.

(Although previously we use `.modules` for something else, but it's gone
now)

## Changes

Since we only need the font assets per entry, it's unnecessary to track
these in the module level and then join them together. This PR removes
the `modules` field from the client manifest, and changes the font
manifest to directly keep the entry—font mapping.

This gets rid of one module traversal from the client manifest plugin.
2023-06-26 13:43:37 -07:00
vercel-release-bot
57ab2818b9 v13.4.8-canary.5 2023-06-26 16:18:48 +00:00
Jimmy Lai
6238f8a5c0
performance: don't compile on hover on dev (#51830)
An annoying issue that slows down compilation times in dev for Next is
that we might trigger compilation of a page via hover on app.

We do this because we want the same experience in production and dev and
the prefetching is important for instantaneous loading states.

The alternative in this PR is that we don't prefetch at all anymore in
dev but instead, when we handle navigation, we can force a prefetch
navigation.

The slight compromise with this approach is that you can't test
prefetching anymore in dev.


<!-- 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 #

-->

link NEXT-1317
2023-06-26 18:12:59 +02:00
Shu Ding
4b1a0165d3
Simplify Flight manifest plugin (#51589)
Instead of traversing the entire client module graph twice (!), this PR
changes it to only traverse the client **entry** modules only. Because
of the way we create client entries, all client modules' _boundaries_
can be retrieved via all outgoing connections of all chunks' entry
modules, filtered by `next-flight-client-entry-loader`.

This brings down the time complexity from `2 * num_client_modules` to
`num_client_entry_modules`.

Closes #51240.

Additional notes from @timneutkens 

- Removed `module.unsafeCache` as it seemed to be leaking modules across
multiple compilations, this should help with memory usage
- Changed entry-loader to have consistent module import map (sort it) to
ensure cache key is consistent

---------

Co-authored-by: Tim Neutkens <tim@timneutkens.nl>
2023-06-26 18:11:08 +02:00
vercel-release-bot
c8f3897fe2 v13.4.8-canary.4 2023-06-26 15:27:18 +00:00
Shu Ding
5b9dd4c47e
Add WATCHPACK_WATCHER_LIMIT=20 (#51826)
Limit the number of Watchpack's watchers to 20 for the routing worker which runs Watchpack. By default this value is 2000 on macOS and 10000 on Windows, which can hold too much resource.
2023-06-26 14:17:44 +00:00
vercel-release-bot
913b365d85 v13.4.8-canary.3 2023-06-26 12:07:28 +00:00
Shu Ding
0dd0ef226c
Fix tree-shaking for metadata image functions on the Edge runtime (#51762)
This PR fixes tree-shaking for the metadata image generation module
(e.g. `opengraph-image.js` and other conventions) when the page has
`runtime = 'edge'`.

## Details

The first step of this fix is to change this from the loader:

```js
import * as exported from "./opengraph-image.js"
```

to be necessary fields only (so the `default` export can potentially be
removed):

```js
import { alt, size } from "./opengraph-image.js"
```

To know which fields are exported, we need to load the module first via
Webpack loader's `loadModule` API and check its
`HarmonyExportSpecifierDependency` dependencies.

This is the first step to make it tree-shakable. Since we have
`./opengraph-image.js` used in another entry, the actual image API route
`opengraph-image/route.js`:

```js
import * as image from "./opengraph-image.js"
```

Webpack still treats both as the same module and generates one chunk for
it. We want to "fork" it into two modules. The technique here is to add
a noop resource query and make it:

```js
import { alt, size } from "./opengraph-image.js?__next_metadata_image_meta__"
```

So it won't be shared in the chunk (as it's a different request), and
can be concatenated inline.

However that's not enough, the inlined result will still have all
imports from our `opengraph-image.js`, including `import { ImageResponse
} from 'next/server'`. Because we can't simply add `"sideEffects":
false` in Next.js' package.json, we need a way to mark this import as
side-effect free. I went through
https://github.com/webpack/webpack/blob/main/lib/optimize/SideEffectsFlagPlugin.js
and used the same method to mark that module with
`module.factoryMeta.sideEffectFree = true`.

With all these added, the page bundle will no longer contain the
`ImageResponse` instance.

## Result

The difference is quite amazing, for the new added test (an empty Edge
runtime page with an opengrah image file) here're the before/after
metrics for the `page.js` server bundle:

Edge bundle size: 892kB → 500kB.
Build time: 26.792s → 8.830s.
2023-06-26 13:44:29 +02:00
Cowboy Ho
70aad4a2b5
Fix NODE_OPTIONS='--inspect' not running expected (#51467)
## Fixing a bug

Fixes #50489
Fixes #48767
Fixes #45697

## What?
When running `NODE_OPTIONS='--inspect' next dev`
Then go to `http://localhost:3000/`
Will display error message `WebSockets request was expected` like the following screenshot
![image](https://github.com/vercel/next.js/assets/14261588/d2f3e520-7cce-40db-be69-99980804cc51)

Also the debug port for app and page still not follow by user input
When `NODE_OPTIONS='--inspect=8000' next dev` the app debug port still `54151`
![image](https://github.com/vercel/next.js/assets/14261588/e3d25c0e-9d00-4767-94d6-d954776912b2)


## Why?
#50248 added a function `getFreePort()` and it used on debug port and HTTP server port
So conflict happen between debug and HTTP port
Then show up error `WebSockets request was expected`

Here are some references about this error:
https://stackoverflow.com/questions/49766500/websockets-request-was-expected-error-when-using-inspect-brk-option


## How?
1. `getFreePort()` should only use on HTTP server
2. Added `getDebugPort()` for read the port from user input
3. Assign port to each worker
4. Add accurate info log for each debug port, e.g.: `proxy`,`router`,`app`,`page`

When `NODE_OPTIONS='--inspect' next dev` 
![image](https://github.com/vercel/next.js/assets/14261588/2260fdff-13fe-435a-9812-984315c0ea2e)

When `NODE_OPTIONS='--inspect=8000' next dev` 
![image](https://github.com/vercel/next.js/assets/14261588/de6e2f2d-9216-481f-b6db-7c5132e97b6f)

Also fix VSCode debugger
It is worth noting that
We can't hit the breakpoint on the first execution
because the file does not exist there yet or was not compiled
In most cases, the breakpoint can only be triggered normally during the second execution
![image](https://github.com/vercel/next.js/assets/14261588/dccded50-46c5-4b6d-beb7-ff0e5324327a)


Closes NEXT-1179
Closes NEXT-517



Co-authored-by: Shu Ding <3676859+shuding@users.noreply.github.com>
2023-06-25 22:31:09 +00:00
Shu Ding
cb7be1912f
Remove unncessary source matching from loader (#51775)
The same logic is handled by SWC already, and extracted here:

dd937bde09/packages/next/src/build/analysis/get-page-static-info.ts (L68)
2023-06-25 21:58:11 +00:00
Shu Ding
1ec61f76a0
Remove execSync (#51785)
Currently we have an `execSync` in the Telemetry class constructor which
runs at startup even if it might not be needed. This PR changes it to be
non-blocking and makes it lazily loaded.

Before:

<img width="907" alt="CleanShot 2023-06-25 at 16 33 57@2x"
src="https://github.com/vercel/next.js/assets/3676859/b3b1acb6-9968-4a00-9da9-b4b7fa859be3">

Note that all 3 processes (main, app renderer, pages renderer) all have
this.

After:

<img width="956" alt="CleanShot 2023-06-25 at 16 36 52@2x"
src="https://github.com/vercel/next.js/assets/3676859/7ef1973b-bdb2-485d-9336-6f67e13bccff">
2023-06-25 14:06:58 -07:00
Zack Tanner
1b804c0529
fix: interception rewrites should support catch-all segments (#51787)
### What?
Interception route rewrites are not properly parsing catch-all segments,
which leads to "missing parameter name" errors when passed to
`pathToRegexp`.

### Why?
The existing `toPathToRegexpPath` function ignores `...` and keeps it as
part of the regexp path. This means `pathToRegexp` will attempt to
handle `/foo/bar/:...baz` and `/foo/bar/:[...baz]` rather than
`/foo/bar/:baz*`

### How?
The regex used for matching the path was updated to support the dynamic
optional segment, and then we special case catch-all segments

Fixes #51784

---------
2023-06-25 14:02:10 -07:00
Shu Ding
869aeb40ce
Fix HMR for missing dependencies in next-app-loader (#51778)
As noted in the comments, it's necessary to always add optional dependencies as missing dependencies even if they exist because they might be deleted and re-added.

Closes #51763.
2023-06-25 19:26:09 +00:00
Shu Ding
70692d80b4
Rename serverActionsSizeLimit as serverActionsBodySizeLimit and add docs (#51755)
Close the circle after #51104. The name "size limit" can be confusing as it could also mean the size of the Server Action function itself, so this PR changes it to `serverActionsBodySizeLimit` and makes sure it's well documented.
2023-06-24 16:16:09 +00:00
Tobias Koppers
016e3e3c70
revalidate should be more than a boolean (#51627)
### What?

`export const revalidate = 0` should be parse as number
2023-06-24 07:38:39 +00:00
Islam Sharabash
96d540c768
Allow matching against user-agent in rewrites that match headers (#48271)
This adds support for matching against the user-agent header when doing rewrites client side.
Currently a rewrite like this will fail because the user-agent header is not provided, and so next.js tries to prevent infinite rewrites:
```
{
  source: '/:path*',
  destination: 'https://example.com/:path*',
  missing: [
    {
      type: 'header',
      key: 'User-Agent',
      value: '.*(?:Electron).*'
    },
  ],
}
```

Adding in the user-agent header allows this rewrite to pass.
2023-06-24 05:32:11 +00:00
JJ Kasper
2c5cf40377
Fix not-found handling in turbopack (#51735)
Adds the overlay changes from
https://github.com/vercel/next.js/pull/51637

Fixes:
https://github.com/vercel/next.js/actions/runs/5362063391/jobs/9728782834
2023-06-23 21:35:38 -07:00
vercel-release-bot
74a5d2068a v13.4.8-canary.2 2023-06-24 02:20:39 +00:00
Jiachi Liu
e19e9e3ca3
Add critical next config value to github info (#51715)
Adding `nextConfig.output` to next-info output so that we could determine if users're using standalone mode if the reproduction is not clear or missing sometimes

Example output

```
    Relevant Packages:
      next: 13.4.8-canary.1
      eslint-config-next: 13.4.8-canary.1
      react: 18.2.0
      react-dom: 18.2.0
      typescript: 5.1.3
    Next.js Config:
      output: standalone
```
2023-06-24 00:07:07 +00:00
Zack Tanner
c98d2b927d
fix: handle 404 errors in HotReload client (#51637)
### What?
In dev mode, routing to a 404 page will result in an infinite redirect
cycle. This PR is an attempt to bring back similar functionality
currently implemented in the [pages
router.](https://github.com/vercel/next.js/blob/canary/packages/next/src/client/dev/on-demand-entries-client.ts#L41-L59)

### Why?
When the `pong` event (emitted from `onHMR`) occurs on a page that
doesn't exist, it will result in frequent calls to
`router.fastRefresh()`. Because the server response is an error, it'll
trigger a mpa navigation
[here](61ab4aadec/packages/next/src/client/components/router-reducer/fetch-server-response.ts (L115-L117)),
which is treated as an external route
[here](61ab4aadec/packages/next/src/client/components/router-reducer/reducers/fast-refresh-reducer.ts (L45-L53))
(and thus the window is reloaded)

In the case where you're on the page and it goes away, since we don't
have access to `__NEXT_DATA__`, I opted to use the dispatcher which will
trigger the parent `NotFoundBoundary`. This part felt a little awkward
-- I'm open to suggestions on a better way to handle this.

Closes NEXT-1299
Fixes #50585

---------

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2023-06-23 16:30:48 -07:00
최지원
a9870df101
feat: add body parser limit for server actions (#51104)
<!-- 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

- 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?
Add configuration options to modify the `bodyParser` size as it used to
be available in Page Router.
### Why?
Server Actions "Error: Body exceeded 1mb limit" cannot be resolved since
the body-parser limit size is hardcoded to `1mb`.
### How?

Closes NEXT-
Fixes #

-->

### What?

Add configuration options to modify the `bodyParser` size as it used to
be available in Page Router for APIs.

```js
export const config = {
  api: {
    responseLimit: false | '8mb' 
  },
}
```

Reference: [API Routes Response Size
Limit](https://nextjs.org/docs/messages/api-routes-response-size-limit)

### Why?

Server Actions "Error: Body exceeded 1mb limit" cannot be resolved since
the body-parser limit size is hardcoded to `1mb`.

```js
// /packages/next/src/server/app-render/action-handler.ts

// ...
const actionData = (await parseBody(req, '1mb')) || ''
// ...
```

Reference:
https://github.com/vercel/next.js/blob/canary/packages/next/src/server/app-render/action-handler.ts#L355
### How?

- Added option "serverActionsLimit" as `SizeLimit` type to
`config-shared.ts`
- Modified `action-handler.ts` to validate `serverActions` &
`serverActionsLimit` options in nextConfig
- Added conditional `serverActionsLimit` value and `1mb` if falsy

**Working on testing**

Fixes #49891 | #51097 | #51099

---------

Co-authored-by: JJ Kasper <jj@jjsweb.site>
Co-authored-by: Shu Ding <g@shud.in>
2023-06-23 16:24:18 -07:00
JJ Kasper
916e21f913
Update manual basePath with trailingSlash (#51726)
With the manualBasePath config we still need to normalize the trailing
slash per that config.

x-ref: [slack
thread](https://vercel.slack.com/archives/C03S8ED1DKM/p1687543336964799?thread_ts=1687487533.019499&cid=C03S8ED1DKM)
2023-06-23 15:36:16 -07:00
Shu Ding
ae4a723446
Correct Flight client's condition for SSR and createServerReference (#51723)
This PR addresses a problem where the `createServerReference` is using
the default condition of flight client (gets resolved to the Node
build), but we use the Edge build of flight client for SSR. This causes
2 flight clients to exist during SSR.
2023-06-23 23:57:50 +02:00
Adam Mcgrath
fda1ecc31e
Add url to patched fetch response (#51665)
### What?

Add `url` property to response returned from patched fetch

### Why?

So that libraries that rely on `response.url` work with the app directory and fetch cacheing

### How?

Using the same code as https://github.com/vercel/edge-runtime/blob/edge-runtime%402.4.3/packages/primitives/src/primitives/fetch.js#L164

fixes #51642 

Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
2023-06-23 21:53:17 +00:00
Wyatt Johnson
bc05ce921a
Move Pages render out of server (#51678)
This removes calls for rendering files in `pages/` via the server code and relies instead relies on the bundled `routeModule` to perform the rendering.

Future cases that try to call the legacy render will hit a new: 

```
Invariant: render should have used routeModule
```

Error. These cases should be reported.
2023-06-23 20:22:43 +00:00
Tim Neutkens
0a4b6ef810
Add default modularizeImports that breaks up lucide-react, mui/icons-material, lodash, react-bootstrap (#50900)
## What?

Adds a default modularizeImports that ensures `lucide-react`, `@mui/icons-material`, `lodash`, and `react-bootstrap` do not cause a massive amount of modules to be compiled in development.
For example `@mui/icons-material` re-exports 10600 (10K+) modules from a single file. Even though it does not affect production bundle size it does affect build time, especially in development, and even more so when your filesystem is slow (e.g. what we're seeing on Windows). 

Related issue: #48748 (not closing)




Co-authored-by: Shu Ding <3676859+shuding@users.noreply.github.com>
2023-06-23 19:53:58 +00:00
Leah
5d54eaaf18
type check tests (and convert next-test-utils.js to ts) (#51071)
Enables type checking for tests in CI and fixes a bunch of things related to that
2023-06-23 17:42:50 +00:00
JJ Kasper
d457e989ff
Revert "Update swc_core to v0.78.15" (#51716)
Reverts vercel/next.js#51269

This is breaking some builds it looks like

x-ref: https://github.com/vercel/next.js/actions/runs/5357843108/jobs/9719367732
x-ref: https://github.com/vercel/next.js/actions/runs/5357843108/jobs/9719368519
2023-06-23 17:12:47 +00:00
이현재
889e2203a5
Update page.tsx tw className (#49040)
I changed the tailwindcss code, which is written differently than the
other elements in `app/page.tsx`

<!-- 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 #

-->

Co-authored-by: Shu Ding <g@shud.in>
2023-06-23 17:11:59 +02:00
Donny/강동윤
5f3d7c43ea
Update swc_core to v0.78.15 (#51269)
### What?

Update SWC crates to 8b765e6763

### Why?

There were many patches.

### How?

Closes WEB-1174

Turbopack counterpart: https://github.com/vercel/turbo/pull/5288
2023-06-23 11:40:11 +00:00
Tobias Koppers
5abeb99b49
add edge rendering for app dir for Turbopack (#51666)
relanding #50830 and #51631 

### Turbopack Changes

* https://github.com/vercel/turbo/pull/5254 <!-- OJ Kwon - ci(workflow):
upload daily next.js test trace -->
* https://github.com/vercel/turbo/pull/5363 <!-- Tobias Koppers -
disable default features for turbopack-ecmascript-plugins -->
2023-06-23 07:08:17 +02:00
vercel-release-bot
d0a1e64962 v13.4.8-canary.1 2023-06-22 23:16:54 +00:00
Jiachi Liu
16eb80b0b0
Fix standalone rendering for unmatched _next routes (#51611)
Request data flow in the server

```
request ---> router worker (1) ---> ipc ---> render worker app (2)
                                                              |-----> render worker pages (3)
```

When it's hitting `_next/*` unmatched routes in standalone server, it will render 404, but when you hit `_next/*` it will render app not-found as the app router is always enabled, but router worker isn't set up with require-hook for proper built-in react version, then the app-render will fail with `./server.edge` exports not found error.

We detect if it's in the render worker, then do the app paths rendering instead of directly looking up for app paths in route worker. This could avoid unexpected accesses to the app-render

Fixes #51482 
Fixes #50232
Closes #51506
Reverts changes in #51172
fix NEXT-1260
2023-06-22 22:58:04 +00:00
Jiachi Liu
89f36a98bc
Hot reload when conflicted pages detected and when conflicts are resolved (#51516)
When conflicted pages occur between app and pages server used to throw error and you need to solve the conflicts and restart the server.

This PR capture the error during files aggregation, and send to client to display the error for files confliction. This will send all the conflicts to client and it will still error until you solve all of them. But since the server is not stuck by errors, client can recover once the error is solved.

Closes NEXT-1283
2023-06-22 22:32:14 +00:00
Jiachi Liu
db4b9858ca
Add esm entry for next/server and alias @vercel/og (#51651)
The next-metadata-route-loader emitted content with `"next/server"` is still using cjs version which is not get tree-shaked on edge runtime, This PR adds a new esm entry for it and mapped it that on edge runtime so unused exports can be tree-shaked. This case happened when users are using ImageResponse from `"@vercel/og"` instead of `"next/server"`.

2nd change is adding another alias to map `@vercel/og` package to vendored og package inside next.js, this way we could merge the two package instead of bundled both of them


Fixes: NEXT-1303

changed `require.reoslve("next/dist/xxx")` to `${NEXT_PROJECT_ROOT}/xxx}` to avoid to be traced by nft.
2023-06-22 21:34:12 +00:00
JJ Kasper
f749684921
Update cache handling in draft mode (#51663)
Similar to `getStaticProps` when draft mode is enabled we should bypass
the cache so fresh data is shown.

x-ref: [slack
thread](https://vercel.slack.com/archives/C052BQ8F9EJ/p1687440125828479?thread_ts=1684336597.437409&cid=C052BQ8F9EJ)
and
[tweet](https://twitter.com/tomus_sherman/status/1669023879656873988)

---------

Co-authored-by: Steven <steven@ceriously.com>
2023-06-22 14:03:11 -07:00
vercel-release-bot
554e58c31a v13.4.8-canary.0 2023-06-22 18:19:20 +00:00
JJ Kasper
d0e7d04dc5
Revert "add edge rendering for app dir for Turbopack" (#51659)
Reverts vercel/next.js#51631

This breaks the windows builds

x-ref:
https://github.com/vercel/next.js/actions/runs/5344032749/jobs/9687974376
x-ref:
https://github.com/vercel/next.js/actions/runs/5344032749/jobs/9687973522
2023-06-22 08:49:50 -07:00
Wyatt Johnson
5871b0d6d7
Pages Error Route Module Rendering (#51374)
Continuing on changes to move the rendering logic into the bundles.

- Unifies edge render functions: `appRenderToHTML` and `pagesRenderToHTML` becomes `renderToHTML`
- When an error occurs, the error module's match is used so the module's internal render can be used (easing transition away from using the server's render method)
- Improved test resiliance
2023-06-22 15:13:13 +00:00
Tobias Koppers
99ec3057d7
add edge rendering for app dir for Turbopack (#51631)
## What

* reland #50830 
* remove Object.hasOwn
* fix CSS chunks in edge runtime

## Turbopack Changes

* https://github.com/vercel/turbo/pull/5253 <!-- OJ Kwon -
fix(turbopack): enable runtime flag -->
* https://github.com/vercel/turbo/pull/5295 <!-- Will Binns-Smith -
remove `__internal_nextjs_integration_test` compile-time feature -->
* https://github.com/vercel/turbo/pull/4362 <!-- Donny/강동윤 - Make build
faster -->
* https://github.com/vercel/turbo/pull/5352 <!-- Tobias Koppers - only
wait for JS chunks in none runtime backend -->
2023-06-22 11:43:59 +02:00
Zack Tanner
6f61fb4068
bugfix: route interception with dynamic paths (#51526)
### What?
Paths with interception markers adjacent to dynamic segments are not correctly parsed, which leads to the path match logic failing. 

### Why?
`getParametrizedRoutes` checks for brackets but isn't expecting to receive an interception marker. For example, a path of `/photos/(.)[author]/[id]` results in the following regex:
`/^\/photos\/\(\.\)\[author\]\/([^/]+?)(?:\/)?$/`

This will not match a path of `/photos/(.)zack/1` since it retained the `[author]` brackets.

`getSegmentParam` has a similar issue when getting values for path params, though we can just skip the interception markers and go straight to the params.

Closes NEXT-1166, NEXT-1013
Fixes #48143
Fixes #49614

link NEXT-1013
2023-06-22 09:43:24 +00:00
Alex Kirszenberg
c6313606c9
Next Build Turbo POC (2) (#51546)
Another attempt at getting https://github.com/vercel/next.js/pull/49942 in.

This time, the mold install step is gated to Linux.
2023-06-22 08:03:44 +00:00
Justin Ridgewell
b714ac55c1
Support response aborting (#51594)
### What?

This is an alternative to #51330, which only support aborting the response (doesn't support back-pressure). If the client cancels the request (HMR update, navigates to another page, etc), we'll be able to detect that and stop pulling data from the dev's `ReadableStream` response.

### Why?

We want to allow API routes to stream data coming from another server (eg, AI services). The responses from these other servers can be long running and expensive. In the case the browser aborts the connection, it's critical that we stop streaming data as soon as possible.

### How?

By checking whether `response.closed` is set during the `for await (…)` iteration, we're able to detect that the client has aborted the connection. Cleanup of the `ReadableStream` is handled implicitly by the async iterator when the loop ends.

The one catch is our use of http-proxy for worker processes. It does not properly detect a client disconnecting (but does handle back-pressure). In order to fix that, I've manually added event listeners to detect the disconnect and cancel the proxied req/res pair.

Re: [WEB-1185](https://linear.app/vercel/issue/WEB-1185) (we still need back-pressure)
Fixes https://github.com/vercel/next.js/issues/50364
Fixes https://github.com/vercel-labs/ai/issues/90
2023-06-22 00:43:31 +00:00
Yash Singh
f59710e907
feat: support for numeric separators in revalidate config (#51438)
### Fixing a bug

- [x] Related issues linked using `fixes #number`
- [x] 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

### What?

Currently, when the check on validating the type of `revalidate` is run,
we use the `Number` function to parse the value of `revalidate`, however
the `Number` function takes a
[`StringNumericLiteral`](https://tc39.es/ecma262/2023/#prod-StringNumericLiteral)
which doesn't allow the usage of the `_` separator to format your
numbers. This PR allows you to add numeric separators in the
`revalidate` export.

### Why?

When configuring the actual code, we should be allowed to use numeric
separators as it is a syntax that is supported by most runtimes.

### How?

A simple `replaceAll` call that removes all `_`s between digits.

Closes NEXT-1122
Fixes #49485

---------

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2023-06-21 17:22:29 -07:00
Andrey Krasovsky
2cae83d0f2
fix(typo): rename var name in comment (#51531)
Co-authored-by: JJ Kasper <jj@jjsweb.site>
2023-06-21 16:01:46 -07:00