Commit graph

432 commits

Author SHA1 Message Date
hrmny
6c1d700afc
feat(turbopack-ecmascript): cache external modules with wrapper (#63337)
### What?
This is a fix for a bundle potentially referring to two different
external modules (e.g. `react` because it gets invalided from the
require cache)

See https://github.com/vercel/turbo/pull/7988

### Turbopack Updates
* https://github.com/vercel/turbo/pull/8376 <!-- Tim Neutkens - Rename
ChunkLoading::None to ChunkLoading::Edge -->
* https://github.com/vercel/turbo/pull/8371 <!-- Donny/강동윤 - test: Add
an execution test for `paren_remover` -->
* https://github.com/vercel/turbo/pull/8370 <!-- Tobias Koppers - Tree
Shaking shared state and side effects -->
* https://github.com/vercel/turbo/pull/7988 <!-- hrmny -
feat(turbopack-ecmascript): cache external modules with wrapper -->

Closes PACK-2622
2024-06-10 15:39:40 +00:00
Jiachi Liu
f893c18528
Append sitemap extension and optimize imafe metadata static generation (#66477)
### What

Optimizing the static generation for dynamic metadata routes

If you're not using `generateSitemaps()` or `generateSitemaps()`, you
don't need to change any file conventions.
If you're using multi sitemap routes, make sure the returned `id`
properties from `generateSitemaps()` don't need to contain `.xml`, since
we'll always append one for you.

Analyzing the exports of metadata routes and determine if we need to
make them as dynamic routes.

### Why

Previously, users are struggling with the multi routes of sitemap or
images.
For sitemap, the `.xml` extension in url doesn't get appended
consistently to the multi sitemap route between dev and prod.
For image routes, the generated image routes are always dynamic routes
which cannot get static optimized.

The reason is that we need to always generate a catch-all route (such as
`/icon/[[...id]]` to handle both single route case (e.g. without
`generateImageMetadata`, representing url `/icon`) or multi route (e.g.
with `generateImageMetadata`, representing url `/icon/[id]`), only
catch-all routes can do it. This approach fail the static optimization
and make mapping url pretty difficult as parsing the file to check the
module exports has to be done before it.

#### Benifits

For image routes urls, this approach could help on static generation
such as single `/opengraph-image` route can be treated as static, and
then it can get static optimized if possible.

**Before**: `/opengraph-image/[[...id]]` cannot be optimized
**After**: single route `/opengraph-image` and multi-route
`/opengraph-image/[id]` are both possible to be statically optimized

For sitemap, since we removed appending `.xml` for dynamic routes, it’s
hard for users to have `/sitemap.xml` url with dynamic route convention
`sitemap.js` . But users desire smooth migration and flexibility.

**Before**: In v15 rc we removed the `.xml` appending that `sitemap.js`
will generate url `/sitemap` makes users hard to migrate, as users need
to re-submit the new sitemap url.
**After**: Now we'll consistently generate the `.xml`. Single route will
become `/sitemap.xml`, and multi route will become `/sitemap/[id].xml`.
It's still better than v15 as the urls generation is consistent, no
difference between dev and prod.

Here's the url generation comparsion

#### Before

All the routes are dynamic which cannot be optimized, we only had a
hacky optimization for prodution build multi-routes sitemap routes

| | only default export | `export generateImageMetadata()` | `export
generateSitemaps()` |
| -- | -- | -- | -- |
| opengraph-image.js | /opengraph-image/[[...id]] |
/opengraph-image[[...id]]/ | /opengraph-image/[[...id]] |
| sitemap.js | /sitemap/[[...id]] | /sitemap/[[...id]] | dev:
`/sitemap/[[...id]]` prod: `/sitemap/[id]` |

#### After

Most of the single route will are to get statically optimized now, and
the multi-routes sitemap are able to get SSG now

| | only default export | `export generateImageMetadata()` | `export
generateSitemaps()` |
| -- | -- | -- | -- |
| opengraph-image.js | /opengraph-image | /opengraph-image/[id] | - |
| sitemap.js | /sitemap.xml | - | /sitemap/[id].xml |

Next.js will have less overhead of mapping urls, we can easily multiply
the urls generation simply based on file conventions.

x-ref: feedback from #65507 
Closes #66232
2024-06-10 17:34:06 +02:00
Jiachi Liu
6cad9233fd
test: migrate dev error tests into separate sandbox test (#66666)
### What

Keep `test/e2e/app-dir/metadata-dynamic-routes/index.test.ts` with
successful build cases, move the dev error tests into separate test

### Why

x-ref:
https://github.com/vercel/next.js/actions/runs/9429301722/job/25975574075?pr=66286

Before the moving the tests, the error is flaky with turbopack since the
error will fail the hmr. Error observed with turbopack when seeing build
failed cases. So I moved the tests into the separate dev tests, running
inside sandboxes. Then each error test doesn't effect each other.

```
 ⨯ ./app/metadata-base/unset/icon--metadata.js:1:1
  Module not found: Can't resolve './icon.tsx'
  > 1 | import { generateImageMetadata } from "./icon.tsx"
      | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    2 | import { fillMetadataSegment } from 'next/dist/lib/metadata/get-metadata-route'
    3 |
    4 | const imageModule = { generateImageMetadata }

```
2024-06-10 11:57:33 +02:00
Sebastian Silbermann
ff366ed08d
Remove redundant React dependency declarations in test (#66530) 2024-06-05 18:10:24 +02:00
Zack Tanner
ceef719459
fix missing stylesheets when parallel routes are present (#66300)
This takes the `layerAssets` property from the previous PR and actually
renders it, replacing the previous style handling. This ensures that
when multiple page segments are rendered on screen, all of their
associated CSS files are loaded. The existing `findHeadInCache` method
only ever returns a single head node, which means it’d miss stylesheets.


Fixes #59308
Fixes #63465
2024-06-03 16:35:31 -07:00
Hendrik Liebau
994d8ee2c3
Fix broken BrowserInterface type (#66461) 2024-06-03 12:56:49 +00:00
Sebastian Silbermann
e421fea1ee
Update React from 81c5ff2e04 to f994737d14 (#66093)
<details>
<summary>React upstream changes</summary>

- https://github.com/facebook/react/pull/29219
- https://github.com/facebook/react/pull/29007
- https://github.com/facebook/react/pull/29207

</details>
2024-05-22 19:34:06 -07:00
Sebastian Silbermann
a25e7d2fe9
Update React from 04b058868c to 81c5ff2e04 (#65869) 2024-05-22 14:46:57 +02:00
Janka Uryga
79bebe7bd3
experimental: unstable_after (#65038)
Implements `unstable_after`, which lets the user schedule work to be
executed after the response is finished.

### Implementation notes

- `unstable_after()` is a dynamic function (bypassable only with `export
dynamic = "force-static"`)
- Usable in: server components (including `generateMetadata`), actions,
route handlers, middleware
- It is meant to run its callbacks even if a response didn't complete
successfully (thrown error) or called `notFound()`/`redirect()`
- Currently gated behind a `experimental.after` feature flag, because it
touches many runtime bits (including a React monkeypatch...)
- The state for `unstable_after()` in a given request lives in
`requestAsyncStorage` (added via `RequestAsyncStorageWrapper`)

- the implementation is based around two functions that we inject via
`renderOpts`:
- `waitUntil(promise)` - keep a function invocation alive until a
promise settles. it is provided as a platform primitive in serverless
contexts, and a noop in `next start`
- for serverless (nodejs), Next.js will attempt to get `waitUntil` from
`globalThis[Symbol.for('@next/request-context')].get().waitUntil`. This
should be considered unstable for now. See
`packages/next/src/server/after/wait-until-builtin.ts` for details.
- `onClose(callback)` **[NEW]** - run something when a response is done.
basically `res.on('close', callback)`, but also implemented for Web APIs
- unfortunately, for Web, this requires some potentially expensive
tricks - see `packages/next/src/server/web/web-on-close.ts`
2024-05-20 08:49:53 +00:00
Tim Neutkens
e359b14881
Upgrade react@beta (#65845)
Ensures `useMemoCache` is available for the React Compiler.

Required for #65804 without having to manually enable experimental React
through e.g. taint: true.

<!-- 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: Jiachi Liu <inbox@huozhi.im>
2024-05-16 21:59:47 +02:00
Jiachi Liu
47769d14bc
Remove swc minify related code branches (#65690)
### What

Remove `swcMinify` related branches as the option is deprecated and it's
always enabled

* Remove the related branches for checking `config.swcMinify`
* Remove the related telemetry about `swcMinify`
2024-05-13 23:37:37 +02:00
Jiachi Liu
af9ac76abe
Remove rsc esm client module extra exports (#65519)
### What

Remove the extra `__esModule` and `$$typeof` export for ESM client
module

For a client page reference, it changed on server side in renderer:

Previous: `{ __esModule, $$typeof, default }`
Now: `{ default }`

### Why

The Module object itself appears as a client reference but it can't be
rendered since it's not a real reference. I'm not sure why it was added
but I think the right thing for an ESM module is to not treat the module
itself as a client reference but only the objects inside of it. E.g. the
"default" export. That's what React does upstream for ESM modules.

Closes NEXT-3360
2024-05-09 19:04:19 +02:00
hrmny
64b718c661
chore: update prettier to 3.2.5 (#65092) 2024-05-08 21:47:14 +02:00
OJ Kwon
531348d864
feat(next): revise server component error message (#65468)
### What

Coming from internal feedback:
https://vercel.slack.com/archives/C046HAU4H7F/p1714858224393659
2024-05-08 12:39:37 -07:00
JJ Kasper
dcff078936
Re-land build(edge): extract buildId into environment (#65426)
### What

* Extract `buildId` and server action encryption key into environment
variables for edge to make code more deterministic
* Fixed the legacy bad env names from #64108
* Always sort `routes` in prerender manifest for consistent output
* Change `environments` to `env` in middleware manifest, confirmed with
@javivelasco this is a fine change without need to bumping the version

### Why

Dynamic variants like `buildId`, SA `encryptionKey` and preview props
are different per build, which results to the non determinstic edge
bundles. Once we extracted them into env vars then the bundles become
deterministic which give us more space for optimization


Closes NEXT-3117

Reverts vercel/next.js#65425

Co-authored-by: Jiachi Liu <inbox@huozhi.im>
2024-05-08 10:40:15 +02:00
Sebastian Silbermann
2c31c79ac8
Support React 19 in App and Pages router (#65058)
Closes NEXT-3218

---------

Co-authored-by: Jiachi Liu <inbox@huozhi.im>
2024-05-07 18:18:32 +02:00
JJ Kasper
85a874a35b
Revert "build(edge): extract buildId into environment" (#65425)
Needs to hold until upstream roll-out

Reverts vercel/next.js#64521
2024-05-06 16:54:23 -07:00
Jiachi Liu
ce99c61b9e
build(edge): extract buildId into environment (#64521)
### What

* Extract `buildId` and server action encryption key into environment
variables for edge to make code more deterministic
* Fixed the legacy bad env names from #64108
* Always sort `routes` in prerender manifest for consistent output
* Change `environments` to `env` in middleware manifest, confirmed with
@javivelasco this is a fine change without need to bumping the version

### Why

Dynamic variants like `buildId`, SA `encryptionKey` and preview props
are different per build, which results to the non determinstic edge
bundles. Once we extracted them into env vars then the bundles become
deterministic which give us more space for optimization


Closes NEXT-3117

---------

Co-authored-by: Tobias Koppers <tobias.koppers@googlemail.com>
Co-authored-by: JJ Kasper <jj@jjsweb.site>
2024-05-06 16:52:24 -07:00
Sebastian Silbermann
89d2abdf8c
Pages router: Use attribute-based head children reconciler when strictNextHead is enabled (#65408)
Closes NEXT-3326
2024-05-06 19:32:14 +02:00
Sebastian Silbermann
581fb0c988
Improve Head > script coverage (#65399)
Closes NEXT-3324
2024-05-06 10:47:18 +02:00
Tim Neutkens
bbd8452d6b
Fix crypto import in edge runtime with Turbopack (#65171)
## What?

Ensures just importing `crypto` does not error, only when it is used it
shows an error in the edge runtime. This matches webpack behavior. The
`crypto` module was missing the list of unsupported packages in the
Next.js Turbopack integration.

Fixes #64464
Fixes PACK-2954

## TODO

While adding tests for this issue I found another bug that only happens
with webpack.

Specifically these 4 packages are accidentally being polyfilled even
when they're not set up to be polyfilled. i.e. there's no npm package
installed for polyfilling them through aliasing or such. Even in that
case `punycode`, `process`, `querystring`, and `string_decorder` get
polyfilled regardless, this causes the newly added test to fail.

Removing the polyfills would be potentially breaking so we'll want to
change it in Next.js 15 instead.

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

-->


Closes NEXT-3252
2024-04-30 11:26:52 +02:00
Jiachi Liu
eb89e392cf
Fix next/dynamic with babel and src dir (#65177)
### What

* Fix `next/dynamic` with babel config and `src/` directory
* Separate the existing `next/dynamic` dev tests, make it easier to
cover more cases, add `.babelrc` + `src/` folder coverage case

### Why

* The new transform is using `src/` or root dir as the base directory
`next/dynamic` for generating relative module path as unique key for
`next/dynamic` modules. The babel one was always using the root dir
(`cwd`), which is incorrect. It should use the `src/` dir.

In the future we could make the different solution to generate the
unique id simpler, instead of using relative paths

Closes NEXT-3254
Closes NEXT-3251
Fixes #64741
2024-04-29 23:02:52 +00:00
Hendrik Liebau
3438b39fcf
Improve initial setup with new App Router TypeScript project (#64826) 2024-04-26 18:19:50 +02:00
Wyatt Johnson
c6320ed87a
Replace createNextDescribe with nextTestSetup (#64817)
<!-- 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 #

-->

I took some time and [wrote a
codemod](https://gist.github.com/wyattjoh/0d4464427506cb02062a4729ca906b62)
that replaces the old usage of the `createNextDescribe` with the new
`nextTestSetup`. You'll likely have to turn on hiding of whitespace in
order to review, but this should primarily introduce no changes to the
test structure other than using the new mechanism now.

Closes NEXT-3178
2024-04-25 12:06:12 -06:00
Sebastian Silbermann
04571f39be
Update React from 14898b6a9 to c3048aab4 (#64798) 2024-04-25 12:35:35 +02:00
Will Binns-Smith
61a0f09c59
Turbopack: Don’t show stack traces for internal modules (#64228)
See
ac7607f977/packages/next/src/client/components/react-dev-overlay/server/shared.ts (L59-L62).

Test Plan: Added an e2e test.


Closes PACK-2919
2024-04-18 16:56:24 -07:00
Jiachi Liu
1e3a1cbaab
Upgrade typescript to 5.3 (#64043)
Closes NEXT-2997

---------

Co-authored-by: eps1lon <sebastian.silbermann@vercel.com>
2024-04-17 18:35:29 +02:00
Shu Ding
754fadacf3
Revert "fix(next): global not-found not working on multi-root layouts" (#64601)
Reverts #63053.

Closes NEXT-3135
2024-04-17 11:19:18 +02:00
Adam Jones
f563940f69
next/script: Correctly apply async and defer props (#52939)
### Summary

Fixes #52935

`next/script` has a `Script` component that supports an `async` prop.
However, when scripts are loaded with the `async` prop set to false, the
script is loaded as if async was set to true. This may cause scripts to
execute out of order. Repro:
https://github.com/domdomegg/next-async-script-reproduction

I think this is occurring because Next uses setAttribute to set the
async and defer attributes. However, this is not a valid way to set
these properties on a script. This is because . Demo:
https://jsfiddle.net/6ktpfae1/

This PR fixes this behaviour by using removeAttribute after calling
setAttribute (rather than using setAttribute "false"). This appears to
result in correct behaviour.

Given it appears this workaround was already applied in `next/head`,
I've harmonised the code between these two.

### Next steps

I think this PR is ready for review. I acknowledge there are no test
changes, but there are no existing tests for `next/script` at all and
creating them I think would be disproportionally difficult given issues
in #52943.

---------

Co-authored-by: Tim Neutkens <tim@timneutkens.nl>
Co-authored-by: Sam Ko <sam@vercel.com>
Co-authored-by: JJ Kasper <jj@jjsweb.site>
2024-04-15 15:01:50 -07:00
Jiwon Choi
81450de6af
hotfix: hardcoded skip turbopack tests to manifest (#64515)
cc @shuding 

CI run failed after #63053 on turbo production, which had not yet been
targeted for turbo.

x-ref: #63103

---------

Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
Co-authored-by: Leah <8845940+ForsakenHarmony@users.noreply.github.com>
Co-authored-by: Jiachi Liu <inbox@huozhi.im>
2024-04-15 19:46:42 +00:00
Jiwon Choi
30521f20ff
fix(next): global not-found not working on multi-root layouts (#63053)
## Why?

For multi-root layouts (route groups on the root with their root
layouts, no layout file on the root), it is not possible to use global
`not-found` since the `layout` is missing on the root.

```sh
.
└── app/
    ├── (main)/
    │   └── layout.js
    ├── (sub)/
    │   └── layout.js
    └── not-found.js --> ERR: missing layout
```

Current Behavior:

```sh
not-found.js doesn't have a root layout. To fix this error, make sure every page has a root layout.
```

## What?

Let multi-root layouts also benefit from the global `not-found`.

## How?

Wrap root `not-found` with default layout if root layout does not exist.
Although this solution is not `multi-root` specific, it won't produce
critical issues since a root `layout` is required for other cases.

Fixes #55191 #54980 #59180
2024-04-15 18:25:53 +02:00
Jiachi Liu
cb8fb3291a
Fix client boundary inheritance for barrel optimization (#64467)
### What

Inherit the client boudaries from the found matched target in load
barrel

### Why
The root cause with the barrel transform, we missed the client boundary
directive during the transform.
Since the new version of mui's case looks like this:

Import path
page.js (server module) -> `<module>/index.js` (shared module) ->
`<module/subpath>/index.js` (client module) ->
`<module/subpath/sub-module.js> (client module)

After our transform, we lost the `"use client"` which causes the
mismatch of the transform:

In `rsc` layer: the file pointing to the sub module entry
(`<module/subpath>/index.js`), but without the client boundary.


Fixes #64369 
Closes NEXT-3101
2024-04-14 23:36:20 +02:00
Jiachi Liu
142050ddc0
Fix css FOUC in dynamic component (#64294)
### What

CSS imports in components that loaded by `next/dynamic` in client
components will cause the css are missing initial in
SSR, and loaded later on client side which will lead to FOUC. This PR
fixes the issue and get CSS preloaded in the SSR for dynamic components.

### Why

The CSS from client components that created through `next/dynamic` are
not collected in the SSR, unlike RSC rendering we already collect the
CSS resources for each entry so we included them in the server rendering
so the styles are availble at that time. But for client components, we
didn't traverse all the client components and collect the CSS resources.

In pages router we kinda collect all the dynamic imports and preload
them during SSR, but this approach is not able to be applied to app
router due to different architecture. Since we already have all the
dynamic imports info and their related chunks in
react-loadable-manifest, so we can do the similar "preloading" thing in
app router. We use the current dynamic module key (`app/page.js ->
../components/foo.js`) which created by SWC transform and match it in
the react loadable manifest that accessed from `AsyncLocalStorage`, to
get the css files created by webpack then render them as preload
styleshee links. In this way we can SSR all the related CSS resources
for dynamic client components.

The reason we pass down the react loadable manifest through
`AsyncLocalStorage` is that it's sort of exclude the manifest from RSC
payload as it's not required for hydration, but only required for SSR.

Note: this issue only occurred in dynamic rendering case for client
components.

### Other Changes Overview

- Change the react loadable manifest key from pages dir based relative
path to a source dir based relative path, to support cases with both
directory or only one of them

Closes NEXT-2578
Fixes #61212
Fixes #61111
Fixes #62940

Replacement for #64021 but only with production test
2024-04-10 16:16:20 +02:00
Sebastian Silbermann
ed4d772359
Stop using baseUrl in root tsconfig (#64117) 2024-04-09 00:25:43 +02:00
Jiachi Liu
530382aeea
Fix hydration error higlight when tag matched multi times (#64133)
### What

We introduced a new algorithm to find the matched hydration error tags,
when there're two tags indicating children and parent as bad descendence
relationship. Now we search for the child first from the last index, and
then from found child to search its above parent. This way we can find
the two related tags in O(1), since they could be not directly nested.

### Why

When a hydration error occurred, such as bad nesting `div` under `p`,
one of the tag `div` is matched multiple times in the component stack,
it shouldn't be highlighted multiple times. This PR fixes the bad
matching about multiple nested tags, e.g. when there're many `div` tag
and `div` is one of the bad tag, only the one directly under p should be
highlited.

Case
```
Page > div > div > p > div
```

Current Result: all `div` and `p` get highlighted, `[]` represents
highlighted.
```
Page > [div] > [div] > [p] > [div]
```

Expected: only the related 2 tags are highlighted, `[]` represents
highlighted.
```
Page > div > div > [p] > [div]
```

Thanks @JohnPhamous for reporting the issue


Closes NEXT-3022
2024-04-08 19:12:03 +02:00
Jiachi Liu
14c8900e70
style(dev-overlay): refine the error message header styling (#63823)
### What

Polish the UX based on the feedbacks from @sambecker 

* Fix the font that still use mono
* Align the color, to use red for the warnings
* Give the title to build error
* Only highlight the nextjs doc url as link

### After vs Before

#### Runtime Error


<img width="335" alt="image"
src="https://github.com/vercel/next.js/assets/4800338/64f2f692-1eae-41db-9287-046aff9ba112">
<img width="335" alt="image"
src="https://github.com/vercel/next.js/assets/4800338/2d4bad15-745e-4083-ba57-8968c0f321c2">

#### Build Error

<img width="335" alt="image"
src="https://github.com/vercel/next.js/assets/4800338/ecfc3883-4522-40c6-b042-6d85e7ea970e">
<img width="335" alt="image"
src="https://github.com/vercel/next.js/assets/4800338/bbf37ec5-b639-4b95-a87f-9911182e431c">



Closes NEXT-2958
2024-04-05 23:39:22 +02:00
Maikel
4efe14238b
fix: bundle fetching with asset prefix (#63627)
Closes: https://github.com/vercel/next.js/issues/63623

When a relative assetPrefix was set (e.g. `/custom-asset-prefix`),
bundle fetching would always return a 404 as the assetPrefix was not
removed from filesystem path

---------

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2024-03-29 16:38:24 -07:00
Donny/강동윤
29d53c87ea
feat(next-swc): Pass names of side-effect-free packages (#63268)
### What?

Pass the names of side-effect-free packages specified in `experimental.optimizePackageImports`.

Turbopack counterpart: https://github.com/vercel/turbo/pull/7731

### Why?

Some packages like `@tremor/react` causes a problem without `optimizePackageImports`.

### How?

Closes PACK-2527
2024-03-29 06:28:48 +00:00
Will Binns-Smith
e519634c81
Turbopack: Fail when next/font is used in _document (#63788)
Test Plan:
d01a621961/test/development/next-font/font-loader-in-document-error.test.ts (L19)


Closes PACK-2858
2024-03-28 15:29:03 -07:00
Tobias Koppers
ab5d0a2002
update turbopack (#63778)
* https://github.com/vercel/turbo/pull/7797 <!-- Tobias Koppers - fix
externals in side-effect optimized modules -->
* https://github.com/vercel/turbo/pull/7830 <!-- Tobias Koppers - Avoid
showing import map description in resolving issue when there is no
import map mapping -->
* https://github.com/vercel/turbo/pull/7833 <!-- Tobias Koppers - add
next.js trace format -->
* https://github.com/vercel/turbo/pull/7835 <!-- Tobias Koppers -
correct global start by first start time -->
* https://github.com/vercel/turbo/pull/7812 <!-- Will Binns-Smith -
Turbopack docs: Fix broken webpack loaders link -->
* https://github.com/vercel/turbo/pull/7847 <!-- Will Binns-Smith -
Turbo tasks: Reuse aggregation context and apply queued updates -->
* https://github.com/vercel/turbo/pull/7840 <!-- Tobias Koppers - add
concurrency corrected duration -->
* https://github.com/vercel/turbo/pull/7854 <!-- Tobias Koppers - fix
size_hint on count hash set -->
2024-03-27 20:09:08 +01:00
Balázs Orbán
752d6e49d5
feat(error-overlay): style tweaks (#63522) 2024-03-25 12:37:12 -06:00
Donny/강동윤
6b6590592e
Update turbopack (#63541)
# Turbopack

* https://github.com/vercel/turbo/pull/7815 <!-- Tobias Koppers - fix
alias in getResolve -->
* https://github.com/vercel/turbo/pull/7796 <!-- Donny/강동윤 - Update
`swc_core` to `v0.90.24` -->
* https://github.com/vercel/turbo/pull/7775 <!-- Tobias Koppers - fix
single css chunks with import context -->
* https://github.com/vercel/turbo/pull/7776 <!-- Tobias Koppers - change
port of trace-server -->
* https://github.com/vercel/turbo/pull/7763 <!-- Tobias Koppers -
Tracing improvements -->
* https://github.com/vercel/turbo/pull/7813 <!-- Tobias Koppers - fix
webpack loader incorrectly calling custom_evaluate -->
* https://github.com/vercel/turbo/pull/7764 <!-- Tobias Koppers - fix
some small bugs in turbo-tasks that are required for GC -->
* https://github.com/vercel/turbo/pull/7816 <!-- Chris Olszewski -
chore: remove some unused imports -->
* https://github.com/vercel/turbo/pull/7823 <!-- OJ Kwon -
fix(sourcemap): update sourcemap, remove checker -->

### What?

Update SWC crates to
ad932f0921

### Why?

To keep in sync.

### How?



 - Closes PACK-2807
 - Closes PACK-2819

---------

Co-authored-by: Tim Neutkens <tim@timneutkens.nl>
2024-03-25 03:15:02 +00:00
Will Binns-Smith
aeafed9405
Turbopack: Fail when module type is unhandled (#63535)
This causes Turbopack to fail and communicate when a file with an
unhandled or unregistered extension is built.

Test Plan: `TURBOPACK=1 pnpm test-dev
test/development/basic/hmr.test.ts`


Closes PACK-2803
2024-03-21 00:36:01 +00:00
Balázs Orbán
a2556196ea
refactor(test): switch tests to use pnpm in more places (#63196) 2024-03-20 15:00:58 -04:00
OJ Kwon
e12535c706
build(cargo): bump up turbopack (#63429)
### What

fix test/development/acceptance-app/app-hmr-changes.test.ts.

Closes PACK-2765
2024-03-18 21:11:37 +00:00
Will Binns-Smith
f96ec515d7
Turbopack HMR: use own snapshot in error-recovery (#63417)
This records dedicated snapshots for Turbopack for the remaining tests
in `test/development/acceptance/error-recovery.test.ts`. The only
remaining difference was the lack of Import trace information.

Test Plan: `TURBOPACK=1 pnpm test-dev
test/development/acceptance/error-recovery.test.ts`


Closes PACK-2761
2024-03-18 12:15:52 -07:00
Jiachi Liu
e1a7de0d04
feat(error-overlay): handle script under html hydration error (#63403)
script tag cannot be placed under html directly, users reported a case
in #51242 that having `<Script>` under html will cause hydration error,
this will display the React hydration error related warning of bad usage
for it.

You will see this warning in dev overlay instead of displaying nothing
```
In HTML, <script> cannot be a child of <html>.
This will cause a hydration error.
```

Added two other react warnings detection patterns  as well
* `Warning: In HTML, text nodes cannot be a child of <%s>.\nThis will
cause a hydration error.',`
* `Warning: In HTML, whitespace text nodes cann...`

But tested they're not generating hydration errors, only warnings in
console, so we don't need to have tests for them.

Closes NEXT-2835
2024-03-18 11:40:01 +01:00
Jiachi Liu
53c21881de
fix(error-overlay): matching html tag with brackets in hydration error (#63365)
### What

* The tags extracted from hydration errors could be "<div>" and "p", we
need to stripe the brackets "<>" for matching the tag name from
component stack
* Change the dimmed text color to lighter so you can see it better in
light mode

#### After vs Before

<img width="450"
src="https://github.com/vercel/next.js/assets/4800338/6caed5ac-c073-41cc-a699-eb29f3785d59">

<img width="450"
src="https://github.com/vercel/next.js/assets/4800338/926aa80f-2a49-4362-b77e-16b819955b0a">


Closes NEXT-2828
2024-03-16 19:24:54 +00:00
OJ Kwon
6b2e2a0d2e
test(fixture): update middleware test fixture & manifest (#63340)
### What

Small update to test fixture to make test stable.

Closes PACK-2749
2024-03-15 15:12:24 -07:00
Jiachi Liu
6556a342b9
fix: hydration error display for text under tag case (#63288)
There's a type of hydration warning is mismatch `"text content"` under a
`<tag>`, such as `Did not expect server HTML to contain the text node
"bad text" in <div>.`, we need to treate them separately from the text
diff or bad neseting tags.

### After

![image](https://github.com/vercel/next.js/assets/4800338/4dabfeae-b42a-4232-ab55-1704db36f5ce)


### Before


![image](https://github.com/vercel/next.js/assets/4800338/1da14435-cb3a-4883-84c8-7f0ce4c83b21)


Closes NEXT-2819
2024-03-14 16:03:28 +01:00