Commit graph

9663 commits

Author SHA1 Message Date
Matt Cowley
c1fa78bf6c
fix(next/image): empty blur image when animated (#54028)
Partial fix for #54012: do not generate a blur image in the image loader when the image is detected to be animated, rather than returning the *entire* animated image as the blur image.
2023-08-15 02:17:40 +00:00
vercel-release-bot
2fac86480c v13.4.16 2023-08-15 01:03:24 +00:00
vercel-release-bot
33d9bf2a8f v13.4.16-canary.1 2023-08-15 00:42:45 +00:00
Shu Ding
cd95fe4085
Adjust internal action proxy export (#54004)
This PR changes the internal `createActionProxy` util from a default
export to a named export, as the default export could be problematic if
it's built without the "esModuleInterop" step.

---------

Co-authored-by: Balázs Orbán <info@balazsorban.com>
2023-08-15 01:16:28 +02:00
vercel-release-bot
4d0aaafdef v13.4.16-canary.0 2023-08-14 22:26:27 +00:00
Will Binns-Smith
bd8ab094e5
Turbopack: fix hiding node_modules warnings in error overlay. (#54022)
This regressed in vercel/turbo#5661 when `context` was renamed `file_path`.
2023-08-14 21:38:52 +00:00
Dima Voytenko
88ad471e33
Concept: test mode for Playwright and similar integration tools (#52520)
An experimental test mode that enables integration tests to mock server-side fetch requests in Playwright tests.

For explanation on how this works, see the [`next-playwright/README.md`](https://github.com/vercel/next.js/pull/52520/files#diff-3b8da7782c16f015df5afafe0ac11247f5b8e5a1c0dbede341ca2b5124dfd924).
2023-08-14 18:45:50 +00:00
vercel-release-bot
6306ec1c1d v13.4.15 2023-08-14 16:40:09 +00:00
vercel-release-bot
242cdca8e0 v13.4.15-canary.0 2023-08-14 16:01:53 +00:00
Jiachi Liu
3f83743a6e
Make next a devDependency of @next/third-parties package (#53996)
ensure `next` is the dependency of third-parties package so turbo will
build next first then `@next/third-parties` to avoid type failing

---------

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2023-08-14 08:55:57 -07:00
Jiachi Liu
4c84ea555d
Remove tsconfig extending for @next/thrid-parties package (#53991)
x-ref:
https://github.com/vercel/next.js/actions/runs/5854800073/job/15871731468

Do not use the `packages/next` tsconfig, aligning tsconfig with other
`@next/` packages. So it won't run tsc with `tsec` plugin
2023-08-14 14:26:24 +02:00
vercel-release-bot
4ee4458d46 v13.4.14 2023-08-14 10:46:46 +00:00
vercel-release-bot
e53f3af934 v13.4.14-canary.5 2023-08-14 07:58:37 +00:00
Ngô Đức Anh
a4b430e6f1
Better IPv6 support for next-server (#53131)
### What?
This PR makes it easier to use Next.js with IPv6 hostnames such as `::1` and `::`.

### How?
It does so by removing rewrites from `localhost` to `127.0.0.1` introduced in #52492. It also fixes the issue where Next.js tries to fetch something like `http://::1:3000` when `--hostname` is `::1` as it is not a valid URL (browsers' `URL` class throws an error when constructed with such hosts). It also fixes `NextURL` so that it doesn't accept `http://::1:3000` but refuse `http://[::1]:3000`. It also changes `next/src/server/lib/setup-server-worker.ts` so that it uses the server's `address` method to retrieve the host instead of our provided `opts.hostname`, ensuring that no matter what `opts.hostname` is we will always get the correct one.

### Note
I've verified that `next dev`, `next start` and `node .next/standalone/server.js` work with IPv6 hostnames (such as `::` and `::1`), IPv4 hostnames (such as `127.0.0.1`, `0.0.0.0`) and `localhost` - and with any of these hostnames fetching to `localhost` also works. Server Actions and middleware have no problems as well.

This also removes `.next/standalone/server.js`'s logging as we now use `start-server`'s logging to avoid duplicates. `start-server`'s logging has also been updated to report the actual hostname.
![image](https://github.com/vercel/next.js/assets/75556609/cefa5f23-ff09-4cef-a055-13eea7c11d89)
![image](https://github.com/vercel/next.js/assets/75556609/619e82ce-45d9-47b7-8644-f4ad083429db)
The above pictures also demonstrate using Server Actions with Next.js after this PR.
![image](https://github.com/vercel/next.js/assets/75556609/3d4166e9-f950-4390-bde9-af2547658148)

Fixes #53171
Fixes #49578
Closes NEXT-1510

Co-authored-by: Tim Neutkens <6324199+timneutkens@users.noreply.github.com>
Co-authored-by: Zack Tanner <1939140+ztanner@users.noreply.github.com>
2023-08-14 07:23:24 +00:00
vercel-release-bot
df6ec96ab2 v13.4.14-canary.4 2023-08-14 04:47:55 +00:00
JJ Kasper
9a6ae144a9
Update swc runners config (#53939)
This fixes unexpected cache hits occurring causing latest next-swc
changes to not be built for the docker based builds. Noticed in our
turbo run summaries for these builds that no input files were detected
most likely due to older Node.js/pnpm versions being used from the old
Docker image.

This also updates to leverage new runner labels for better build perf
cutting build times down from over an hour down to around 20 min.

Fixes build issue on aarch64-linux-musl due to `TurboMalloc` not being
able to resolve. Test build done here
https://github.com/vercel/next.js/actions/runs/5850893681/job/15860929304

x-ref:
https://github.com/vercel/next.js/actions/runs/5843580924/job/15845848384

x-ref:
https://github.com/vercel/next.js/actions/runs/5837652747/job/15833506858
x-ref:
https://github.com/vercel/next.js/actions/runs/5837652747/job/15833506925
x-ref:
https://github.com/vercel/next.js/actions/runs/5837652747/job/15833507067
x-ref:
https://github.com/vercel/next.js/actions/runs/5837652747/job/15833507135
2023-08-13 19:02:48 -07:00
vercel-release-bot
261db496f7 v13.4.14-canary.3 2023-08-12 21:41:13 +00:00
Zack Tanner
23f623546e
add "expect" to list of forbidden IPC headers (#53947)
`expect` is an unsupported header for undici: c83b084879/lib/core/request.js (L354) -- this filters it out so that the API routes don't throw an internal server error if that header is included. 

Also added a test case for the previously submitted PR that was added for `content-length: 0`

- x-ref: #53843

Fixes #53822 (erroneously closed by a content-length issue being fixed)
2023-08-12 19:38:38 +00:00
Josh Story
2b38118ea0
Update React ot latest canary (#53881)
Updated React from cb3404a0c to f359f9b41.

### React upstream changes

- https://github.com/facebook/react/pull/27191
- https://github.com/facebook/react/pull/27209
- https://github.com/facebook/react/pull/27199
- https://github.com/facebook/react/pull/27218
- https://github.com/facebook/react/pull/27217
- https://github.com/facebook/react/pull/27212
2023-08-12 17:20:14 +00:00
Jiachi Liu
4056994304
Recover not found errors from flight data to render with proper boundary (#53703)
### What?

We change the not-found rendering strategy to the origin one which recovers the not found error from the flight data, and hit the error boundary to display the closet not found component.

For parallel `@slot` we shouldn't pass down the not-found boundary, the boundary is only for `@children`.

### Why?

We're having a lot of not-found matching issues that manually searching for not found and layout won't be accurate as we have various scenarios like `(group)` routes, dynamic routes, etc.

### How?

Only render html with empty body so that the error can recover from flight and render the proper not-found component during hydration.

One change for metadata is that we need to get the "not-found" metadata in the initial render, so we'll catch the not-found error once there first and start render the "not-found" metadata and put it in the flight data. Then when it recovers it's still preserved.

Fixes #53694
2023-08-12 08:41:47 +00:00
Artur Bień
e0ca2ba544
feat(image): DataURL placeholder support for <Image /> (#53442)
Adds support for base64-encoded `placeholder`. Enables using placeholders without the "blur" effect.

Fixes #47639
- [x] Add support for DataURL placeholder
- [x] Add tests
- [x] Update docs

Co-authored-by: Steven <229881+styfle@users.noreply.github.com>
2023-08-11 23:45:20 +00:00
Leah
ddc8f50d24
enable @vercel/og support for turbopack (#53917)
### What?

Now that we have wasm support (and support for `?module`) `@vercel/og` should be supported

### Turbopack updates

* https://github.com/vercel/turbo/pull/5677 
* https://github.com/vercel/turbo/pull/5660 

Closes WEB-138
2023-08-11 22:16:41 +00:00
Shu Ding
707b1e3bc3
Limit sharp's concurrency (#53385)
Sharp by default spawns #cpu_cores threads to process images which could lead to large memory consumption. This PR caps the `concurrency` value especially on dev.

Locally I see a small memory improvement (10~20 MB) from this, but it will mostly affect long-running servers.

Related: https://github.com/lovell/sharp/issues/2607

Co-authored-by: Steven <229881+styfle@users.noreply.github.com>
2023-08-11 20:21:41 +00:00
Justin Ridgewell
fe80aff6dc
Turbopack: Emit whether server or client assets changed (#53879)
### What?

Updates the new `entrypoint.changed()` method to signal whether the server or client assets changed. Now, a `{ changed: 'server' | 'client' | 'both' }` will value will be yielded by the subscription.

### Why?

So that client-only changes can be handled differently than server-only changes.

### How?

We just needed to track the server and client output assets separately, so that we can detect changes to either individually. It's difficult to tell what `Vc` change triggered a recomputation on the Rust side (I'd have to involve mutable `State` into the Vc), and it's also hard to re-emit a duplicate value (eg, if a client change follows a client change, we need 2 emits). Instead, I tie the two different `server_changed()` and `client_changed()` functions into a single enum on the TS side.

Depends on https://github.com/vercel/next.js/pull/53809, since I don't want to introduce merge conflicts while Tobias is on vacation.
2023-08-11 18:08:33 +00:00
Jiachi Liu
50ff54ee29
Use summary_large_image as twitter card if images present by default (#53919)
This is an improvement for twitter card, if there's image present we could use `summary_large_image` to make the twitter card look better instead of using `summary` by default, so that users could benefit from the large image card display on twitter
2023-08-11 17:52:45 +00:00
Jan Nicklas
9e1e9bf311
Fix/match resource (#53796)
### Bug Fix
fixes #53366



### Change

Add `query` and [`matchResource`](https://webpack.js.org/api/loaders/#inline-matchresource) to the module mapping. 



### Why

`mod.resource` and all other paths inside `packages/next/src/build/webpack/plugins/flight-client-entry-plugin.ts` are already using the query:

e127c51327/packages/next/src/build/webpack/plugins/flight-client-entry-plugin.ts (L506-L507)

e127c51327/packages/next/src/build/webpack/plugins/flight-client-entry-plugin.ts (L584-L585)



### Motivation

We are using a static extraction css-in-js solution which uses the [inline match resource feature](https://webpack.js.org/api/loaders/#inline-matchresource) (see more in #53366)

As a css-in-js file contains the TSX and the CSS code we have to split the file into two modules which share the same `resource.path`.  

This works well however there is a problem in the mapping inside `.next/server/app/page_client-reference-manifest.js`.
The `ssrModuleMapping` from `addSSRIDMapping` in 
e127c51327/packages/next/src/build/webpack/plugins/flight-manifest-plugin.ts (L270) links to the latest module (the css part) and not the the initial one (the js part).

Therefore the css module is rendered [react-server-dom-webpack](https://www.npmjs.com/package/react-server-dom-webpack/v/0.0.1?activeTab=versions) and breaks.

The SSR/SSG fails with the error `Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined.`

Co-authored-by: Shu Ding <3676859+shuding@users.noreply.github.com>
2023-08-11 17:36:58 +00:00
Justin Ridgewell
85da585d1f
Turbopack: Fix debugging in napi for next-api (#53889)
### What?

#51883:

> Node.js sets stdout to non-blocking by default, rust expects it to be blocking
> 
> so when logging a lot of data, it can happen that rust receives an error while writing causing it to panic, the error is just that the resource is temporarily unavailable, but rust doesn't handle this case
> 
> See https://github.com/napi-rs/napi-rs/issues/1630

### Why?

### How?

This moves the work done in #51883 into the `loadBindings` function used by both next-api and next-dev.
2023-08-11 17:13:40 +00:00
Shu Ding
599cde8631
Add @heroicons/react to modularizeImports (#53902)
As discussed [here](https://vercel.slack.com/archives/C0591D8EN4C/p1691752316347649?thread_ts=1691743605.677919&cid=C0591D8EN4C), there're other popular icon and component libraries to be added until we have a better solution.
2023-08-11 14:49:13 +00:00
vercel-release-bot
9229f74b86 v13.4.14-canary.2 2023-08-11 12:02:35 +00:00
Tobias Koppers
45576ae752
Turbopack: more tests and bugfixes for next.rs api (#53809)
### What?

* adds more HMR test cases
* fixes bugs found

### Why?

### Turbopack changes

* https://github.com/vercel/turbo/pull/5668 <!-- OJ Kwon - ci(test):
temporarily increase test timeout -->
* https://github.com/vercel/turbo/pull/5696 <!-- Tobias Koppers -
Cleanup minify -->
2023-08-11 10:29:36 +02:00
Colin McDonnell
7e16538485
Include instructions for bun package manager (#53590)
## For Contributors

### Improving Documentation

- [x] Run `pnpm prettier-fix` to fix formatting issues before opening the PR.
- [x] Read the Docs Contribution Guide to ensure your contribution follows the docs guidelines: https://nextjs.org/docs/community/contribution-guide

### What?

Add instructions for using `bun/bunx` where relevant. I only added mentions where npm/yarn/pnpm were all already listed. 

### Why

Bun can be used as a runtime-agnostic [package manager](https://bun.sh/package-manager) and script runner in any project with a `package.json`.

(Sorry, I probably should have consolidated this with https://github.com/vercel/next.js/pull/53467)

Co-authored-by: Steven <229881+styfle@users.noreply.github.com>
2023-08-10 23:44:20 +00:00
Dave Carlson
9bb10b1cb3
Delete errorneous empty content length header (#53843)
fixes https://github.com/vercel/next.js/issues/53822

PR https://github.com/vercel/next.js/pull/53368 introduced a regression causing fetch with custom headers to fail in safari.
There are known issues with uncidi when a content-length: 0 header exists.

When performing a custom fetch in safari, this header is present.
When performing a custom fetch in chrome, this header is not present.




Co-authored-by: Zack Tanner <1939140+ztanner@users.noreply.github.com>
2023-08-10 22:03:13 +00:00
Steven
6f7ffadc86
fix: normalize backslash in getStaticPaths() for windows (#53876)
This normalizes the backslash for windows users who accidentally use `\` in the request paths instead of the expected `/`.

For example, in https://github.com/nodejs/nodejs.org/pull/5617 the slash was hardcoded for split that caused the backlash to remain the the `getStaticPaths()` result.

- Fixes #51225
2023-08-10 21:27:02 +00:00
Tim Neutkens
d4ff236f48
Reuse RenderWorker type (#53782)
Found that this type was duplicated. This just reuses the existing definition.
2023-08-10 04:35:33 +00:00
JJ Kasper
6bd8cd7cac
Ensure we set cache-control: no-cache for actions (#53824)
This ensures we don't accidentally allow caching server actions causing unexpected behavior.
2023-08-09 23:59:42 +00:00
Luud Janssen
5fe332186e
Add changeFrequency and priority attributes to sitemaps (#48484)
Closes #48479. 

Couldn't find the source for the Next.js beta docs, so I didn't add documentation.

Co-authored-by: Jiachi Liu <4800338+huozhi@users.noreply.github.com>
2023-08-09 20:36:22 +00:00
Zack Tanner
712669f605
improve error message for conflicting parallel segments (#53803)
This is a follow-up to log both conflicting paths & a link to route group docs, which I believe is the only scenario someone could trigger this

- https://github.com/vercel/next.js/pull/53752
2023-08-09 17:21:24 +00:00
JJ Kasper
7d67f00f8f
Sort root entries per pageExtensions config for consistency (#53769)
While running our `test/integration/middleware-src` test suite across
systems, noticed this behaved inconsistently due to us relying on the
order the filesystem ordered duplicates e.g. `middleware.ts` and
`middleware.js`.

Considering we already have a loud warning for this duplicate this adds
consistency across systems by ensuring these are sorted per our
pageExtensions order which is `ts` takes priority over `js` by default.

An additional test case was not added as the above mentioned suite
covers this but was verified as passing on one of the systems (mac OS)
where it was not previously.
2023-08-09 09:54:55 -07:00
JJ Kasper
4b4533787b
Add warnings for static generation bail outs (#53761)
Currently using server actions on a page or using edge runtime causes
that page to bail out of ISR or static generation so this adds warnings
to make users aware of this.

x-ref: [slack
thread](https://vercel.slack.com/archives/C03KAR5DCKC/p1690816539472449)

---------

Co-authored-by: Zack Tanner <zacktanner@gmail.com>
2023-08-08 20:09:34 -07:00
Vercel Release Bot
5c9553002c
Update font data (#53759)
This auto-generated PR updates font data with latest available
2023-08-09 01:10:50 +00:00
Eric Fennis
5e716ec918
fix: Update outdated transform imports lucide-react (#53697)
### What?

Fixing outdated import mapping with the latest `lucide-react` changes. See [lucide-icons/lucide@v0.264.0](https://github.com/lucide-icons/lucide/releases/tag/v0.264.0)

Closes: lucide-icons/lucide#1482

### Why?

Import mapping was outdated

### How?

By updating the default config and the tests.

## Notes

Maintainer here from @lucide-icons.
To this day I didn't know the Nextjs default config file has predefined hardcoded modularize imports. 
I was a bit surprised that there is a default mapping for libraries that could change in the future like Lucide. 

I'm not in favor of this hardcoded "modularize imports", because this creates a hard dependency on libraries. With Lucide, we still have not reached 1.0 and will sometimes rename icons and add aliases for them. So issues will occur in the future, and constantly updating this config doesn't feel right. 

Is there, not a better way? Like for example, a package exposing a config file containing the import mapping?
This way import map will automatically be in sync with changes in a package. 

Let me know what you think of this.
2023-08-09 00:48:48 +00:00
Josh Story
79b7c1493b
App Router Preinitialize all required scripts except one for bootstrap (#53705)
Currently all scripts that are required for every page are loaded as
part of the bootstrap scripts API in React. Unfortunately this loads
them all as sync scripts and thus requires preloading which increases
their priority higher than they might otherwise be causing things like
images to load later than desired, blocking paint. We can improve this
by only using one script for bootstrapping and having the rest
pre-initialized. This only works because all of these scripts are
webpack runtime or chunks and can be loaded in any order asynchronously.

With this change we should see improvements in LCP and other metrics as
preloads for images are favored over loading scripts

Co-authored-by: Steven <steven@ceriously.com>
2023-08-08 17:28:17 -07:00
Zack Tanner
d58fd68f0a
fix parallel route tests & improve error for conflicting pages (#53752)
This fixes some tests that were disabled due to a missing `page` segment for the corresponding slots in `/parallel/nested`. 

While fixing, I also noticed if you accidentally create two pages that resolve to the same URL segment (which is fairly easy to do accidentally do with route groups), we were throwing an unhelpful error of "Cannot find module: '<snip>/page_client-reference-manifest.js'" when building (and fail silently in dev). For example, this scenario was throwing a manifest error:

```
app
  (groupa)
    page.tsx
  (groupb)
    page.tsx
```

This will now throw with a more helpful error when resolving parallel segments if the page segment was already resolved. This also re-enables the disabled tests.

Closes NEXT-1440
Fixes #53569 (by virtue of throwing a more helpful error)
2023-08-08 22:56:39 +00:00
Josh Story
f0dab3a8da
update vendored React packages to the the latest canary (#53742)
Updated React from 9377e1010 to cb3404a0c.

### React upstream changes

- https://github.com/facebook/react/pull/27190
- https://github.com/facebook/react/pull/27189
- https://github.com/facebook/react/pull/27201
- https://github.com/facebook/react/pull/27147
- https://github.com/facebook/react/pull/26949
- https://github.com/facebook/react/pull/27058
- https://github.com/facebook/react/pull/27142
- https://github.com/facebook/react/pull/27133
- https://github.com/facebook/react/pull/27130
- https://github.com/facebook/react/pull/27105
- https://github.com/facebook/react/pull/27117
- https://github.com/facebook/react/pull/27057
2023-08-08 20:16:24 +00:00
Zack Tanner
ee15b3be5d
fix: error overlay hijacking application focus (safari) (#53693)
### What?
When Safari is in the background and HMR triggers a full page reload,
Safari hijacks application focus.

### Why?
Having a `role="dialog"` is correctly prompting Safari to autofocus the
first focusable element (the close button). However, Safari's behavior
seems to also bring the application to the foreground when a background
focus event occurs.

### How?
This only adds the role when the document is focused. 

#### Before

https://github.com/vercel/next.js/assets/1939140/9d2cce52-c6ee-4d49-9262-03620efad86c

#### After

https://github.com/vercel/next.js/assets/1939140/dc7d337c-b621-49e9-9a17-03b5d8b5c3f4

Confirmed voiceover behavior still appears to be correct
<img width="1371" alt="CleanShot 2023-08-07 at 12 14 34@2x"
src="https://github.com/vercel/next.js/assets/1939140/e53acfbc-cf6b-4d74-8b83-cf98edb2c2ab">

slack x-ref:
https://vercel.slack.com/archives/C03KAR5DCKC/p1691264077313599

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2023-08-08 21:45:03 +02:00
Tobias Koppers
9d1b3f43a1
Turbopack: add hmr test case and fix bugs (#53719)
### What?

test case for HMR

### Turbopack Changes

* https://github.com/vercel/turbo/pull/5686 <!-- Tobias Koppers - remove
error in update -->
2023-08-08 17:07:24 +02:00
vercel-release-bot
d7405b0c28 v13.4.14-canary.1 2023-08-08 14:11:47 +00:00
Tim Neutkens
c5a8e0989e
Consolidate Server and Routing process into one process (#53523)
In the current version of Next.js there are 4 processes when running in
production:

- Server
- Routing
- Rendering Pages Router
- Rendering App Router

This setup was introduced in order to allow App Router and Pages Router
to use different versions of React (i.e. Server Actions currently
requires react@experimental to function). I wrote down more on why these
processes exist in this comment:
https://github.com/vercel/next.js/issues/49929#issuecomment-1637185156

This PR combines the Server and Routing process into one handler, as the
"Server" process was only proxying to the Routing process. In my testing
this caused about ~2x the amount of memory per request as the response
body was duplicated between the processes. This was especially visible
in the case of that memory leak in Node.js 18.16 as it grew memory usage
on both sides quickly.

In the process of going through these changes I found a couple of other
bugs like the propagation of values to the worker processes not being
awaited
([link](https://github.com/vercel/next.js/pull/53523/files#diff-0ef09f360141930bb03263b378d37d71ad9432ac851679aeabc577923536df84R54))
and the dot syntax for propagation was not functioning.

It also seemed there were a few cases where watchpack was used that
would cause many more files to be watched than expected, for now I've
removed those cases, specifically the "delete dir while running" and
instrument.js hmr (instrument.js is experimental). Those tests have been
skipped for now until we can revisit them to verfiy it

I've also cleaned up the types a bit while I was looking into these
changes.

### Improvement

⚠️ Important preface to this, measuring memory usage / peak usage is not
super reliable especially when JS gets garbage collected. These numbers
are just to show the rough percentage of less memory usage.

#### Baseline

Old:

```
next-server: 44.8MB
next-router-worker: 57.5MB
next-render-worker-app: 39,6MB
next-render-worker-pages: 39,1MB
```

New:

```
next-server: Removed
next-router-worker: 64.4MB
next-render-worker-app: 43.1MB (Note: no changes here, this shows what I meant by rough numbers)
next-render-worker-pages: 42.4MB (Note: no changes here, this shows what I meant by rough numbers)
```

Overall win: ~40MB (process is removed)

#### Peak usage

Old:

```
next-server: 118.6MB
next-router-worker: 223.7MB
next-render-worker-app: 32.8MB (I ran the test on a pages application in this case)
next-render-worker-pages: 101.1MB
```

New:

```
next-server: Removed
next-router-worker: 179.1MB
next-render-worker-app: 33.4MB
next-render-worker-pages: 117.5MB
```

Overall win: ~100MB (but it scales with requests so it was about ~50% of
next-router-worker constantly)

Related: #53523

---------

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2023-08-08 16:06:32 +02:00
Zack Tanner
fef6f82aba
Add docs page for uncaught DynamicServerErrors (#53402)
When using imports from `next/headers` in a layout or page,
`StaticGenerationBailout` will throw an error to indicate Next.js should
fallback to dynamic rendering. However, when async context is lost, this
error is uncaught and leads to a confusing error message at build time.

This attempts to improve DX surrounding this error by linking out to a
page that explains when it might happen. I've also tweaked
`StaticGenerationBailout` to always throw a fully descriptive reason as
opposed to just `DynamicServerError: Dynamic server usage: cookies`

Closes NEXT-1181
Fixes #49373

---------

Co-authored-by: Lee Robinson <me@leerob.io>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2023-08-08 12:49:53 +02:00
Balázs Orbán
b41497d763
fix(next/image): don't call ReactDOM.preload if missing, such as jest (#53443)
### What?

`ReactDOM.preload` is available in `react-dom@experimental` builds. If it's not available, we should fall back to `Head`+`link`

### Why?

Since `ReactDOM.preload` is only available in `react-dom@experimental` builds, certain environments (like Jest or [Storybook](https://github.com/storybookjs/storybook/issues/23661)) might have a version of `react-dom` installed that won't work with `preload()`

### How?

Closes NEXT-1482
Fixes #53272

See also: https://github.com/storybookjs/storybook/issues/23661

Co-authored-by: Steven <229881+styfle@users.noreply.github.com>
2023-08-08 01:04:40 +00:00
Jiachi Liu
9035f14dda
Fix not-found rendering in production with edge (#53687)
Edge runtime doesn't have `/404` entry points as not-found, if server hits 404 it's hitting `/_not-found` entry point of edge bundles unlike nodejs server rendering.

In app-render it needs the information that when `pathname` (or can call `pagePath`) is `/404` it can render the `not-found.js` components properly

Separate the not-found test suite into 2 parts, a basic case testing all urls with `not-found.js` boundary, and another conflict route case with `not-found.js` with `not-found/` route at the same time

Fixes #53652
Fixes #53210
2023-08-07 20:05:22 +00:00
Janicklas Ralph
033732a3e5
Adding GoogleMaps and Youtube embed components (#52909)
Adding GoogleMapsEmbed and YoutubeEmber components into `@next/third-parties`
Adding tests and README
Each component is tagged with `data-ntpc` attribute

cc: @kara @housseindjirdeh @huozhi @gnoff 




Co-authored-by: Jiachi Liu <4800338+huozhi@users.noreply.github.com>
2023-08-07 19:38:13 +00:00
Tobias Koppers
654bd8c803
add unit test case for next.rs api (#53679)
### What?

unit test for next.rs api

### Why?

ensure that it's working

### How?
2023-08-07 19:26:44 +02:00
Steven
7ec76eb7e4
fix(create-next-app): fix CI defaults (default to typescript) (#53686)
Since the default for `create-next-app` has been TypeScript for some time, we should make sure this is also the case for CI.

This PR also makes sure that CI will use the same value as if the question was asked. Therefore changing defaults in the future will automatically change the behavior of CI defaults.

- Related https://github.com/vercel/next.js/issues/42592
2023-08-07 17:24:45 +00:00
Alex Kirszenberg
589150184e
Turbopack: Hide Turbo Engine internals (#53007)
See https://github.com/vercel/turbo/pull/5584
2023-08-07 14:55:13 +00:00
vercel-release-bot
5ea372d642 v13.4.14-canary.0 2023-08-07 12:49:08 +00:00
Tobias Koppers
25e6db4274
Turbopack: add edge app routes (#53387)
### What?

* adds middleware manifest and other missing items for edge app routes
* fixes react-server condition in edge context
* fixes node.js route context

---------

Co-authored-by: Alex Kirszenberg <alex.kirszenberg@vercel.com>
2023-08-07 13:00:06 +02:00
Alex Kirszenberg
9483ff170a
Initial HMR Nexturbo API implementation (#52950)
This implements a MVP of HMR. HMR works similarly as in turbopack-dev-server, but instead of going through the router to retrieve output assets, output assets are eagerly stored into a global hash map, and retrieved directly from there (see `VersionedContentMap`).

This will require some more glue on the Next.js side in order to handle:
* RSC headers;
* handling Turbopack subscriptiob HMR events from the Next.js WS server, proxying them to `hmr_events`, and sending back the stream of updates.

There's currently no way to evict deleted output assets, nor to communicate these events to the client. @sokra mentioned the `VersionedContentMap` could store a list of assets per entrypoint, instead of having a top-level flat map.

Co-authored-by: Tobias Koppers <1365881+sokra@users.noreply.github.com>
2023-08-07 10:37:57 +00:00
yudai yamamoto
b993afbf7c
Fix action failures due to state tree encoding (#53655)
fixes #53654

### Related PRs
- #51017
2023-08-07 10:02:48 +00:00
vercel-release-bot
498692b698 v13.4.13 2023-08-07 06:57:47 +00:00
vercel-release-bot
1e02a92a94 v13.4.13-canary.18 2023-08-07 01:06:01 +00:00
JJ Kasper
3c55417f16
Update font data (#53649)
This auto-generated PR updates font data with latest available

Co-authored-by: vercel-release-bot <infra+release@vercel.com>
2023-08-06 17:54:10 -07:00
JJ Kasper
bb380e7715
Fix other case for buildId mismatch (#53643)
Continues fix from https://github.com/vercel/next.js/pull/53596 and
applies it for the `x-matched-path` specific code path.
2023-08-06 15:47:20 -07:00
vercel-release-bot
bc8deab6ef v13.4.13-canary.17 2023-08-06 20:38:12 +00:00
JJ Kasper
f11406015c
Fix tracing in require-hook (#53642)
This ensures the resolve calls for `styled-jsx` are done in the correct context so that tracing can include the correct symlinks/package.json files. 

x-ref: [slack thread](https://vercel.slack.com/archives/C03S8ED1DKM/p1691217652833079)
2023-08-06 20:23:20 +00:00
JJ Kasper
7bf3d77b5e
Revert "Implement new forking technique for vendored packages. (#51083)" (#53640)
This reverts commit e06880ea4c.

reverts: https://github.com/vercel/next.js/pull/51083

x-ref: [slack
thread](https://vercel.slack.com/archives/C04DUD7EB1B/p1691349686136519)
x-ref: [slack
thread](https://vercel.slack.com/archives/C03S8ED1DKM/p1691349579712979?thread_ts=1691217652.833079&cid=C03S8ED1DKM)
2023-08-06 13:00:12 -07:00
vercel-release-bot
f47081f15b v13.4.13-canary.16 2023-08-05 00:20:47 +00:00
Zack Tanner
26c19b1fa2
return a 404 when /next/_data build IDs are mismatched (#53596)
`normalizeNextData` in `next-server` used to exit early with a 404 when there was a build ID mismatch, but a recent refactor accidentally removed this functionality. This PR updates it to behave similarly to [web-server](https://github.com/vercel/next.js/blob/canary/packages/next/src/server/web-server.ts#L180-L187) where we render404 if there's a mismatch.

[slack x-ref](https://vercel.slack.com/archives/C03S8ED1DKM/p1691111541353749)
2023-08-05 00:15:42 +00:00
Josh Story
e06880ea4c
Implement new forking technique for vendored packages. (#51083)
## Vendoring

Updates all module resolvers (node, webpack, nft for entrypoints, and nft for next-server) to consider whether vendored packages are suitable for a given resolve request and resolves them in an import semantics preserving way.

### Problem

Prior to the proposed change, vendoring has been accomplished but aliasing module requests from one specifier to a different specifier. For instance if we are using the built-in react packages for a build/runtime we might replace `require('react')` with `require('next/dist/compiled/react')`.

However this aliasing introduces a subtle bug. The React package has an export map that considers the condition `react-server` and when you require/import `'react'` the conditions should be considered and the underlying implementation of react may differ from one environment to another. In particular if you are resolving with the `react-server` condition you will be resolving the `react.shared-subset.js` implementation of React. This aliasing however breaks these semantics because it turns a bare specifier resolution of `react` with path `'.'` into a resolution with bare specifier `next` with path `'/dist/compiled/react'`. Module resolvers consider export maps of the package being imported from but in the case of `next` there is no consideration for the condition `react-server` and this resolution ends up pulling in the `index.js` implementation inside the React package by doing a simple path resolution to that package folder.

To work around this bug there is a prevalence of encoding the "right" resolution into the import itself. We for instance directly alias `react` to `next/dist/compiled/react/react.shared-subset.js` in certain cases. Other times we directly specify the runtime variant for instance `react-server-dom-webpack/server.edge` rather than `react-server-dom-wegbpack/server`, bypassing the export map altogether by selecting the runtime specific variant. However some code is meant to run in more than one runtime, for instance anything that is part of the client bundle which executes on the server during SSR and in the browser. There are workaround like using `require` conditionally or `import(...)` dynamically but these all have consequences for bundling and treeshaking and they still require careful consideration of the environment you are running in and which variant needs to load.

The result is that there is a large amount of manual pinning of aliases and additional complexity in the code and an inability to trust the package to specify the right resolution potentially causing conflicts in future versions as packages are updated.

It should be noted that aliasing is not in and of itself problematic when we are trying to implement a sort of lightweight forking based on build or runtime conditions. We have good examples of this for instance with the `next/head` package which within App Router should export a noop function. The problem is when we are trying to vendor an entire package and have the package behave semantically the same as if you had installed it yourself via node_modules

### Solution

The fix is seemingly straight forward. We need to stop aliasing these module specifiers and instead customize the resolution process to resolve from a location that will contain the desired vendored packages. We can then start simplifying our imports to use top level package resources and generally and let import conditions control the process of providing the right variant in the right context.

It should be said that vendoring is conditional. Currently we only vendor react pacakges for App Router runtimes. The implementation needs to be able to conditionally determine where a package resolves based on whether we're in an App Router context vs a Page Router one.

Additionally the implementation needs to support alternate packages such as supporting the experimental channel for React when using features that require this version.

### Implementation

The first step is to put the vendored packages inside a node_modules folder. This is essential to the correct resolving of packages by most tools that implement module resolution. For packages that are meant to be vendored, meaning whole package substitution we move the from `next/(src|dist)/compiled/...` to `next/(src|dist)/vendored/node_modules`. The purpose of this move is to clarify that vendored packages operate with a different implementation. This initial PR moves the react dependencies for App Router and `client-only` and `server-only` packages into this folder. In the future we can decide which other precompiled dependencies are best implemented as vendored packages and move them over.

It should be noted that because of our use of `JestWorker` we can get warnings for duplicate package names so we modify the vendored pacakges for react adding either `-vendored` or `-experimental-vendored` depending on which release channel the package came from. While this will require us to alter the request string for a module specifier it will still be treating the react package as the bare specifier and thus use the export map as required.

#### module resolvers
The next thing we need to do is have all systems that do module resolution implement an custom module resolution step. There are five different resolvers that need to be considered

##### node runtime
Updated the require-hook to resolve from the vendored directory without rewriting the request string to alter which package is identified in the bare specifier. For react packages we only do this vendoring if the `process.env.__NEXT_PRIVATE_PREBUNDLED_REACT` envvar is set indicating the runtime is server App Router builds. If we need a single node runtime to be able to conditionally resolve to both vendored and non vendored versions we will need to combine this with aliasing and encode whether the request is for the vendored version in the request string. Our current architecture does not require this though so we will just rely on the envvar for now

##### webpack runtime
Removed all aliases configured for react packages. Rely on the node-runtime to properly alias external react dependencies. Add a resolver plugin `NextAppResolverPlugin` to preempt perform resolution from the context of the vendored directory when encountering a vendored eligible package.

##### turbopack runtime
updated the aliasing rules for react packages to resolve from the vendored directory when in an App Router context. This implementation is all essentially config b/c the capability of doing the resolve from any position (i.e. the vendored directory) already exists

##### nft entrypoints runtime
track chunks to trace for App Router separate from Pages Router. For the trace for App Router chunks use a custom resolve hook in nft which performs the resolution from the vendored directory when appropriate.

##### nft next-server runtime
The current implementation for next-server traces both node_modules and vendored version of packages so all versions are included. This is necessary because the next server can run in either context (App vs Page router) and may depend on any possible variants. We could in theory make two traces rather than a combined one but this will require additional downstream changes so for now it is the most conservative thing to do and is correct

Once we have the correct resolution semantics for all resolvers we can start to remove instances targeting our precompiled instances for instance making `import ... from "next/dist/compiled/react-server-dom-webpack/client"` and replacing with `import ... from "react-server-dom-webpack/client"`

We can also stop requiring runtime specific variants like `import ... from "react-server-dom-webpack/client.edge"` replacing it with the generic export `"react-server-dom-webpack/client"`

There are still two special case aliases related to react
1. In profiling mode (browser only) we rewrite `react-dom` to `react-dom/profiling` and `scheduler/tracing` to `scheduler/tracing-profiling`. This can be moved to using export maps and conditions once react publishses updates that implement this on the package side.
2. When resolving `react-dom` on the server we rewrite this to `react-dom/server-rendering-stub`. This is to avoid loading the entire react-dom client bundle on the server when most of it goes unused. In the next major react will update this top level export to only contain the parts that are usable in any runtime and this alias can be dropped entirely

There are two non-react packages currently be vendored that I have maintained but think we ought to discuss the validity of vendoring. The `client-only` and `server-only` packages are vendored so you can use them without having to remember to install them into your project. This is convenient but does perhaps become surprising if you don't realize what is happening. We should consider not doing this but we can make that decision in another discussion/PR.

#### Webpack Layers
One of the things our webpack config implements for App Router is layers which allow us to have separate instances of packages for the server components graph and the client (ssr) graph. The way we were managing layer selection was a but arbitrary so in addition to the other webpack changes the way you cause a file to always end up in a specific layer is to end it with `.serverlayer`, `.clientlayer` or `.sharedlayer`. These act as layer portals so something in the server layer can import `foo.clientlayer` and that module will in fact be bundled in the client layer.

#### Packaging Changes
Most package managers are fine with this resolution redirect however yarn berry (yarn 2+ with PnP) will not resolve packages that are not defined in a package.json as a dependency. This was not a problem with the prior strategy because it was never resolving these vendored packages it was always resolving the next package and then just pointing to a file within it that happened to be from react or a related package.

To get around this issue vendored packages are both committed in src and packed as a tgz file. Then in the next package.json we define these vendored packages as `optionalDependency` pointing to these tarballs. For yarn PnP these packed versions will get used and resolved rather than the locally commited src files. For other package managers the optional dependencies may or may not get installed but the resolution will still resolve to the checked in src files. This isn't a particularly satisfying implemenation and if pnpm were to be updated to have consistent behavior installing from tarballs we could actually move the vendoring entirely to dependencies and simplify our resolvers a fair bit. But this will require an upstream chagne in pnpm and would take time to propogate in the community since many use older versions

#### Upstream Changes

As part of this work I landed some other changes upstream that were necessary. One was to make our packing use `npm` to match our publishing step. This also allows us to pack `node_modules` folders which is normally not supported but is possible if you define the folder in the package.json's files property.

See: #52563

Additionally nft did not provide a way to use the internal resolver if you were going to use the resolve hook so that is now exposed

See: https://github.com/vercel/nft/pull/354

#### additional PR trivia
* When we prepare to make an isolated next install for integration tests we exclude node_modules by default so we have a special case to allow `/vendored/node_modules`

* The webpack module rules were refactored to be a little easier to reason about and while they do work as is it would be better for some of them to be wrapped in a `oneOf` rule however there is a bug in our css loader implementation that causes these oneOf rules to get deleted. We should fix this up in a followup to make the rules a little more robuts.


## Edits
* I removed `.sharedlayer` since this concept is leaky (not really related to the client/server boundary split) and it is getting refactored anyway soon into a precompiled runtime.
2023-08-04 23:47:10 +00:00
JJ Kasper
e4aecabc7d
Update ISR revalidateTag handling (#53595)
This ensures `revalidateTag()` doesn't cause an async/background revalidation unexpectedly and instead does a blocking revalidate so fresh data is shown right away when a path is using ISR. 

Test deployment with patch can be seen here: https://next-revalidation-test-47rqf8q5s-vtest314-ijjk-testing.vercel.app/

Fixes: https://github.com/vercel/next.js/issues/53187
2023-08-04 23:31:18 +00:00
Wyatt Johnson
1df2686bc9
Remove Base Path from usePathname output (#53582)
This removes the `basePath` from the output of `usePathname`. Previously this always resulted in hydration errors, this now strips the `basePath` when it's found/configured.

Now when you configure `basePath`, you don't have to factor it into your application logic and can instead rely on the values always returning the pathname without it.

Fixes #46562
2023-08-04 22:10:00 +00:00
Will Binns-Smith
1d8a633595
Update to turbopack-230804.2 (#53588)
- vercel/turbo#5671
- vercel/turbo#5675
- vercel/turbo#5676
- vercel/turbo#5662
- vercel/turbo#5663
2023-08-04 21:51:35 +00:00
Steven
e7a3fd9163
chore(lint): fix lint warning about unused import current_dir (#53587)
<img width="660" alt="image" src="https://github.com/vercel/next.js/assets/229881/a9cc7270-7aee-4258-b30e-b371d9924a64">
2023-08-04 20:14:34 +00:00
Leah
542c4fc26a
chore: update to pnpm@8.6.11 (#50923)
https://github.com/pnpm/pnpm/releases/tag/v8.0.0
2023-08-04 19:40:20 +00:00
Tobias Koppers
94709ef1b9
update turbopack and update code for API changes (#53576)
* https://github.com/vercel/turbo/pull/5640
* https://github.com/vercel/turbo/pull/5661
2023-08-04 21:14:41 +02:00
vercel-release-bot
324814f2ae v13.4.13-canary.15 2023-08-04 19:13:19 +00:00
Jiachi Liu
ab14895ada
Fix dynamic route not-found boundary matching (#53564)
### What & Why

The dynamic not-found boundary didn't work as expected as it was using the `pathname` to match how many levels of the segements should be matched. For dynamic routes this doesn't work, unlike normal page, the unmatched segment can also hit the not found boundary in the same level.

### How

Use `segment` of loader tree nodes to determine if not-found boundary searching is reached to the end instead of using `pathname`. 
> NOTE: For production `/_not-found` case since it's a valid page on production and still has the original tree, so we handle that as a special case to use the not found loader tree (with empty child routes) to render.

Fixes #53344
2023-08-04 16:07:58 +00:00
Jiachi Liu
cc4879d1dc
Move metadata error under error boundaries (#53551)
### What & Why

Using `notFound()` in `generateMetadata()` or in page will lead to unacught global not found error when you do navigation, this is because `head` cache is actually not inside the error boundary as designed to stay in the beginning of the content. But in this way we won't be able to catch the notFound error thrown from metadata API. So we created a new approach that can separate the error itself from metadata result, and throw as error under the error boundaries, and metadata itself will always be safe to render.

### How

We use a new promise that resolve the `error` thrown from metadata resolving, and let the render result always return successfully and always has a value, using default metadata when there's error thrown. Create two components, one rendering the metadata tags, and another `MetadataOutlet` to throw the error when the resolving is failed but rendered under error boundaries.



```jsx
const [MetadataTree, MetadataOutlet] = createMetadataComponents(/*...*/)
const ComponentTree = createComponentTree({ metadataOutlet: <MetadataOutlet /> })

renderRSC(
  <AppRourer head={<MetadataTree />}>
    <ComponentTree />
  </AppRourer>
)
```

`metadataOutlet` will stay next to page component in the layout hierarchy

discuessed with @gnoff 

Minor changes: 

* When there's rendering root layout layer, not found boundary should be `DefaultNotFound` if the custom one doesn't exisit


Fixes #53371
Fixes #53149
2023-08-04 15:32:36 +00:00
vercel-release-bot
f04dc5ad51 v13.4.13-canary.14 2023-08-04 09:02:27 +00:00
Tobias Koppers
4ea1d8a45d
update turbopack (#53545)
* https://github.com/vercel/turbo/pull/5582 
* https://github.com/vercel/turbo/pull/5633 
* https://github.com/vercel/turbo/pull/5637 
* https://github.com/vercel/turbo/pull/5648 <!-- OJ Kwon - test(turbopack): run daily with --experimental  -->
* https://github.com/vercel/turbo/pull/5618 
* https://github.com/vercel/turbo/pull/5624 
* https://github.com/vercel/turbo/pull/5597 
* https://github.com/vercel/turbo/pull/5632 
* https://github.com/vercel/turbo/pull/5636 
* https://github.com/vercel/turbo/pull/5666
2023-08-04 07:19:20 +00:00
Tobias Koppers
82280ea82b
add support for EXPERIMENTAL_TURBOPACK in next build (#53535)
### What?

EXPERIMENTAL_TURBOPACK env var puts next build into turbopack mode

### Why?

the test cases set this flag
2023-08-04 07:27:06 +02:00
Colin McDonnell
57ce466502
Add --use-bun to create-next-app (#53467)
This adds support for `--use-bun` to `create-next-app` to use `bun
install` when bootstrapping a new project.

```
npx create-next-app --use-bun
```

As with Yarn and pnpm, it reads from `npm_config_user_agent` to
determine if the user ran `bunx create-next-app`. If so, it defaults to
using Bun.

```sh
bunx create-next-app
```

## For Contributors

### Improving Documentation

- [x] Run `pnpm prettier-fix`
- [x] `pnpm build && pnpm lint` 
- [x] Added test to
`test/integration/create-next-app/package-manager.test.ts`

---------
2023-08-03 18:00:38 -07:00
lijianan
b224f47f23
chore: remove useless curly brackets from next/legacy/image (#53534)
<!-- 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 #

-->

remove useless parentheses
2023-08-03 17:13:41 -07:00
Balázs Orbán
9477b61b51
fix(next): clarify fetch polyfill, drop node-fetch (#53548)
### What?

Fix documentation about `fetch` polyfilling, and drop `node-fetch` references.

### Why?

Since we stopped using `node-fetch` in `next` in favor of `undici` there were some inconsistencies in the docs, and unused references to the `node-fetch` package inside `packages/next`-


Noted this while answering this [Slack thread](https://vercel.slack.com/archives/C03S8ED1DKM/p1691089801007129)
2023-08-03 23:12:26 +00:00
Zack Tanner
f8a4e0f3c3
fix: fetch deduping in dev (#53549)
This attempts to fix an issue where fetch requests were not being
deduped on the first request to the page (but subsequent requests were
properly deduped).

This seems to be caused by the async context from
`staticGenerationStore` being lost by the time the patched fetch is
called, and so it was falling back to a regular fetch and skipping the
cache. This attempts to fix that by falling back to
`fetch.__nextGetStaticStore()`.

[slack
x-ref](https://vercel.slack.com/archives/C03KAR5DCKC/p1691007445597619)
2023-08-03 15:10:55 -07:00
OJ Kwon
630c41cd92
feat(next): next info --verbose for additional details (#53181)
### What?

First phase implementation for WEB-1313.

This PR expands existing `next info` features by adding new flag `--run-diags`. When this flag is supplied, next.js will try to collect more information. Primarily informations are related to next-swc installation to see if it's possible to diagnose why next-swc cannot be loaded on certain systems. It is not a definitive list - depends on the findings we may increase more items to collect.

These are the list of status included in the output

- Host info: CI / WSL / Docker
- Next.js installation: node, pkg mger version, next.js pkg
- Partial Node.js diagnostics report: `header, javascriptHeap, sharedObjects`
- next-swc installation: check if installed next-swc can be loaded
- (Mac os only) next-swc shared object dependencies: using `otool` or `dyld_info` to collect binary dependencies. Linux / Windows support will follow later.

Below's an example generated report, expect user to attach into issue if there are failures. 

<details>

```
### Host system information


  WSL: false
  Docker: false
  CI: false


### Next.js installation


  Binaries:
    Node: 18.11.0
    npm: 8.19.2
    Yarn: N/A
    pnpm: 7.24.3
  Relevant Packages:
    next: 13.4.13-canary.1
    eslint-config-next: 13.4.13-canary.1
    react: 18.2.0
    react-dom: 18.2.0
    typescript: 5.1.3
  Next.js Config:
    output: N/A



### Node.js diagnostic report

{
  "header": {
    "reportVersion": 2,
    "event": "JavaScript API",
    "trigger": "GetReport",
    "filename": null,
    "dumpEventTime": "2023-07-25T14:13:32Z",
    "dumpEventTimeStamp": "1690319612854",
    "processId": 33203,
    "threadId": 0,
    "nodejsVersion": "v18.11.0",
    "wordSize": 64,
    "arch": "arm64",
    "platform": "darwin",
    "componentVersions": {
      "node": "18.11.0",
      "v8": "10.2.154.15-node.12",
      "uv": "1.43.0",
      "zlib": "1.2.11",
      "brotli": "1.0.9",
      "ares": "1.18.1",
      "modules": "108",
      "nghttp2": "1.47.0",
      "napi": "8",
      "llhttp": "6.0.10",
      "openssl": "3.0.5+quic",
      "cldr": "41.0",
      "icu": "71.1",
      "tz": "2022b",
      "unicode": "14.0",
      "ngtcp2": "0.8.1",
      "nghttp3": "0.7.0"
    },
    "release": {
      "name": "node",
      "headersUrl": "https://nodejs.org/download/release/v18.11.0/node-v18.11.0-headers.tar.gz",
      "sourceUrl": "https://nodejs.org/download/release/v18.11.0/node-v18.11.0.tar.gz"
    },
    "osName": "Darwin",
    "osRelease": "22.5.0",
    "osVersion": "Darwin Kernel Version 22.5.0: Thu Jun  8 22:22:20 PDT 2023; root:xnu-8796.121.3~7/RELEASE_ARM64_T6000",
    "osMachine": "arm64"
  },
  "javascriptHeap": {
    "totalMemory": 25624576,
    "executableMemory": 1048576,
    "totalCommittedMemory": 23543808,
    "availableMemory": 4324923368,
    "totalGlobalHandlesMemory": 16384,
    "usedGlobalHandlesMemory": 8384,
    "usedMemory": 20296720,
    "memoryLimit": 4345298944,
    "mallocedMemory": 1431256,
    "externalMemory": 1450294,
    "peakMallocedMemory": 6525792,
    "nativeContextCount": 1,
    "detachedContextCount": 0,
    "doesZapGarbage": 0,
    "heapSpaces": {
      "read_only_space": {
        "memorySize": 0,
        "committedMemory": 0,
        "capacity": 0,
        "used": 0,
        "available": 0
      },
      "old_space": {
        "memorySize": 8994816,
        "committedMemory": 9175040,
        "capacity": 8830992,
        "used": 8829704,
        "available": 1288
      },
      "code_space": {
        "memorySize": 966656,
        "committedMemory": 917504,
        "capacity": 765440,
        "used": 762496,
        "available": 2944
      },
      "map_space": {
        "memorySize": 802816,
        "committedMemory": 1048576,
        "capacity": 773376,
        "used": 773264,
        "available": 112
      },
      "large_object_space": {
        "memorySize": 6094848,
        "committedMemory": 6094848,
        "capacity": 6056016,
        "used": 6056016,
        "available": 0
      },
      "code_large_object_space": {
        "memorySize": 0,
        "committedMemory": 0,
        "capacity": 0,
        "used": 0,
        "available": 0
      },
      "new_large_object_space": {
        "memorySize": 376832,
        "committedMemory": 376832,
        "capacity": 4995992,
        "used": 351088,
        "available": 4644904
      },
      "new_space": {
        "memorySize": 8388608,
        "committedMemory": 5931008,
        "capacity": 4123904,
        "used": 3524152,
        "available": 599752
      }
    }
  },
  "sharedObjects": [
    "/Users/ojkwon/Library/Application Support/fnm/node-versions/v18.11.0/installation/bin/node",
    "/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation",
    "/usr/lib/libobjc.A.dylib",
    "/System/Library/PrivateFrameworks/CoreServicesInternal.framework/Versions/A/CoreServicesInternal",
    "/usr/lib/liboah.dylib",
    "/usr/lib/libfakelink.dylib",
    "/usr/lib/libicucore.A.dylib",
    "/usr/lib/libSystem.B.dylib",
    "/System/Library/PrivateFrameworks/SoftLinking.framework/Versions/A/SoftLinking",
    "/usr/lib/libc++abi.dylib",
    "/usr/lib/libc++.1.dylib",
    "/usr/lib/system/libcache.dylib",
    "/usr/lib/system/libcommonCrypto.dylib",
    "/usr/lib/system/libcompiler_rt.dylib",
    "/usr/lib/system/libcopyfile.dylib",
    "/usr/lib/system/libcorecrypto.dylib",
    "/usr/lib/system/libdispatch.dylib",
    "/usr/lib/system/libdyld.dylib",
    "/usr/lib/system/libkeymgr.dylib",
    "/usr/lib/system/libmacho.dylib",
    "/usr/lib/system/libquarantine.dylib",
    "/usr/lib/system/libremovefile.dylib",
    "/usr/lib/system/libsystem_asl.dylib",
    "/usr/lib/system/libsystem_blocks.dylib",
    "/usr/lib/system/libsystem_c.dylib",
    "/usr/lib/system/libsystem_collections.dylib",
    "/usr/lib/system/libsystem_configuration.dylib",
    "/usr/lib/system/libsystem_containermanager.dylib",
    "/usr/lib/system/libsystem_coreservices.dylib",
    "/usr/lib/system/libsystem_darwin.dylib",
    "/usr/lib/system/libsystem_dnssd.dylib",
    "/usr/lib/system/libsystem_featureflags.dylib",
    "/usr/lib/system/libsystem_info.dylib",
    "/usr/lib/system/libsystem_m.dylib",
    "/usr/lib/system/libsystem_malloc.dylib",
    "/usr/lib/system/libsystem_networkextension.dylib",
    "/usr/lib/system/libsystem_notify.dylib",
    "/usr/lib/system/libsystem_sandbox.dylib",
    "/usr/lib/system/libsystem_secinit.dylib",
    "/usr/lib/system/libsystem_kernel.dylib",
    "/usr/lib/system/libsystem_platform.dylib",
    "/usr/lib/system/libsystem_pthread.dylib",
    "/usr/lib/system/libsystem_symptoms.dylib",
    "/usr/lib/system/libsystem_trace.dylib",
    "/usr/lib/system/libunwind.dylib",
    "/usr/lib/system/libxpc.dylib",
    "/System/Library/Frameworks/IOKit.framework/Versions/A/IOKit",
    "/System/Library/Frameworks/CoreServices.framework/Versions/A/CoreServices",
    "/usr/lib/libDiagnosticMessagesClient.dylib",
    "/usr/lib/libenergytrace.dylib",
    "/usr/lib/libbsm.0.dylib",
    "/usr/lib/libz.1.dylib",
    "/usr/lib/system/libkxld.dylib",
    "/System/Library/Frameworks/CFNetwork.framework/Versions/A/CFNetwork",
    "/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/FSEvents.framework/Versions/A/FSEvents",
    "/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/CarbonCore.framework/Versions/A/CarbonCore",
    "/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/Metadata.framework/Versions/A/Metadata",
    "/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/OSServices.framework/Versions/A/OSServices",
    "/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/SearchKit.framework/Versions/A/SearchKit",
    "/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/AE.framework/Versions/A/AE",
    "/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/LaunchServices",
    "/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/DictionaryServices.framework/Versions/A/DictionaryServices",
    "/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/SharedFileList.framework/Versions/A/SharedFileList",
    "/System/Library/Frameworks/Security.framework/Versions/A/Security",
    "/System/Library/Frameworks/SystemConfiguration.framework/Versions/A/SystemConfiguration",
    "/usr/lib/libapple_nghttp2.dylib",
    "/usr/lib/libcompression.dylib",
    "/usr/lib/libnetwork.dylib",
    "/usr/lib/libsqlite3.dylib",
    "/System/Library/Frameworks/Foundation.framework/Versions/C/Foundation",
    "/System/Library/Frameworks/Network.framework/Versions/A/Network",
    "/usr/lib/libCoreEntitlements.dylib",
    "/System/Library/PrivateFrameworks/MessageSecurity.framework/Versions/A/MessageSecurity",
    "/System/Library/PrivateFrameworks/ProtocolBuffer.framework/Versions/A/ProtocolBuffer",
    "/usr/lib/libMobileGestalt.dylib",
    "/System/Library/PrivateFrameworks/AppleFSCompression.framework/Versions/A/AppleFSCompression",
    "/usr/lib/libcoretls.dylib",
    "/usr/lib/libcoretls_cfhelpers.dylib",
    "/usr/lib/libpam.2.dylib",
    "/usr/lib/libxar.1.dylib",
    "/System/Library/PrivateFrameworks/CoreAutoLayout.framework/Versions/A/CoreAutoLayout",
    "/System/Library/Frameworks/DiskArbitration.framework/Versions/A/DiskArbitration",
    "/usr/lib/libarchive.2.dylib",
    "/usr/lib/libxml2.2.dylib",
    "/usr/lib/liblangid.dylib",
    "/System/Library/Frameworks/Combine.framework/Versions/A/Combine",
    "/usr/lib/swift/libswiftCore.dylib",
    "/usr/lib/swift/libswiftCoreFoundation.dylib",
    "/usr/lib/swift/libswiftDarwin.dylib",
    "/usr/lib/swift/libswiftDispatch.dylib",
    "/usr/lib/swift/libswiftIOKit.dylib",
    "/usr/lib/swift/libswiftObjectiveC.dylib",
    "/usr/lib/swift/libswiftXPC.dylib",
    "/usr/lib/swift/libswift_Concurrency.dylib",
    "/usr/lib/swift/libswift_StringProcessing.dylib",
    "/usr/lib/swift/libswiftos.dylib",
    "/System/Library/PrivateFrameworks/AppleSystemInfo.framework/Versions/A/AppleSystemInfo",
    "/System/Library/PrivateFrameworks/IOMobileFramebuffer.framework/Versions/A/IOMobileFramebuffer",
    "/System/Library/Frameworks/IOSurface.framework/Versions/A/IOSurface",
    "/usr/lib/libpcap.A.dylib",
    "/usr/lib/libdns_services.dylib",
    "/usr/lib/liblzma.5.dylib",
    "/usr/lib/libbz2.1.0.dylib",
    "/usr/lib/libiconv.2.dylib",
    "/usr/lib/libcharset.1.dylib",
    "/usr/lib/swift/libswift_RegexParser.dylib",
    "/usr/lib/libheimdal-asn1.dylib",
    "/usr/lib/libCheckFix.dylib",
    "/System/Library/PrivateFrameworks/TCC.framework/Versions/A/TCC",
    "/System/Library/PrivateFrameworks/CoreNLP.framework/Versions/A/CoreNLP",
    "/System/Library/PrivateFrameworks/MetadataUtilities.framework/Versions/A/MetadataUtilities",
    "/System/Library/Frameworks/Accelerate.framework/Versions/A/Accelerate",
    "/usr/lib/libmecab.dylib",
    "/usr/lib/libCRFSuite.dylib",
    "/usr/lib/libgermantok.dylib",
    "/usr/lib/libThaiTokenizer.dylib",
    "/System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vImage.framework/Versions/A/vImage",
    "/System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/vecLib",
    "/System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libvMisc.dylib",
    "/System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libvDSP.dylib",
    "/System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib",
    "/System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libLAPACK.dylib",
    "/System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libLinearAlgebra.dylib",
    "/System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libSparseBLAS.dylib",
    "/System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libQuadrature.dylib",
    "/System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBNNS.dylib",
    "/System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libSparse.dylib",
    "/System/Library/PrivateFrameworks/MIL.framework/Versions/A/MIL",
    "/System/Library/Frameworks/OpenDirectory.framework/Versions/A/Frameworks/CFOpenDirectory.framework/Versions/A/CFOpenDirectory",
    "/System/Library/Frameworks/OpenDirectory.framework/Versions/A/OpenDirectory",
    "/System/Library/PrivateFrameworks/APFS.framework/Versions/A/APFS",
    "/System/Library/Frameworks/SecurityFoundation.framework/Versions/A/SecurityFoundation",
    "/usr/lib/libutil.dylib",
    "/System/Library/PrivateFrameworks/InstalledContentLibrary.framework/Versions/A/InstalledContentLibrary",
    "/System/Library/PrivateFrameworks/CoreServicesStore.framework/Versions/A/CoreServicesStore",
    "/usr/lib/libapp_launch_measurement.dylib",
    "/System/Library/PrivateFrameworks/AppleMobileFileIntegrity.framework/Versions/A/AppleMobileFileIntegrity",
    "/usr/lib/libmis.dylib",
    "/System/Library/PrivateFrameworks/MobileSystemServices.framework/Versions/A/MobileSystemServices",
    "/System/Library/PrivateFrameworks/ConfigProfileHelper.framework/Versions/A/ConfigProfileHelper",
    "/System/Library/PrivateFrameworks/CoreAnalytics.framework/Versions/A/CoreAnalytics",
    "/System/Library/PrivateFrameworks/AppleSauce.framework/Versions/A/AppleSauce",
    "/System/Library/PrivateFrameworks/LanguageModeling.framework/Versions/A/LanguageModeling",
    "/usr/lib/libxslt.1.dylib",
    "/usr/lib/libcmph.dylib",
    "/System/Library/PrivateFrameworks/CoreEmoji.framework/Versions/A/CoreEmoji",
    "/System/Library/PrivateFrameworks/LinguisticData.framework/Versions/A/LinguisticData",
    "/System/Library/PrivateFrameworks/Lexicon.framework/Versions/A/Lexicon",
    "/System/Library/PrivateFrameworks/BackgroundTaskManagement.framework/Versions/A/BackgroundTaskManagement",
    "/usr/lib/libTLE.dylib"
  ]
}

### next-swc installation

next-swc is installed correctly for aarch64-apple-darwin

### next-swc shared object dependencies

/Users/ojkwon/github/next.js-upstream/node_modules/@next/swc-darwin-arm64/next-swc.darwin-arm64.node:
	/Users/runner/work/next.js/next.js/target/aarch64-apple-darwin/release/deps/libnext_swc_napi.dylib (compatibility version 0.0.0, current version 0.0.0)
	/System/Library/Frameworks/CoreServices.framework/Versions/A/CoreServices (compatibility version 1.0.0, current version 1228.0.0)
	/System/Library/Frameworks/Security.framework/Versions/A/Security (compatibility version 1.0.0, current version 60420.60.24)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1319.0.0)
	/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 1953.255.0)
	/usr/lib/libiconv.2.dylib (compatibility version 7.0.0, current version 7.0.0)

/Users/ojkwon/github/next.js-upstream/node_modules/@next/swc-darwin-arm64/next-swc.darwin-arm64.node [arm64]:
    -platform:
        platform     minOS      sdk
           macOS     12.0      13.1   
    -segments:
        load-offset   segment section        sect-size  seg-size perm
        0x00000000    __TEXT                             94304KB r.x
        0x00001680             __text           66042588
        0x03EFD15C             __stubs            3336
        0x03EFDE64             __init_offsets      112
        0x03EFDED4             __gcc_except_tab 5771520
        0x0447F000             __const          8830192
        0x04CEACF0             __cstring           128
        0x04CEAD70             __unwind_info    2417156
        0x04F38F78             __eh_frame       13496364
        0x05C18000    __DATA_CONST                        3040KB rw.
        0x05C18000             __got              2288
        0x05C188F0             __const          3101360
        0x05F10000    __DATA                               512KB rw.
        0x05F10000             __data           422352
        0x05F771D0             __thread_vars      1656
        0x05F77848             __thread_data       104
        0x05F778B0             __thread_bss       2776
        0x05F78388             __common          62704
        0x05F87880             __bss             18424
    -dependents:
        attributes     load path
                       /System/Library/Frameworks/CoreServices.framework/Versions/A/CoreServices
                       /System/Library/Frameworks/Security.framework/Versions/A/Security
                       /usr/lib/libSystem.B.dylib
                       /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation
                       /usr/lib/libiconv.2.dylib
```


</details>
2023-08-03 17:03:41 +00:00
vercel-release-bot
be457445b8 v13.4.13-canary.13 2023-08-03 15:51:26 +00:00
Shu Ding
9f24840032
Fix resource being preloaded multiple times during development (#53525)
Closes #49607. Since `ReactDOM.preload`s might be called multiple times during the rendering process, we need to ensure the timestamp queries are stable across the request so Flight can properly deduplicate them.
2023-08-03 15:15:44 +00:00
Adrian Bettridge-Wiese
3c84b3ac99
Add useOptimistic to client-only errors (#53313)
### What?
This PR makes it so calling `experimental_useOptimistic` throws an error telling you it only works in a client component. Because the Next docs have an example of renaming it into `useOptimistic` in the import, I also added that as a forbidden import. There may be a better way to do this, if so, please let me know.

Fixes #53312 

### Why?
Currently, the error you get says `(0 , react__WEBPACK_IMPORTED_MODULE_1__.experimental_useOptimistic) is not a function or its return value is not iterable`. This is misleading.
<img width="1043" alt="Screenshot 2023-07-28 at 3 30 10 PM" src="https://github.com/vercel/next.js/assets/12662580/ee16fd84-633d-47a1-8db4-cfc050546614">

### How?
Adds `experimental_useOptimistic` to the lists of forbidden imports. Adds some specific tests around this, but I'm not sure they're necessary, looking at how the other tests are written.

Co-authored-by: Zack Tanner <1939140+ztanner@users.noreply.github.com>
2023-08-03 07:21:00 +00:00
Donny/강동윤
c017765ef2
Update swc_core to v0.79.36 (#53416)
### What?

Update `swc_core` to 383509fd9d

### Why?

To fix minifier regression.

### How?

 - Closes WEB-1326
 - Fixes #53151
 - Fixes #53286
 - Fixes #53273
2023-08-02 21:59:19 +00:00
Zack Tanner
59c767b258
Allow next/headers in middleware & draftMode in edge runtime (#53465)
## What
Using methods from `next/headers` in middleware would throw a `requestAsyncStorage` invariant. Additionally, using `draftMode()` in middleware/an edge runtime is not possible

## Why
We do not expose `requestAsyncStorage` to the middleware adapter. Also, the prerender manifest wasn't available to the `EdgeRouteModuleWrapper` & middleware adapter, so it wasn't possible to enable/disable it.

## How
This makes `requestAsyncStorage` available for middleware, and makes the preview mode data available from build to the edge runtime/middleware. 

Fixes #52557
2023-08-02 20:22:35 +00:00
vercel-release-bot
480e3a3939 v13.4.13-canary.12 2023-08-02 17:19:31 +00:00
JJ Kasper
1c2595b15d
Ensure router-server clean-up exits properly (#53495)
x-ref: [slack
thread](https://vercel.slack.com/archives/C059MNV0E1G/p1690980326674279)
2023-08-02 09:25:54 -07:00
Tobias Koppers
61baae126f
fix Next.rs API (#53456)
### What?

* fixes problems in Next.rs API introduced by #52846 
* adds test infrastructure for experimental turbo testing
* adds two test cases to verify the infrastructure
* add grouping of output logs in run-tests
* simplify template loading

### Why?

### How?
2023-08-02 14:31:52 +02:00
Shu Ding
b31b0ee0cc
Add list of aliased lucide-react icons to the transform rules (#53483)
`lucide-react` follows the naming rule of `LucideName`, `NameIcon` and `Name` being exported from `/icons/{{ kebabCase Name }}`, but it has some special aliases such as `Stars` exported from `/icons/sparkles`. For now we have to add these rules manually.

Fixes https://github.com/vercel/next.js/pull/53051#issuecomment-1656211058. In the future we'll still need an automatic way to do this.

The list was created from https://unpkg.com/lucide-react@0.263.1/dist/esm/lucide-react.mjs.
2023-08-02 11:38:40 +00:00
vercel-release-bot
b1bf7aeefa v13.4.13-canary.11 2023-08-02 11:15:46 +00:00
Tim Neutkens
e603bc9dd1
Disable router.prefetch in development (#53477)
## What?

Follow-up to #51830. That PR disables prefetching in `<Link>` but not in the router, so `router.prefetch` would still cause a prefetch and additional compile.
2023-08-02 10:37:59 +00:00
vercel-release-bot
e757cac3f4 v13.4.13-canary.10 2023-08-02 09:49:13 +00:00
Tim Neutkens
a88e3a8087
Enable additional webpack memory cache (#52540)
This option was previously disabled because of test failures with HMR,
re-enabling it as it helps with HMR speed (skips resolving on changes).
 
<!-- Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:

## For Contributors

### Improving Documentation

- Run `pnpm prettier-fix` to fix formatting issues before opening the
PR.
- Read the Docs Contribution Guide to ensure your contribution follows
the docs guidelines:
https://nextjs.org/docs/community/contribution-guide

### Adding or Updating Examples

- The "examples guidelines" are followed from our contributing doc
https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md
- Make sure the linting passes by running `pnpm build && pnpm lint`. See
https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md

### Fixing a bug

- Related issues linked using `fixes #number`
- Tests added. See:
https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md

### Adding a feature

- Implements an existing feature request or RFC. Make sure the feature
request has been accepted for implementation before opening a PR. (A
discussion must be opened, see
https://github.com/vercel/next.js/discussions/new?category=ideas)
- Related issues/discussions are linked using `fixes #number`
- e2e tests added
(https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Documentation added
- Telemetry added. In case of a feature if it's used or not.
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md


## For Maintainers

- Minimal description (aim for explaining to someone not on the team to
understand the PR)
- When linking to a Slack thread, you might want to share details of the
conclusion
- Link both the Linear (Fixes NEXT-xxx) and the GitHub issues
- Add review comments if necessary to explain to the reviewer the logic
behind a change

### What?

### Why?

### How?

Closes NEXT-
Fixes #

-->

---------

Co-authored-by: Shu Ding <g@shud.in>
2023-08-02 11:43:39 +02:00
Wyatt Johnson
12e77cae30
Remove Route Handlers (#53462)
This removes the route handler abstraction and old match validation code in favor of the existing `load-components` flow that exports the `routeModule` directly.
2023-08-01 21:33:41 +00:00
Andrew Gadzik
9bde7dcc0f
Add warning logs for incorrect page exports (#53449)
<!-- 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 #53448

---------

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2023-08-01 13:59:20 -07:00
Julius Marminge
079813c11c
chore(create-next-app): use tailwind.config.ts for typescript templates (#47795)
Minor change to use `tailwind.config.ts` for TypeScript projects.
2023-08-01 20:05:57 +00:00
vercel-release-bot
3a3030882c v13.4.13-canary.9 2023-08-01 16:30:58 +00:00
Shu Ding
d393f07eb7
Enable Webpack compression for dev (#53430)
As explained in the comments, for local development, we still want to compress the cache files individually to avoid I/O bottlenecks as we are seeing 1~10 seconds of FS I/O time from user reports.
2023-08-01 14:54:10 +00:00
Tim Neutkens
2aee3ef0d4
Ensure child processes can clean up (#53439)
## What?

Since the recent changes to the server the CPU profile for the router process was no longer written on `ctrl + c`. Turns out the reason is that we now call kill with `SIGKILL` which can't be observed in Node.js.

I've changed it to `SIGINT` instead so that the SIGINT handlers are called during cleanup. The CPU profile writing happens in SIGINT.
2023-08-01 13:16:15 +00:00
Vladlen Grachev
629c9db823
Fix broken request handler (#51939)
Hi!

In previous versions (13.4.2 and earlier) in the custom server I could
do the following:
```
const parsedUrl = parse(req.url, true);
const { pathname } = parsedUrl;

if (pathname === '/c') {
  await handle(req, res, parse('/b', true));
} else {
  await handle(req, res, parsedUrl);
}
```

Of course, you can replace `handle` with `app.render` in the attached
example, but in practice it is convenient to put the definition of
`parsedUrl` into middleware and substitute the necessary `parsedUrl` in
exceptional situations.

This was broken in #49805.

I'm not sure if this use of request handler is expected, but it has
always worked and people have used it (probably due to lack of
documentation about the difference between `app.render` and
`app.getRequestHandler()`). So the change looks breaking, and I don't
think it should appear in minor versions.

---------

Co-authored-by: Tim Neutkens <tim@timneutkens.nl>
2023-08-01 13:51:05 +02:00
Tobias Koppers
ff5338ce03
disable cache compression (#53427)
### What?

Disables webpacks cache compression

### Why?

CI already compresses the cache. No need for next.js to do that. In fact this actually causes worse experience in multiple ways:

* CI compresses the cache after the build has finished. So compressing inline slows down the build.
* gzip compression runs with BEST_SPEED optimization, which creates larger cache files. This leads to running into potential cache size limits easier.
* Two layers for compression are not efficient in size and speed.

Trade-off:

* The whole cache will be decompressed on every build, which is less efficient.

In a few tests the benefits are greater than the trade offs.
2023-08-01 08:51:03 +00:00
JJ Kasper
975fb1f466
Fix windows unit tests (#53412)
Fixes differences in tests to handle windows now that we've fixed them
not being run.

x-ref:
https://github.com/vercel/next.js/pull/53408/checks?check_run_id=15501915673
2023-07-31 18:06:18 -07:00
Josh Goldberg ✨
fc52e02787
chore: enable typescript-eslint's recommended and stylistic configs internally (#52948)
Spinning out from #37151 and my draft PR #52845, this enables the two
basic recommended rulesets from
[typescript-eslint](https://typescript-eslint.io) for the Next.js
monorepo source code:

*
[`plugin:@typescript-eslint/recommended`](https://typescript-eslint.io/linting/configs#recommended):
Our base recommended rules that detect common bugs or _(non-stylistic)_
TypeScript bad practices
*
[`plugin:@typescript-eslint/stylistic`](https://typescript-eslint.io/linting/configs#stylistic):
Our base starting stylistic recommended for keeping codebases visually
consistent and avoiding out-of-practice visual constructs

The process I used is pretty standard (see
https://github.com/typescript-eslint/typescript-eslint/issues/6760 for
other repos it was done on):

1. Enable those base recommended presets
2. Remove any rule settings that are now redundant
3. Reconfigure any rule whose default settings didn't seem to make sense
for this codebase
4. Add a `// Todo: ...` comment, and under it, add a disable for any
rule that immediately reported a lot of complaints

Note that this only enables the presets internally. It doesn't impact
what end-users of published packages such as Next.js or
`create-next-app` experience. That's a separate task in #52845.

I also didn't fix any existing warning from the `canary` branch. Would
you like me to do that? My preference would be a separate PR to get it
in more quickly.

Any code changes are commented inline.

---------

Co-authored-by: Steven <steven@ceriously.com>
2023-07-31 16:32:54 -07:00
Shu Ding
7182d4dd2a
Always add ?ts= query for scripts during development (#53411)
Safari caches scripts during the same browsing session no matter what cache headers are set. This makes it impossible to update our runtime bundles (e.g. Webpack's runtime) during development as the legacy bundle might be cached and still served. If an updated client bundle uses a feature (e.g. `__webpack_require__.n`) that causes a change of the runtime, it triggers an error.

The most straightforward solution would be adding a query to prevent caching.

Fixes #53281.
2023-07-31 22:32:28 +00:00
vercel-release-bot
caf5ee80be v13.4.13-canary.8 2023-07-31 20:06:20 +00:00
Tim Neutkens
a721a749d8
router: apply server actions in a similar way to router.refresh() (#53373)
## What?

I was investigating reports of server actions with `revalidatePath` /
`revalidateTag` not invalidating the client-side router cache. Managed
to reproduce the issue here:
https://github.com/timneutkens/server-actions-test (requires Vercel KV
to run).

While looking at the reducer I noticed a few things that seemed off:

- setTimeout to trigger another `dispatch` on the same reducer with the
fetched data. This means that it would not be part of the same React
Transition.
- redirects weren't applying the data that comes back from the server
(that allows for single hop navigation)
- prefetchCache was invalidated, but the router cache which is used for
back/forward navigation was not invalidated, causing back/forward to not
get the new data.
- all changes in the action-reducer mutate. The part that shouldn't
mutate was part of that setTimeout dispatch.

This PR aims to solve all of these by reworking the actions reducer to
be handled similarly to `router.refresh()`. Since `router.refresh()` was
already modeled to be similar to `revalidatePath('/')`.

The flow is now more like the other reducers:
- Fetch data
- Wait for the data to come back
- Apply the data to the cache and keep it in a mutable variable
- Return the new cache and otherwise values like the url

In particular the actions reducer handles a few extra specifics:
- Resolving the server action promise, so that the value is passed to
the application code waiting for the result.
- Applying redirects from `redirect()` calls.
- Invalidating the router cache

## Followup changes

- Currently when calling `revalidatePath('/dashboard')` the entire
router cache is invalidated instead of only `/dashboard` and further
down, this is not in scope for this PR but still has to be added.
- `notFound()`, I'm not sure how this is supposed to work exactly, it
doesn't really make sense to me to allow it in server actions.

Kudos @feedthejim for helping investigate for this PR 😌 

<!-- Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:

## For Contributors

### Improving Documentation

- Run `pnpm prettier-fix` to fix formatting issues before opening the
PR.
- Read the Docs Contribution Guide to ensure your contribution follows
the docs guidelines:
https://nextjs.org/docs/community/contribution-guide

### Adding or Updating Examples

- The "examples guidelines" are followed from our contributing doc
https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md
- Make sure the linting passes by running `pnpm build && pnpm lint`. See
https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md

### Fixing a bug

- Related issues linked using `fixes #number`
- Tests added. See:
https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md

### Adding a feature

- Implements an existing feature request or RFC. Make sure the feature
request has been accepted for implementation before opening a PR. (A
discussion must be opened, see
https://github.com/vercel/next.js/discussions/new?category=ideas)
- Related issues/discussions are linked using `fixes #number`
- e2e tests added
(https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Documentation added
- Telemetry added. In case of a feature if it's used or not.
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md


## For Maintainers

- Minimal description (aim for explaining to someone not on the team to
understand the PR)
- When linking to a Slack thread, you might want to share details of the
conclusion
- Link both the Linear (Fixes NEXT-xxx) and the GitHub issues
- Add review comments if necessary to explain to the reviewer the logic
behind a change

### What?

### Why?

### How?

Closes NEXT-
Fixes #

-->
2023-07-31 21:52:31 +02:00
Wyatt Johnson
03a09ba1e6
Shared Loaders for Webpack and Turbopack (#52846)
This updates the Turbopack build code to provide the same `routeModule` export for App Pages as the Webpack loader does. This also adapts the Turbopack and Webpack loaders to use a shared loader file that is templated.

Fixes NEXT-1469

The template supports the following styles:

# Injections

```ts
declare const tree: LoaderCode
```

Allows you to define the variable in scope in TS, this lets you reference it with correct types within the rest of the file.

```ts
// INJECT:tree
```

Is replaced by the variable that's injected. This lets you ensure the correct invocation/initilization order.

# Variables

Variables will be substituted in the TS code when found. It's only really useful for strings, as the definition looks for the following in the outputted JS code:

```ts
"VAR_REPLACE_ME"
```

So you can have something like:

```ts
const thing = new AmazingThing({ page: "VAR_PAGE" })
```

And it'll be replaced by:

```ts
const thing = new AmazingThing({ page: "/thing" })
```

Where `VAR_PAGE` is `JSON.stringify("/thing")`.
2023-07-31 19:20:04 +00:00
vercel-release-bot
82e3d5126a v13.4.13-canary.7 2023-07-31 17:31:05 +00:00
JJ Kasper
d8d45a9843
Remove fibers from peerDependencies (#53395)
We don't need this peerDependency as it's no longer recommended and only
added for specific cases. This avoids us having to run `node-gyp` just
for this peer dep.

> NOTE OF OBSOLESCENCE -- The author of this project recommends you
avoid its use if possible.

x-ref:
https://github.com/vercel/next.js/actions/runs/5716924037/job/15489725344?pr=53391
2023-07-31 10:12:42 -07:00
Jiachi Liu
de873d02b3
Prefer svg icon instead favicon if possible (#53343)
### What?

Change the `favicon.ico` metadata `sizes` property from always `"any"`
to using the actual size possible

### Why?

When chrome/firefox browsers search for icon it needs the proper
metadata to determine which one to use, giving `favicon.ico` sizes with
`"any"` will prevent it loading the `icon.svg` as default icon when
available.

Changing to set proper size of `favicon.ico` (as the `favicon.ico` sizes
could be 16x16, 32x32, etc.) fixes the issue.

It works (loading svg icon) for chrome and firefox:

Firefox
<img width="505" alt="image"
src="https://github.com/vercel/next.js/assets/4800338/6873e595-479d-4d9e-ae5c-39e5f938fcf5">

Chrome
<img width="460" alt="image"
src="https://github.com/vercel/next.js/assets/4800338/03bbe4c7-ef76-4f34-a611-337b0d4b97a3">

It loads favicon.ico for Safari:
Using the `test/e2e/app-dir/metadata` app it shows the favicon.ico for
Safari
<img width="1000" alt="image"
src="https://github.com/vercel/next.js/assets/4800338/92cc8714-ea5e-432d-8144-2a4a42ee4ce2">

Can't have it as an e2e test as I tested it always loads the
`favicon.ico` in headless mode which can't determine the behaviors

Fixes #52002

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2023-07-31 07:32:39 -07:00
Jimmy Lai
f2c5eb840f
actions: fix revalidate after redirect (#53368)
This PR reverts a change that removed the `content-length` header filtering from the req made by the actions when redirecting. This change made some tests flaky and presumably also broke server actions in subtle ways.

There's still one other bug when redirecting after revalidating that will happen in you revalidate a page that was already rendered before where we will still show stale content. @timneutkens is fixing that one.

NEXT-1483
2023-07-31 10:08:52 +00:00
Tobias Koppers
3abaa85977
update turbopack (#53291)
* https://github.com/vercel/turbo/pull/5626 <!-- Tobias Koppers - remove
require.cache clear from chunk loading -->
2023-07-28 22:57:36 -07:00
Zack Tanner
afa9f96515
add a "skip" cache type to verbose logging mode (#53275)
When verbose logging is enabled and a cache MISS is logged due to either `revalidate: 0`,`cache: no-store` or `cache-control: no-store`, this logs a slightly different message, ie:

```
- GET / 200 in 804ms
   ├─── GET <url> in 205ms (cache: SKIP, reason: cache: no-cache)
   ├────── GET <url> 200 in 0ms (cache: HIT)
   ├────── GET <url> 200 in 373ms (cache: SKIP, reason: revalidate: 0)
   └────── GET <url> 200 in 111ms (cache: SKIP, reason: cache-control: no-cache (hard refresh))
 ```
 
 Closes NEXT-1412
2023-07-28 20:01:31 +00:00
Sukka
127e30ed42
refactor(cna): make create-next-app even smaller (#53241)
The PR follows #53146 and #53115.

The PR does 3 things:

- Replaces a [very heavy dependency `cpy`](https://github.com/vercel/next.js/pull/53146#issuecomment-1649193789) with a more lightweight copy helper.
  - The `fs.cp(src, dest, {recursive: true})` API is not used, as it is still experimental:
  <img width="1630" alt="image" src="https://github.com/vercel/next.js/assets/40715044/c61a454a-3a96-4658-a389-fbb68c241f18">
- Update `cross-spawn` to the latest version `7.0.3`
  - The only breaking change introduced in `cross-spawn@7.x` is dropping Node.js 8 supports, which allows `cross-spawn` to drop a dependency. Since `create-next-app` requires Node.js 16.8.0, I assume bumping `cross-spawn` would be safe.
- Update `fast-glob` to the latest version `3.3.1` to remove more KiBs (pointed out by @imranbarbhuiya)
  - The breaking change introduced in `fast-glob@3.x` is dropping Node.js 8 supports and some options changes.

Together the PR removes another 202 KiB from the `create-next-app/dist/index.js`. The size of `create-next-app/dist/index.js` is now 616 KiB.

<img width="583" alt="image" src="https://github.com/vercel/next.js/assets/40715044/4deb5e36-a63b-4501-b67c-29ea06e30578">
2023-07-28 17:21:58 +00:00
Zack Tanner
604681912b
ensure colocated unit tests run in CI & fix various failing tests (#53270)
Colocated unit tests (such as ones in `packages/next` and `packages/font`) weren't running in CI since `run-tests` marks the glob cwd as `<root>/tests`. This modifies the working directory to be the root so the new expanded test pattern will pick up files outside of `test/`.

Several of these tests were failing so there are updates in here to fix them. Specifically:

- Source Sans Pro font was renamed to Source Sans 3
- `fillCacheWithDataProperty` test was hitting the `bailOptimistic` code path
- `resolve-metadata` had an invalid assertion (`rel: icon` gets added as part of `IconsMetadata`)
- `resolve-opengraph` wasn't handling undefined images
- `server-patch-reducer` now use inline snapshots as one was failing since it now has a prefetchCache
2023-07-28 13:54:15 +00:00
vercel-release-bot
e575179b3e v13.4.13-canary.6 2023-07-28 12:32:12 +00:00
Tobias Koppers
09a5521c89
Turbopack: clear require.cache after writing files (Next.rs API) (#53285)
### What?

make sure to clear require.cache when writing files again

### Why?

changes should be reflected on reloads
2023-07-28 12:48:55 +02:00
Balázs Orbán
aaa94cd6e0
fix(font): expose loading error for debugging (#53284)
### What?

Exposing the original error message.

### Why?

While looking at #53279, I noticed that we don't show the original error message, which makes it hard to guess why the error was thrown in the first place.

### How?

Related #53279
2023-07-28 08:19:50 +00:00
vercel-release-bot
0814c82d0b v13.4.13-canary.5 2023-07-28 00:50:18 +00:00
JJ Kasper
aed332b2f6
Implement Next.rs API (#52983)
This implements the handling for the new `--experimental-turbo` flag
that keeps the Next.js routing handling in front of turbopack and
leverages the new Next.rs API.

---------

Co-authored-by: Tobias Koppers <tobias.koppers@googlemail.com>
Co-authored-by: Alex Kirszenberg <alex.kirszenberg@vercel.com>
2023-07-27 16:15:31 -07:00
Tobias Koppers
7c67b1216c
fix route groups in app_structure (#53247)
### What?

the key shouldn't include route groups
2023-07-27 22:22:18 +00:00
Alex Kirszenberg
f8107f0abb
Turbopack: Update Turbopack (#53266)
* https://github.com/vercel/turbo/pull/5621 <!-- Tobias Koppers - fix
esm export in build runtime -->
* https://github.com/vercel/turbo/pull/5620 <!-- Tobias Koppers - Revert
"export namespace object instead commonjs interop object" -->
2023-07-27 12:00:13 -07:00
Zack Tanner
0d2c5520ed
refactor smooth scroll bailout logic in app navigations (#53186)
This refactors the changes from my previous PR to allow smooth scrolling for the appDir case -- `componentDidUpdate` isn't a reliable way to check if only the hash has changed. This adds a property to `focusAndScrollRef` and compares canonicalUrls (sans hash fragment)

- Original https://github.com/vercel/next.js/pull/52915

Co-authored-by: Tim Neutkens <6324199+timneutkens@users.noreply.github.com>
2023-07-27 14:39:51 +00:00
Shu Ding
d15fd76ef7
Avoid bundling react-dev-overlay for dev (#53259)
Mark `react-dev-overlay` as an external for the client layer. This
reduces the server bundle by 1 MB (2.5 MB → 1.5 MB) during dev with
fewer resolve calls. Note that it applies to all pages, so this will
have a non-trivial memory improvement potentially.
2023-07-27 16:13:41 +02:00
Shu Ding
555ff3bcdb
Improved modularizeImports rules (#53051)
This PR adds some improved `modularizeImports` rules to ensure that some
of the popular UI libraries (mostly icons) can be correctly optimized
instead of creating thousands of modules. Here's an example of applying
this to `lucide-react`:

![CleanShot 2023-07-22 at 19 34
15@2x](https://github.com/vercel/next.js/assets/3676859/cf9ef13f-1d5d-4df6-9097-364983ea7b8b)

With https://github.com/swc-project/plugins/pull/196 being landed, we
can add different transform rules for specific names in the import. For
example, for `lucide-react` there're now 3 transforms:
- `'Lucide(.*)': ...`
- `'(.*)Icon': ...`
- `'*': ...`

On top of that, another critical change made in this PR is the
introducing of `modularize-import-loader`. With this new loader, we can
delegate the task of re-exporting the value to Webpack, where we can
adjust the type of the export and the target path. This is very
necessary and can't be done in SWC alone because libs like
`lucide-react` is using `.mjs` and don't have `exports` values for the
individual icons in the package.json files.

Because of that, if we simply transform the expression to `import Icon
from 'lucide-react/esm/icons/foo` it will fail because:
1. It's missing a `.mjs` extension
2. It doesn't have `/esm/icons/foo.mjs` in package.json `exports`

For 1), in fact that they moved to `.mjs` only in a recent upgrade so we
can't even hard code it to be `.mjs` in the transform (breaks old
versions).

Because of all the above, I decided to go with Webpack's own resolution
logic with the loader as a _temporary_ solution. It's temporary because
it's still assuming that the file structure of these libs doesn't
change.
2023-07-27 16:08:25 +02:00
Jiachi Liu
c5308eb4a8
Respect fetching logging config and Polish logs format (#52973)
Respect to the logging option which was introduced in #49250 that only logs when `experimental.logging` set to `"verbose"`

Polish the logging format a bit that make it more compact and lit
![image](https://github.com/vercel/next.js/assets/4800338/7b41424b-1215-415b-84c9-4619512ba0b4)


Related NEXT-1357
2023-07-27 09:02:42 +00:00
Tobias Koppers
911ba88888
some bugfixes to resolving and context creation (#53219)
### What?

pulled out of #52983
2023-07-27 07:46:50 +00:00
vercel-release-bot
127c5bbf80 v13.4.13-canary.4 2023-07-27 00:17:07 +00:00
Zack Tanner
c73fdfd87c
Fix file tracing issues for not-found pages (#53231)
This fixes the `.nft.json` output for not-found pages to correctly grab the client reference manifest. We were checking for `entryPoint.name.startsWith('app/')` but then asserting on `entryPoint.name === '/_not-found'` when determining the manifest path.

This also fixes the build output to mark pages with `λ` if the corresponding page has dynamic data. This revealed a separate issue that de-opts all pages into dynamic rendering if the root `NotFound` page bails, tracked in [NEXT-1474](https://linear.app/vercel/issue/NEXT-1474/if-the-root-notfound-page-opts-into-dynamic-rendering-all-pages-do-too)

[slack x-ref](https://vercel.slack.com/archives/C03S8ED1DKM/p1683763412272429)
2023-07-27 00:08:53 +00:00
Zack Tanner
22ca85946e
Wrap incremental cache in an IPC server (#53030)
This uses an IPC server (if available) for incremental cache methods to help prevent race conditions when reading/writing from cache and also to dedupe requests in cases where multiple cache reads are in flight. This cuts down on data fetching across the different build-time workers.

Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
2023-07-26 23:19:46 +00:00
OJ Kwon
0d4ec1047d
fix(next-swc): exclude raw target triples without native bindings (#53230)
<!-- 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



### Why?

### How?

Closes NEXT-
Fixes #

-->

### What?
context: https://vercel.slack.com/archives/C04KC8A53T7/p1690403434786639

We've been using raw target triples from napi-rs directly. It includes
all of the platforms napi-rs lists, however next-swc have narrower
support for native bindings. PR omits target triples that doesn't have
corresponding next-swc binary, then try to pick up triples from there.
Also leaves small logs if triples are missing from the list for further
debugging.

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2023-07-26 15:32:08 -07:00
Grace Yun
6c3560dbbd
[create-next-app] fix template css for top / bottom alignment (#53227)
Fixes a small CSS regression with the `create-next-app` template(s). Especially evident with templates using Tailwind CSS.

Before:
<img width="1047" alt="image" src="https://github.com/vercel/next.js/assets/74513600/9d3e8ef4-52b9-4590-be26-ee91f4bd65dd">

After:
![image](https://github.com/vercel/next.js/assets/74513600/952ca166-59df-40d1-bb6d-cb2fbc592c3b)
2023-07-26 20:41:08 +00:00
OJ Kwon
f814fb8046
feat(next-swc): log swc download url if fails (#53176)
<!-- 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



### Why?

### How?

Closes NEXT-
Fixes #

-->

### What?

Minor addition to download swc package to log url if fails.

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2023-07-26 13:13:37 -07:00
Justin Ridgewell
31d2b720d9
Reimplement stream cancellation (#52281)
### What?

This reimplements our stream cancellation code for a few more cases:
1. Adds support in all stream-returning APIs
2. Fixes cancellation detection in node 16
3. Implements out-of-band detection, so can cancel in the middle of a
read

It also (finally) adds tests for all the cases I'm aware of.

### Why?

To allow disconnecting from an AI service when a client disconnects. $$$

### How?

1. Reuses a single pipe function in all paths to push data from the
dev's `ReadableStream` into our `ServerResponse`
2. Uses `ServerResponse` to detect disconnect, instead of the
`IncomingMessage` (request)
    - The `close` event fire once all incoming body data is read
- The request `abort` event will not fire after the incoming body data
has been fully read
3. Using `on('close')` on the writable destination allows us to detect
close
- Checking for `res.destroyed` in the body of the loop meant we had to
wait for the `await stream.read()` to complete before we could possibly
cancel the stream

- - -

#52157 (and #51594) had an issue with Node 16, because I was using
`res.closed` to detect when the server response was closed by the client
disconnecting. But, `closed` wasn't
[added](https://github.com/nodejs/node/pull/45672) until
[v18.13.0](https://nodejs.org/en/blog/release/v18.13.0#:~:text=%5Bcbd710bbf4%5D%20%2D%20http%3A%20make%20OutgoingMessage%20more%20streamlike%20(Robert%20Nagy)%20%2345672).
This fixes it by using `res.destroyed`.

Reverts #52277
Relands #52157
Fixes #52809

---------
2023-07-26 12:57:34 -07:00
Tobias Koppers
39fd9177ef
Split into dev server and next.rs api mode (#53220)
### What?

* split into two dev modes
* split app-index into webpack and turbopack
* add two different entrypoints

### Why?

### How?
2023-07-26 19:21:49 +00:00
Tobias Koppers
a1adaf89ef
update turbopack (#53221)
* https://github.com/vercel/turbo/pull/5619 <!-- Tobias Koppers - export
namespace object instead commonjs interop object -->
2023-07-26 11:56:08 -07:00
Zack Tanner
b0c1697f1e
Fix hydration errors caused by root ErrorOverlay (#53216)
A bug was introduced in #52843 that causes hydration issues -- this
fixes that by moving the previous logic into the existing `isError` path
that doesn't trigger a call to `hydrateRoot` ensuring we are only doing
this on the client tree

Fixes #53110 and Fixes #53006
Closes NEXT-1470
2023-07-26 20:17:59 +02:00
Sukka
66ffc3cd39
refactor(cna): replace chalk with picocolors, glob with fast-glob@2.2.7 (#53146)
Follows #53115

- Replace `chalk` with `picocolors`
  - Note that `chalk.hex('#007acc')` has been replaced with `picocolors.blue`
- Replace `glob` with `fast-glob@2.2.7`
  - Not only does `fast-glob` is a faster drop-in replacement of `glob` with first-party `Promise`-based API support, but also `fast-glob` is already a dependency of `cpy`:
 
  <img width="812" alt="image" src="https://github.com/vercel/next.js/assets/40715044/8efa24c4-5312-4b1c-bf8d-68255ca30b60">


Together the PR removes about `50 KiB` from the `create-next-app/dist/index.js`:

<img width="570" alt="image" src="https://github.com/vercel/next.js/assets/40715044/db2f3723-14cc-48ce-9cb2-8aa1fb1d5e95">


Co-authored-by: Steven <229881+styfle@users.noreply.github.com>
2023-07-26 18:16:13 +00:00
OJ Kwon
974accc2c7
feat(turbopack): embed build time info, emits next features telemetry event (#53028)
### What?

closes WEB-1301. To collect some information inside of rust binary, embed it as build-time constant. It supersedes existing target triple embedding as well.
2023-07-26 17:49:34 +00:00
vercel-release-bot
f389d815fd v13.4.13-canary.3 2023-07-26 04:13:11 +00:00
JJ Kasper
cbbfebf5da
Handle basePath app-dir minimal case (#53189)
This ensures even when the invoke headers aren't present we properly
handle `basePath`.

Tested against
https://tmp-contents-idtza0iup-vtest314-ijjk-testing.vercel.app/hello/world

Fixes:
https://github.com/vercel/vercel/actions/runs/5660473696/job/15342856245?pr=10249#step:9:563
2023-07-25 21:05:47 -07:00
Artur Bień
7160af3dba
fix(next/image): washed out blur placeholder (#52583)
Fixes #52548

This PR fixes the issue of the `<Image />` "blur" placeholder where the
placeholder image appears "washed out" and feathered around the edges.

The fix does NOT involve any API changes - only the underlying SVG
filter is updated.
The filter works for any image type (JPEG, GIF, WEBP) no matter if it
contains transparency or not.

## How it works

```html
  <filter id='b' color-interpolation-filters='sRGB'>
    <feMorphology in='SourceAlpha' operator='dilate' radius='15' result='dilate' />
    <feGaussianBlur in='dilate' stdDeviation='15' result='mask' />
    <feGaussianBlur in='SourceGraphic' stdDeviation='20' result='blur' />
    <feComponentTransfer in='blur' result='solid'>
      <feFuncA type='table' tableValues='1 1' />
    </feComponentTransfer>
    <feComposite in2='mask' in='solid' operator='in' result="comp" />
    <feMerge>
      <feMergeNode in="SourceGraphic" />
      <feMergeNode in="comp" />
    </feMerge>
  </filter>
  ```
Currently the underlying filter uses `feComponentTransfer ` to get rid of the feathered edges but only for JPEG images. This is because if alpha channel was to be mapped to 1 for images with transparency in it, all of the transparent pixels would turn black (which is obviously undesirable).

The way I fixed it is by creating a mask from the SourceAlpha (effectively the "shape" of the object in an image), slightly blurring it for a smoother look (feMorphology + feGaussianBlur), and then clipping the `feComponentTransfer` result to the shape of the mask (`<feComposite in2='mask' in='solid' operator='in' result="comp" />`). 

Then finally `feMerge` is used to stack original image and the clipping result from the previous step just to make sure that any left over artifacts from clipping are hidden.

## Result

Here's a comparison between the current implementation (left column), and the filter above (right column)

<img width="614" alt="Screenshot 2023-07-12 at 10 44 56" src="https://github.com/vercel/next.js/assets/28541613/afdc1f88-eb1a-4a21-a88a-06057a875e1b">

---------

Co-authored-by: Steven <steven@ceriously.com>
2023-07-25 21:45:24 -04:00
Kyle Satti
d0cbf359dd
Updates @typescript-eslint/parser to 6.1.0 (#52848)
### What?
Updates the `@typescript-eslint/parser` dependency of `eslint-config-next` to the latest release `6.1.0`. 

### Why?
This is blocking NextJS developers from updating their own dependency on `@typescript-eslint/eslint-plugin`, which in turn requires `@typescript-eslint/parser@6.1.0`

### How?
Updated the package.json and ran `pnpm install`. I'm assuming that CI will catch any issues with the update (I know this could be deemed as a bit lazy, so apologies for that. It's all I have time to do at the moment).
2023-07-25 22:29:03 +00:00
vercel-release-bot
f89987f09d v13.4.13-canary.2 2023-07-25 19:56:56 +00:00
JJ Kasper
e60a1e747c
Fix minimal basePath handling (#53174)
We no longer handle basePath stripping further down in minimal mode so
this prevents the re-adding we used to do.

Manually tested with
https://33-base-path-gsp-404-m8w6hhs1m-vtest314-ijjk-testing.vercel.app/docs/api/hello

Fixes: [slack
thread](https://vercel.slack.com/archives/C03F2CMNGKG/p1690309135573409)
2023-07-25 12:33:43 -07:00
vercel-release-bot
87acd0432a v13.4.13-canary.1 2023-07-25 14:48:22 +00:00
Steven
32278603fd
chore: extract common get-validated-args (#53165)
- Closes #53044 

Co-authored-by: ZYSzys <23313266+ZYSzys@users.noreply.github.com>
2023-07-25 14:25:52 +00:00
Balázs Orbán
e1133cf097
fix(edge): allow Request cloning via NextRequest (#53157)
### What?

Allow the following:

```ts
new NextRequest(new Request(...))
```

### Why?

Cloning a request by passing it to the constructor of another `Request` is allowed by the spec: https://developer.mozilla.org/en-US/docs/Web/API/Request/Request#parameters

### How?

If the passed argument is an instance of `Request`, we pass it as-is to `super()`

Fixes #52967
Closes NEXT-1468
2023-07-25 11:36:39 +00:00
vercel-release-bot
d680975537 v13.4.13-canary.0 2023-07-24 23:10:37 +00:00
Steven
a0856eb596
chore: update warning message from yarn add sharp to npm i sharp (#53130)
Previously, this warning message assumed the user knew what `yarn` was and had it installed.

This PR changes the warning message to assume the user knows what `npm` is and has it installed, since `npm` ships with the official `node` installation.
2023-07-24 22:33:12 +00:00
Jiachi Liu
d8f4fa8946
Fix not found hangs the build with overridden node env (#53106)
### Why

In #52985 the not found solution introduces `NODE_ENV` to determine if it his the not found boundary and should render the not found, as in the next build mode, we have `/_not-found` as a special route which has a empty parallel route, but in next dev mode so far it his the `parallel-default-route`. This could dependend on the `NODE_ENV` passing to next server but not necessarily.

### What

Fixes #53082
Fixes #53083 

### How

When server actions `not-found` hits, now we create a new loader tree based on the previous one, including `layout` and other components but not the children parallel routes

For production case, to make the rendering independent from the `NODE_ENV`, we're using original pathname to check if it's `/_not-found` to determine if it's production build 404 page

To support replace the loader tree of action, did a little refactor that passing down the loader tree from top level to `bodyResult`. Then we can change the loader tree itself before rendering, in short, we tweak it from original tree to one for not-found case, so server actions could render it properly
2023-07-24 21:00:53 +00:00
OJ Kwon
9da305fe32
feat(turbopack): emit MODULE_FEATURE telemetry from turbopack (#52356)
### What?

closes WEB-1274. In effort to create feature parity to existing webpack/telemetry-plugin, this PR attempts to define a new struct `ModuleFeatureTelemetry` and emit it via resolve plugin, if module & its subpath matches to the existing plugin.

next-dev (--experimental-turbo) now will emit telemetry payload with other output, however this PR does not actually `record` telemetry via `telemetry.record` since original webpack telemetry records it in prod build only.
2023-07-24 20:07:32 +00:00
Tobias Koppers
4558fac29b
move webpack specific logic into a separate file (#53114)
### What?

move webpack specific code out of the `client/index.ts` file

### Why?

sharing with turbopack. Avoiding extra shims to fake webpack.
2023-07-24 19:07:58 +00:00
Sukka
d8c4700a37
refactor(codemod): replace chalk with picocolors (#53115)
The PR replaces `chalk` inside `@next/codemod` with `picocolors`.

Generally, `@next/codemod` is used through `npx`/`pnpx` as it serves as a sort of "one-time fix". By replacing `chalk` with the `picocolors` (which is 14 times smaller and 2 times faster), we can speed up the installation process of `npx @next/codemod`.

Currently, `@next/codemod` has about 10k downloads per week, so I guess this PR is worth it:

<img width="441" alt="image" src="https://github.com/vercel/next.js/assets/40715044/a32fd6e0-bbe6-48e8-985d-83393c141b23">

In my next PR, I will replace `chalk` inside `create-next-app` with `picocolors` as well.
2023-07-24 17:56:45 +00:00
Tobias Koppers
909dad557d
Turbopack: use edge environment in server-side rendering of client components too (#53099)
### What?

* use the correct edge resolve options for SSR of client components

### Why?

It need to use the edge import conditions here for
https://github.com/vercel/next.js/pull/51083
2023-07-24 19:24:30 +02:00
Alex Kirszenberg
2cd0c8abc7
Add app, error, and document entrypoints (#53013)
### What

adds endpoints for `_app` `_error` and `_document` for pages

Co-authored-by: Tobias Koppers <1365881+sokra@users.noreply.github.com>
2023-07-24 08:57:48 +00:00
Tobias Koppers
c8eb7f3de0
update Turbopack (#53098)
* https://github.com/vercel/turbo/pull/5574
2023-07-24 07:18:27 +00:00
akfm
1494283a74
fix: Add Next-Url to http vary in consideration of intercept routes. (#52746)
### Why

We calculate the “next url” depending on the router state and the previous router state so that when you navigate to a route, the proxy matches with that header and returns you the intercepted route if matching

### What 
- Fixes #52745




Co-authored-by: Jiachi Liu <4800338+huozhi@users.noreply.github.com>
2023-07-22 21:38:23 +00:00
Shu Ding
7843204938
Improve internal web stream utils (#53004)
This PR refactors some code specifically related to web stream utilities. Please read the review comments for more details.
2023-07-22 14:49:58 +00:00
JJ Kasper
1398de9977
Revert "Revert "Separate routing code from render servers (#52492)"" (#53029)
Reverts vercel/next.js#53016
2023-07-21 14:02:52 -07:00
vercel-release-bot
552bca46eb v13.4.12 2023-07-21 20:30:24 +00:00
vercel-release-bot
576cb6ed4f v13.4.12-canary.0 2023-07-21 19:40:40 +00:00
JJ Kasper
ac62406ca0
Revert "Separate routing code from render servers (#52492)" (#53016)
Temporarily reverts these changes to allow patch release first. 

Reverts: https://github.com/vercel/next.js/pull/52149
Reverts: https://github.com/vercel/next.js/pull/52492
2023-07-21 10:52:19 -07:00
Jiachi Liu
1fefb4a8d2
Reland "Refine the not-found rendering process for app router" (#52985)
Reland #52790
Reverts vercel/next.js#52977

was failed due to failed job
[vercel/next.js/actions/runs/5616458194/job/15220295829](https://github.com/vercel/next.js/actions/runs/5616458194/job/15220295829)

Should be fine to resolve with
https://github.com/vercel/next.js/pull/52979 now

Fixes #52718
Fixes #52739

---------

Co-authored-by: Alex Kirszenberg <alex.kirszenberg@vercel.com>
Co-authored-by: Tobias Koppers <tobias.koppers@googlemail.com>
2023-07-21 10:09:30 -07:00
Alex Kirszenberg
319353e86f
Increase timeout for 404 tests (#52998) 2023-07-21 13:59:41 +02:00
Tobias Koppers
1717d1e986
Turbopack: Refactoring module references (#52930)
### What?

see https://github.com/vercel/turbo/pull/5572

### Why?

### How?
2023-07-21 10:37:57 +00:00
Donny/강동윤
84820c900f
Update swc_core to v0.79.22 (#52945)
### What?

Update swc_core to `v0.79.22` and other SWC crates to the latest.
### Why?

This is for further next.js work: https://vercel.slack.com/archives/C02HY34AKME/p1689768597095499


### How?

Closes WEB-1299

turbopack counterpart: https://github.com/vercel/turbo/pull/5575

Co-authored-by: Tobias Koppers <1365881+sokra@users.noreply.github.com>
2023-07-21 10:01:08 +00:00
Tobias Koppers
e88777267a
update Turbopack (#52986)
* https://github.com/vercel/turbo/pull/5567 <!-- Alex Kirszenberg -
Remove unnecessary ValueDebugFormat item, hide Vc field -->
* https://github.com/vercel/turbo/pull/5576 <!-- Alex Kirszenberg -
Extract shared HMR utils to their own modules/crates -->
* https://github.com/vercel/turbo/pull/5503 <!-- OJ Kwon -
feat(turbopack_core): define trait for diagnostics -->
* https://github.com/vercel/turbo/pull/5487 <!-- Will Binns-Smith -
turbopack-cli: modularize code to support turbopack build -->
* https://github.com/vercel/turbo/pull/5488 <!-- Will Binns-Smith -
turbopack-cli: implement `turbopack build` -->
* https://github.com/vercel/turbo/pull/5450 <!-- Leah - feat: async
modules / top level await -->

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2023-07-21 10:34:35 +02:00
Wyatt Johnson
205d3845d1
Move Pages API rendering into bundle (#52149)
Moves the rendering for Pages API routes into the bundle. This also implements the `routeModule` interface for both Pages and Pages API routes in the Turbopack output. This also fixes a bug where the order of the imports for `Document` and `App` were reversed in the Turbopack build.
2023-07-21 05:51:37 +00:00
JJ Kasper
f57eecde5e
Separate routing code from render servers (#52492)
This breaks out routing handling from `next-server`, `next-dev-server`,
and `base-server` so that these are only handling the "render" work and
eventually these will be deleted completely in favor of the bundling
work being done.

The `router` process and separate `render` processes are still
maintained here although will be investigated further in follow-up to
see if we can reduce the need for these.

We are also changing the `require-cache` IPC to a single call instead of
call per entry to reduce overhead and also de-dupes handling for
starting the server between the standalone server and normal server.

To maintain support for existing turbopack route resolving this
implements the new route resolving in place of the existing
`route-resolver` until the new nextturbo API is fully landed.

After these initial changes we should continue to eliminate non-render
related code from `next-server`, `base-server`, and `next-dev-server`.
2023-07-20 22:13:42 -07:00
vercel-release-bot
04ae5be8d0 v13.4.11 2023-07-21 04:28:14 +00:00
vercel-release-bot
5853258d19 v13.4.11-canary.2 2023-07-21 03:49:07 +00:00
JJ Kasper
d7335b75d1
Revert "Refine the not-found rendering process for app router" (#52977)
Reverts vercel/next.js#52790

Reverting temporarily as this breaks turbopack's not found handling due
to the app tree being generated there not having the necessary parallel
routes in the `_not-found` entry x-ref:
0df8aac935/packages/next-swc/crates/next-core/src/app_structure.rs (L677-L681)

x-ref:
https://github.com/vercel/next.js/actions/runs/5616458194/job/15220295829
2023-07-20 20:39:05 -07:00
vercel-release-bot
0df8aac935 v13.4.11-canary.1 2023-07-20 22:21:52 +00:00
JJ Kasper
e609e023ca
Fix build side-effects from third-parties package (#52969)
We shouldn't be generating src files during the build script as these
can break publishing.
2023-07-20 15:10:57 -07:00
Jimmy Lai
55eebefbab
app-router: prefetching tweaks (#52949)
This PR tries to address some feedback around prefetching, like in #49607, where they were some warnings because we were over prefetching.

The tweaks in this PR:
- if there are no loading boundary below, we don't prefetch the full page anymore. I made that change a while ago but I think it wasn't the original intent from @sebmarkbage. Fixing that now. So now, we will prefetch the page content until the nearest loading boundary, only if there is any.
- there's now a queue for limiting the number of concurrent prefetches. This is to not ruin the bandwidth for complex pages. Thanks @alvarlagerlof for that one.
- also, if the prefetch is in the queue when navigating, it will get bumped.
- bonus: fixes a bug where we were wrongly stripping headers in dev for static pages

Test plan:
<img width="976" alt="CleanShot 2023-07-20 at 17 53 43@2x" src="https://github.com/vercel/next.js/assets/11064311/2ea34419-c002-4aea-94df-57576e3ecb2e">
In the screenshot you can see that:
- only 5 requests at a time are authorised
- when I clicked on 15, it got prioritised in the queue (did not cancel the rest)
- the prefetch only included the content until the loading boundary




Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
2023-07-20 21:46:38 +00:00
Jiachi Liu
cb24c555a6
Refine the not-found rendering process for app router (#52790)
### What

This PR changes the flow of not-found rendering process. 

### Why

`not-found.js` was rendered in two ways before:
* 1 is SSR rendering the not-found as 404
* 2 is triggering the error on RSC rendering then the error will be
preserved in inline flight data, on the client it will recover the error
and trigger the proper error boundary.

The solution has been through a jounery:
No top-level not found boundary -> introduce metadata API -> then we
create a top level root not found boundary -> then we delete it due to
duplicated rendering of root layout -> now this

So the solution before this PR is still having a root not found boundary
wrapped in the `AppRouter`, it's being used in a lot of places including
HMR. As we discovered it's doing duplicated rendering of root layout,
then we removed it and it started failing with rendering `not-found` but
missing root layout. In this PR we redesign the process.

### How

Now the rendering architecture looks like:

* For normal root not-found and certain level of not-found boundary
they're still covered by `LayoutRouter`
* For other error renderings including not-found
* Fully remove the top level not-found boundary, when it renders with
404 error it goes to render the fallback page
* During rendering the fallback page it will check if it should just
renders a 404 error page or render nothing and let the error from inline
flight data to trigger the error boundary

pseudo code
```
try {
  render AppRouter > PageComponent
} catch (err) {
  create ErrorComponent by determine err
  render AppRouter > ErrorComponent
}
```

In this way if the error is thrown from top-level like the page itself
or even from metadata, we can still catch them and render the proper
error page based on the error type.

The problematic is the HMR: introduces a new development mode meta tag
`<meta name="next-error">` to indicate it's 404 so that we don't do
refresh. This reverts the change brougt in #51637 as it will also has
the duplicated rendering problem for root layout if it's included in the
top level not found boundary.

Also fixes the root layout missing issue:

Fixes #52718
Fixes #52739

---------

Co-authored-by: Shu Ding <g@shud.in>
2023-07-20 14:12:06 -07:00
Shu Ding
a96a9b0791
Fix client reference manifest for interception routes (#52961)
We have the logic to group the client compiler's entry names to make sure we generate one single manifest file for the page. This is complicated and requires a special step to "group" the entry names because a page can depend on a bunch of files from everywhere.

And currently, the normalization of "entryName → groupName" doesn't cover interception routes' conventions (`(.)`, `(..)` and `(...)`). This PR fixes that.

Closes #52862, closes #52681, closes #52958.
2023-07-20 20:06:44 +00:00
Darshan Jain
8e3cd83dc8
Allow general language codes in the Metadata API (#52920)
Closes #52898

LangCode Missing zh-Hans and zh-Hant

| 'yo-NG'
  | 'zh-CN'
  | 'zh-Hans'   //added
  | 'zh-Hant'        //added
  | 'zh-HK'
  | 'zh-MO'
  | 'zh-SG'
  | 'zh-TW'
  | 'zu-ZA'


f5272acbe5/packages/next/src/lib/metadata/types/alternative-urls-types.ts (L419)


Co-authored-by: Shu Ding <3676859+shuding@users.noreply.github.com>
2023-07-20 11:05:33 +00:00
Tobias Koppers
840059415b
add edge support for next.rs API (#52885)
### What?

adds edge pages, apis, app pages and app routes to next.rs api

### Why?

### How?
2023-07-20 08:57:58 +00:00
Zack Tanner
8664ffe26d
fix: allow smooth scrolling if only hash changes (pages & app) (#52915)
We were preventing smooth scrolling to avoid jarring UX when `scroll-behavior: smooth` was set and the user navigates to another route ([PR](https://github.com/vercel/next.js/pull/40642) and [related comment](https://github.com/vercel/next.js/issues/51721#issuecomment-1623416600)). 

This updates both pages & app router to restore smooth scroll functionality if the only the route hash changes.

Fixes #51721
Closes NEXT-1406
2023-07-20 06:13:04 +00:00
Zack Tanner
4994a428ae
improve error DX on pages with RSC build errors (#52843)
### What?
- Visiting a page in the app router without a proper component export doesn't show the dev overlay, but logs errors to the console
- When it does show the error overlay (e.g. during an HMR event), the error message was sharing the module code itself rather than the component path, making it hard to debug

### Why?
`createComponentTree` can throw these errors before the AppRouter tree is mounted, leaving the errors uncaught by the dev overlay.

### How?
This wraps the server root in the `ReactDevOverlay` when in dev mode with a minimal "HMR" for when the server component is edited (to reload the page).

Closes NEXT-308
2023-07-20 00:32:57 +00:00
Wyatt Johnson
3e821ef189
Support basePath with edge runtime for Custom App Routes (#52910)
Fixes a bug where the edge runtime didn't support `basePath` with Custom App Routes.

- Fixes #49661
2023-07-19 23:54:34 +00:00
Darshan Jain
7771e78207
Fixed:#52853 Lacking 'color' attribute in IconDescriptor Metadata (#52902)
Fixes #52853

Lacking 'color' attribute in IconDescriptor  Metadata

```diff
export type IconDescriptor = {
  url: string | URL
  type?: string
  sizes?: string
+ color?: string          // added the color attribute 
  /** defaults to rel="icon" unless superseded by Icons map */
  rel?: string
  media?: string
  /**
   * @see https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/fetchPriority
   */
  fetchPriority?: 'high' | 'low' | 'auto'
}
```


https://github.com/vercel/next.js/blob/v13.4.11-canary.0/packages/next/src/lib/metadata/types/metadata-types.ts#L99
2023-07-19 21:45:58 +00:00
Jiachi Liu
ec8af55833
Update vendor @vercel/og (#52897)
Upgrade `@vercel/og` to latest version

https://github.com/vercel/og/releases/tag/0.5.9
2023-07-19 21:04:27 +00:00
Tobias Koppers
446b172780
update turbopack (#52899)
* https://github.com/vercel/turbo/pull/5563
2023-07-19 18:17:57 +00:00
Tobias Koppers
86d7b85dc9
Turbopack: Next.rs API improvements (#52856)
### What?

* adds `Project.update` to update project options
* fix manifest paths to be under `server`
* pass `env` into project
* handle and expose issues in all methods
* expose server paths in WrittenEndpoint
2023-07-19 19:50:15 +02:00
Jimmy Lai
91c31c69b0 Revert "stuff"
This reverts commit 85bd7cc11f.
2023-07-19 14:00:54 +02:00
Jimmy Lai
85bd7cc11f stuff 2023-07-19 13:56:46 +02:00
Yagiz Nizipli
0f945637b9
perf: optimize flat-readdir to use fs.opendir (#52361)
This pull request replaces `readdir` with `opendir` and simplifies the
implementation.

Co-authored-by: Steven <steven@ceriously.com>
Co-authored-by: Tim Neutkens <tim@timneutkens.nl>
2023-07-18 22:16:26 +02:00
Tobias Koppers
0aeda3aedc
Turbopack: ensure output assets reference only output assets (#52832)
### What?

refactoring see https://github.com/vercel/turbo/pull/5557

### Turbopack Changes

* https://github.com/vercel/turbo/pull/5506 <!-- Leah -
feat(turbopack-ecmascript): implement acyclic SCC graph for ESM imports
-->
* https://github.com/vercel/turbo/pull/5557 <!-- Tobias Koppers - Ensure
output assets reference only output assets -->
2023-07-18 21:54:38 +02:00
Wyatt Johnson
87763d73e0
Rename Webpack Layers (#52605)
Renames the webpack layers to be more semantical:

```
server compiler:
server layer → RSC layer
client layer → SSR layer
shared layer → shared layer

client compiler:
appClient layer → app browser layer
```
2023-07-18 18:48:27 +00:00
Janicklas Ralph
009b6a19d6
Setting up third-parties package (#51194)
This PR Introduces `next/third-parties`

- `@next/third-parties` is a new package in the Next.js monorepo. 
- The package contains collection of components that can be used to
efficiently load third party libraries into your Next.js application.
- This package uses [Third Party
Capital](https://github.com/GoogleChromeLabs/third-party-capital/) under
the hood to fetch the best loading recommendations.
- This PR mainly sets up the package to run a script at build time to
auto generate the components from [Third Party
Capital](https://github.com/GoogleChromeLabs/third-party-capital/)
config.

Packages are grouped by company, for eg:

`import { GoogleMapsEmbed } from '@next/third-parties/google'`


cc: @housseindjirdeh @kara 
<!-- 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?

### Why?

### How?

Closes NEXT-
Fixes #

-->

---------
2023-07-18 10:52:39 -07:00
OJ Kwon
2cea3f7000
feat(next-swc): support env var for --experimental-turbo (#52841)
### What?

Minor update to next-swc to support `__INTERNAL_CUSTOM_TURBOPACK_BINDINGS` for the --experimental-turbo entrypoint as same as current --turbo.
2023-07-18 17:45:02 +00:00