Commit Graph

516 Commits

Author SHA1 Message Date
Vercel Release Bot 2f7a48fa4d Upgrade React from 2d16326d-20240930 to 70fb1363-20241010 (#71118)
Co-authored-by: eps1lon <sebastian.silbermann@vercel.com>
2024-10-11 17:03:27 +00:00
Hendrik Liebau 490704430b Add source map support for server components/actions in the browser (#71042)
This PR adds support for showing the original server sources of server
components and server actions in the browser's developer tools.

To accomplish that, we're building on top of #69190, #70563, and #70564,
in which we prepared the proper generation of the source maps.

This PR completes the feature, by wiring up `findSourceMapURL` (see
https://github.com/facebook/react/pull/30741) with a new dev server
middleware that serves those source map files to the browser.

Another change we had to make is disabling the dead-code elimination of
server actions in client bundles (see #70103), but only in development
mode. This optimization is primarily intended for production bundles, so
the change should not pose a problem.

With that, it's now possible to jump directly into the server sources
from the browser's dev tools, e.g. for component stacks of server logs
that are replayed in the browser, or when inspecting server action props
in the React DevTools.
2024-10-11 13:53:39 +00:00
Niklas Mischkulnig 3093851092 Turbopack: more sourcemappings for imports (#70469)
Closes PACK-3270

- Retains sourcemaps for the generated `__turbopack_import__`
statements. At least in dev
- Refactoring to allow simply returning statements to hoist

<br>

- [x] ~~Prevent duplicate `__turbopack_import__` calls when importing
the same module multiple times~~
- [x] ~~The order is slightly different now~~
2024-10-09 09:30:32 +02:00
Zack Tanner a4763ccf14 Reapply "Dedupe sync access warning on the Server by callsite" (#70672) (#70738)
Relands https://github.com/vercel/next.js/pull/70672 with fixes that
were failing in CI.


[x-ref](https://github.com/vercel/next.js/actions/runs/11153352206/job/31002090099)
2024-10-03 12:38:35 -07:00
Zack Tanner ebffec2538 Revert "Dedupe sync access warning on the Server by callsite" (#70736)
This fails the 18.3.1 matrix since `React.cache` is unavailable.

Needs to be relanded with a patch to no-op in this case.

Reverts vercel/next.js#70672
2024-10-02 17:19:46 -07:00
Sebastian "Sebbie" Silbermann fb8564428d Dedupe sync access warning on the Server by callsite (#70672)
The warnings are fixed by callsite not by something changing an
abstraction on top of it. That's at least what the codemod assumes.

Basically each warning is now mapped to a change the codemod should've
made but didn't to avoid false-positives (e.g. propagating `async`
across module boundaries).

For browser specific access we don't dedupe since we have no
`React.cache`
2024-10-02 16:52:01 -07:00
Donny/강동윤 5fd1d537c1 feat(next-swc): lint for ssr: false in server components (#70378)
Co-authored-by: Jiachi Liu <inbox@huozhi.im>
2024-09-25 20:40:33 +02:00
Sebastian "Sebbie" Silbermann 1cb6faaee1 Extend support of Pages router to React 18 (#70219) 2024-09-25 19:08:13 +02:00
Niklas Mischkulnig 21f0c30e2c Turbopack: improve stack trace in overlay (#70343)
## Before:

<img width="965" alt="Bildschirmfoto 2024-09-23 um 14 55 16"
src="https://github.com/user-attachments/assets/26aabfdd-0e43-4dd2-a025-5eaf6a717043">


## After:
<img width="972" alt="Bildschirmfoto 2024-09-23 um 14 52 54"
src="https://github.com/user-attachments/assets/3b7ce28a-c2ea-475b-ab53-ed9838546400">

## The whole Turbopack module registry is hidden in `Next.js`:
<img width="612" alt="Bildschirmfoto 2024-09-23 um 14 53 04"
src="https://github.com/user-attachments/assets/a38295ad-90a7-49b2-a272-661e0b80bfbb">
2024-09-24 09:53:06 +02:00
Janka Uryga 1fa8e23e4d test: fix race condition in serverComponentsHmrCache tests (#70368)
fixes a race condition in the `after()`-related test in
`server-components-hmr-cache.test.ts`

i made `getLoggedAfterValue` stricter while investigating an unrelated
issue, and saw it occasionally throw (see [CI
run](https://github.com/vercel/next.js/actions/runs/11001754094/job/30547234764?pr=70362#step:29:708)).
before this change, if `getLoggedAfterValue` was called before any logs
with `"After: "` were written, it would just return `undefined`, which
is obviously not what the test wants. this seems to have been happening
occasionally, but it wasn't visible because even if we got `undefined`
from one of the calls, the
`expect(valueBeforePatch).not.toEqual(valueAfterPatch)` assertion would
still pass -- one of the values is a string and the other is
`undefined`, so obviously they're not equal!
2024-09-24 09:52:52 +02:00
Jiachi Liu 4380d0b79d Externalize node binary modules for app router (#70330) 2024-09-23 21:03:52 +02:00
Tim Neutkens 69f07b680c Revert "Support React 18 in Pages Router" (#69911)
Reverts vercel/next.js#69484
2024-09-10 10:20:27 +02:00
Sebastian "Sebbie" Silbermann 0f2845d2d8 Support React 18 in Pages Router (#69484)
Pages router (`/pages`) will continue to support React 18 not the React
19 RC. Current thinking is that we'll add support for React 19 in Pages
Router once 19 is stable.

This does not affect App Router (`/app`) which continues to use the
latest React Canary (i.e. React 19).

https://github.com/vercel/next.js/pull/65058 is required reading to
understand the changes in this PR

---------

Co-authored-by: Zack Tanner <1939140+ztanner@users.noreply.github.com>
2024-09-09 15:26:08 -07:00
Jiachi Liu d7c6200c87 Add browser devtool inspect url copy button to dev overlay (#69357) 2024-09-03 17:18:39 +02:00
Janka Uryga 53201b178f [after] duplicate test pages for edge instead of next.patch (#69477)
`unstable_after` needs to be tested in both nodejs and edge runtimes.
Previously, we set the runtime via `next.patch()`, but this proved
error-prone (e.g. because `sandbox()` call would override this patch,
and not actually run anything in edge...)

This PR makes this more static by splitting the test pages for
`unstable_after` into `/nodejs` and `/edge`, each with a corresponding
`export const runtime = "..."` in its root layout. The pages in `/edge`
mirror the structure of `/nodejs` and reexport components from it (which
makes the tests easier to update than simply duplicating everything).
note that "use client" directives and route segment configs cannot be
reexported and need to be duplicated.
2024-08-30 15:01:25 +00:00
Sebastian "Sebbie" Silbermann 3e3fcdb8df Ensure vendored react-dom/server.browser is used (#69142) 2024-08-21 16:18:09 +02:00
Sebastian "Sebbie" Silbermann e21f1b5bf9 Remove unused react-dom/server.browser references (#68988) 2024-08-20 20:29:24 +02:00
Jimmy Lai 15aeb92efb misc: tweak fetch patch restoration timing during HMR to allow for userland fetch patching (#68193) 2024-08-20 14:58:55 +00:00
Sebastian "Sebbie" Silbermann bfa7df40e3 Remove references to removed react-dom/server APIs in Webpack shims (#68987) 2024-08-20 16:58:10 +02:00
Sebastian "Sebbie" Silbermann 43b99d0f4c Add test suite for react-dom/server usage in React Server environment (#68945) 2024-08-20 15:28:58 +02:00
Jiwon Choi 485497d943 chore: remove asset prefix warning log and update docs (#68681)
### Why?

In https://github.com/vercel/next.js/pull/68622 we fixed a bug that HMR
breaks when `assetPrefix` is set to full URL.
The fix was targeted to the edge case where the user may set `localhost`
to the `assetPrefix`, and technically, when the request is valid the HMR
should work.

However, we do not recommend this pattern as the `assetPrefix` is
intended to be used for setting a CDN URL.

### How?

Therefore we modify the docs to gently imply that the `assetPrefix` is
for CDN URL.
Also, removed the warning log that could be confusing whether we support
it or not.
Setting localhost will still work, but we do not mention about it within
the app.
2024-08-09 02:53:49 +09:00
Jiwon Choi 01a3f988b9 fix: HMR not works when assetPrefix set to URL (#68622) 2024-08-08 15:34:36 +09:00
hrmny a4665ef7a0 fix(turbopack): don't log errors when they are thrown (#68331)
### What?
Disables logging when an error is thrown anyway (which will be logged
upstream).

Reduces the errors logged when there is a compiler error to 1, currently
it shows 3 times.


Closes PACK-3170
2024-08-05 17:26:58 +02:00
JJ Kasper e9990a6a86 Move static indicator into dev overlay (#68369)
This moves the static indicator we added for the app router into the dev
overlay so it can share the logic/be aware when either are showing to
coordinate position. This also applies similar design to make the look
more consistent as well.



https://github.com/user-attachments/assets/bca899d4-0635-4868-8284-02f0cb4b5444

Closes: NDX-74
2024-07-31 22:52:07 -07:00
Sebastian Silbermann da0c46900c Update React from 6230622a1a-20240610 to 3208e73e-20240730 (#68330)
Co-authored-by: Hendrik Liebau <mail@hendrik-liebau.de>
2024-07-30 22:55:39 +02:00
JJ Kasper c039891908 Revert "Update React from 6230622a1a-20240610 to 76002254-20240724 (#68149)" (#68300)
This seems to be causing an crash on vercel-site for our [one of our
top-level
pages](https://vercel-site-git-update-next-v15-0-0-canary-89.vercel.sh/ai)

Reverts https://github.com/vercel/next.js/pull/68149
2024-07-30 10:19:57 +02:00
Sebastian Silbermann 67a1fb892c Update React from 6230622a1a-20240610 to 76002254-20240724 (#68149) 2024-07-29 07:19:45 +00:00
Kento Moriwaki 7307d6255a Ignore serverComponentChanges in pages (#66312)
## Description

I discovered a bug related to the coexistence of the app router and
pages router in our application. When a page is being served by the
pages router, any changes to server components (in this case,
`globals.css` imported from `app/layout.tsx`) cause the entire page to
reload, significantly lowering productivity.

I believe this is not the intended behavior since server component
changes should have no impact on pages served by the pages router.

## Investigation

I traced the changes and found that:

- At the point of this PR
(https://github.com/vercel/next.js/pull/41464), the process seems to be
handling this correctly.
- Later, in this PR (https://github.com/vercel/next.js/pull/45268), it
started causing reloads, seemingly intended for the app router but
inadvertently affecting the pages router as well.

Given that separate `hot-reloader-client.ts` files are now being used
for the app router and pages router, it is now possible to correctly
branch the hot-reloading process.

I have tested this change locally and it is working fine.
2024-07-24 10:27:19 -07:00
JJ Kasper 24a811f3c8 Downgrade React from dfd30974ab-20240613 to 6230622a1a-20240610 2024-07-24 10:24:23 +02:00
Sebastian Silbermann 668f8edb0e Update React from 6230622a1a-20240610 to dfd30974ab-20240613 (#66711) 2024-07-23 10:54:10 +02:00
Jiachi Liu ec34cdfbbb Fix logging option internal consuming (#67972) 2024-07-22 09:53:28 +08:00
Jiwon Choi 05decb11a8 feat: disable development logging by setting logging: false in next config (#67590)
### Why?

Logging compiled route `GET / in ...` is a very handy feature.
It would be more great if we have an option to opt-out the logging.

### How?

Set `logging` to false in next config.

```js
const nextConfig = {
 logging: false,
}
// ...
```

x-ref: #65992

Closes NEXT-3583
Closes NDX-26

---------

Co-authored-by: Jiachi Liu <inbox@huozhi.im>
Co-authored-by: Delba de Oliveira <32464864+delbaoliveira@users.noreply.github.com>
2024-07-20 03:26:51 +09:00
Hendrik Liebau 5c9706ed1f Enable experimental.serverComponentsHmrCache by default (#67800)
The target release for the [server components HMR
cache](https://github.com/vercel/next.js/pull/67527) feature is 15, so
we want to enable it already for canaries.
2024-07-17 21:10:37 +02:00
Jiwon Choi d33d57d636 Align the typeEnv value type with default process env value type (#67804)
### What

Align the typeEnv value type with default process env value type `string
| undefined`

### Why?

When the `experimental.typedEnv` is enabled, we generate a `env.d.ts`
file during the Dev Server.
The type for the loaded env values will be `string` on Dev (type
inference).

Since we do not generate the `env.d.ts` file during the build time,
there could be confusion from the difference of env types between the
Dev and Build.

The reason we don't want to strongly type as `string` or `readonly
string` is because the multiple environment: Dev, Preview, Production,
where the env could be different.

If we type in one place based on the loaded .env file, the environment
(like deployment preview or deployment production) might not have these
values in env files or they only have the env vars in Node.js
`process.env`.

So the type file in build could be unpredictable, after discussion we
decided to keep the original type for values, but the keys of envs are
still be able to hint during development.


### How?

Temporarily infer the type as `string | undefined`.
The `typedEnv` will serve as the intellisense (type hint).

Closes NDX-84
2024-07-17 09:40:54 +00:00
Hendrik Liebau 57baeec90d Server Components HMR Cache (#67527)
This adds support for caching `fetch` responses in server components
across HMR refresh requests. The two main benefits are faster responses
for those requests, and reduced costs for billed API calls during local
development.

**Implementation notes:**

- The feature is guarded by the new experimental flag
`serverComponentsHmrCache`.
- The server components HMR cache is intentionally independent from the
incremental cache.
- Fetched responses are written to the cache after every original fetch
call, regardless of the cache settings (specifically including
`no-store`).
- Cached responses are read from the cache only for HMR refresh
requests, potentially also short-cutting the incremental cache.
- The HMR refresh requests are marked by the client with the newly
introduced `Next-HMR-Refresh` header.
- I shied away from further extending `renderOpts`. The alternative of
adding another parameter to `renderToHTMLOrFlight` might not necessarily
be better though.
- This includes a refactoring to steer away from the "fast refresh"
wording, since this is a separate (but related) [React
feature](https://github.com/facebook/react/issues/16604#issuecomment-528663101)
(also build on top of HMR).

x-ref: #48481
2024-07-13 18:22:58 +02:00
Jiwon Choi a4a628c149 refactor: typedEnv is not readonly (#67693)
### Why?

The process.env values may be modified, so is not `readonly string`.

### How?

Removed `readonly`.
2024-07-12 20:02:33 +09:00
JJ Kasper 8cc2dd0edf Add prerender indicator for app router (#67306)
## Background

Currently in app router during development all pages are dynamic
rendered and streamed since we don't know if a page will be prerendered
until after the page is rendered. During build time we do a render pass
for each path and if it doesn't bail from static generation it is
considered prerendered/ISR'd.

Since it can be tricky to track all the bail outs for static generation
and doing numerous builds to track this isn't feasible we want to have
some sort of signal in development to show if it would have been
prerendered.

## New Handling

To alleviate the above pain point we are planning to bring back the
prerendered indicator from pages initially and have a config to disable
if desired. We are also going to investigate other possible indicators
potentially through headers or similar.

<details>

<summary>Preview</summary>

![CleanShot 2024-06-29 at 08 56
11@2x](https://github.com/vercel/next.js/assets/22380829/37d4d351-903d-49a2-9541-932e7d5a1e54)

![CleanShot 2024-06-29 at 08 55
46@2x](https://github.com/vercel/next.js/assets/22380829/8356f287-e0d0-4c37-aa1e-1f08639dd478)

</details>

---------

Co-authored-by: Jiachi Liu <inbox@huozhi.im>
2024-07-10 20:37:51 +00:00
Jiwon Choi 1309deea30 feat: type hint for env in dev mode (#67157) 2024-07-10 22:36:12 +09:00
hrmny a22858d6e7 test: add test for parallel routes hmr (#67392)
### What?

A test for #67222
2024-07-02 15:07:16 +00:00
Sebastian Silbermann fe8d953e2d Replace hasRedbox() (#67025)
...with `assertHasRedbox` and `assertNoRedbox`.

`hasRedbox()` has a hardcoded timeout of 5s that is only required for
the negative assertion.
Instead, we now have dedicated assertions for the positive
(`assertHasRedbox`) and negative case (`assertNoRedbox`).
The negative assertion still has the hardcoded timeout.
But the positive assertion just retries until we find the Redbox.

This speeds up tests using the positive assertion.
Removing `hasRedbox` also uncovered some unused expressions e.g. `await
hasRedbox(browser)`.
These expressions probably wanted to use `expect(await
hasRedbox(browser)).toBe(true)
2024-06-20 10:37:32 +02:00
Hendrik Liebau 994d8ee2c3 Fix broken BrowserInterface type (#66461) 2024-06-03 12:56:49 +00: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
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
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
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
Sebastian Silbermann ed4d772359 Stop using baseUrl in root tsconfig (#64117) 2024-04-09 00:25:43 +02:00
Donny/강동윤 3e6720c364 build: Update turbopack (#63229)
# Turbopack

* https://github.com/vercel/turbo/pull/7719 <!-- Tobias Koppers - accept
css files outside of the project as virtual assets -->
* https://github.com/vercel/turbo/pull/7661 <!-- Tobias Koppers - more
efficient node.js process startup -->
* https://github.com/vercel/turbo/pull/7720 <!-- Tobias Koppers -
generate correct async module handling for side effects optimization -->
* https://github.com/vercel/turbo/pull/7718 <!-- Donny/강동윤 -
fix(turbopack): Fix CSS Modules class name for lightningcss mode -->

### What?

Update tests to make CSS Modules of `lightningcss` work with CSS grids.

### Why?

`lightningcss` enforces the class name to end with `[local]`.

See: https://lightningcss.dev/css-modules.html#css-grid


### How?

Closes PACK-2731
2024-03-13 10:13:56 +00:00
pacexy 0bad7143d7 Fix webpack HMR for pages on the edge runtime (#60881)
This fixes the issue that build error is not cleared correctly during
`next dev` even if the build succeeds, and we have to re-run `next dev`
to make it work.

It appears only when:

1. page runtime is `edge`
2. use webpack hot reloader
3. import components in the `edge` page

Reproduction:
https://github.com/pacexy/nextjs-edge-webpack-hmr-reproduction

I recorded a screenshot to make it easier to understand:


https://github.com/vercel/next.js/assets/32255488/0ddc21bf-2ea7-49ce-b682-c89dea757c61

Closes NEXT-2168

---------

Co-authored-by: Jiachi Liu <inbox@huozhi.im>
2024-03-11 16:53:04 +01:00