Commit Graph

516 Commits

Author SHA1 Message Date
Jiachi Liu 737d3199c6 [segment-explorer] optimize tree view (#80392) 2025-06-11 18:21:10 +02:00
Jiachi Liu cf1f47a5d1 [dev-overlay] fix duplicate re-render of errors (#80322)
### What

When there's a same error throwing constantly, we should avoid unnecessary re-renders on the exact same error. In dev overlay we already have strategies that can dedupe the error. And we noticed the error is shown correctly but just the dialog got re-rendered with animations.

After digging deeper, noticed we are still adding the same runtime error into the error collection, just because each time it got the new "ID", as the "ID" itself is incremental based on actions. Each action will get a new error ID. Hence we're adding a condition in deduping. If we found that the new error already existed in the previous events, we'll return with the same previous events instance to tell dev overlay that errors are not changed.

Fixes NEXT-4493

#### After
https://github.com/user-attachments/assets/c1f004b5-2de6-445a-aad0-efdfd0ecb8c9

#### Before
https://github.com/user-attachments/assets/1249ed54-ba63-4eb6-a08a-64560ab4014a
2025-06-10 11:42:20 +02:00
Luke Sandberg 19e8e3c3c2 Revert "Revert "[turbopack] Compute Import Traces for Issues"" (#80220)
Reverts vercel/next.js#80215 which was a revert of vercel/next.js#79351

Closes PACK-4105
2025-06-07 15:28:07 -07:00
Jiachi Liu 356cdf2393 [devtool] display segment explorer as tree view (#80261) 2025-06-07 01:07:06 +02:00
Jiachi Liu c2621a14ef [devtool] style the segment explorer as nested view (#80212) 2025-06-06 14:38:58 +02:00
Luke Sandberg 0d2e80554a Revert "[turbopack] Compute Import Traces for Issues" (#80215)
Reverts vercel/next.js#79351

See https://github.com/vercel/next.js/actions/runs/15474422003/job/43570614813#step:34:1556
2025-06-05 13:44:39 -07:00
Luke Sandberg 7a66008cae [turbopack] Compute Import Traces for Issues (#79351)
When turbopack reports an issue, compute a set of import-traces for that file so the user can better understand the context of the issue and trivially answer questions like:

* Why is this file included at all?
* Why does next think this is a client-component?

To do this we leverage the `SingleModuleGraph` and use the `astar` algorithm from `petgraph` to compute the shortest path to a root module.  This isn't the most optimal approach but should be sufficient since we don't anticipate this being a performance issue.

A complex part of this is that the module-graph tracks the relationships between _modules_ but Issues are associated with _files_.  While modules are also associated with files this is a many-to-one relationship.  This is why we might report _multiple_ traces for a single issue and also why a single file might appear multiple times in a trace.

## Open formatting questions

* how should we represent paths from other 'filesystems'?
    - for disk filesystems i could compute relative paths to the root of the current directory? the `[project]` filesystem?  For now i just use the filesystem name as a hypothetically cromulent root.


## Alternatives

The main alternative investigated was associating  Issues with `Modules` by collecting them during graph construction. This unfortunately proved to be a non-trivial performance regression and so it was abandoned.  The core problem is that we would need to introduce additional `OperationVc` and task roots to simply `collect` the issues.  This also wouldn't eliminate the duplicate traces issue, and instead we might end up reporting duplicate issues instead.

## Performance
TODO

Closes PACK-4105
2025-06-05 11:21:11 -07:00
Jiachi Liu bc4b72df8e [devtool] fix explorer flag consuming and style (#80110) 2025-06-03 18:40:59 +02:00
Sebastian "Sebbie" Silbermann c51300807e [dev-overlay] Show error overlay on any thrown value in /app (#79658)
May have been a leftover from earlier. 

We always consider any throw. Even without a sync stack, we might still have an async stack to show. And even if we have no stack at all, the message is still relevant. Basically, never hide errors.
2025-05-27 20:17:38 +02:00
Josh Story bc3045357b [dynamicIO] reimplement dynamicIO validation on prerender (#79414)
This updates the dynamic validation implementation to more closely
follow the pattern used in prerenders for dynamicIO + PPR. Now that PPR
is the only way to use dynamicIO we only have one implementation and the
validation should match it as much as possible.
2025-05-21 11:47:11 -07:00
Hendrik Liebau 2a95766744 Remove obsolete ppr configs from Dynamic IO tests (#79305)
Now that `ppr` is enabled by default when `dynamicIO` is enabled, we can remove the obsolete `ppr: true` configs from the Dynamic IO tests.
2025-05-19 16:52:03 +02:00
Hendrik Liebau 53933954e3 Enable PPR in Dynamic IO tests (#79301)
To prepare for an upcoming change where `ppr` will be enabled
automatically when `dynamicIO` is enabled, we're hard coding `ppr: true`
in the Dynamic IO tests with this PR. The non-PPR assertions are
subsequently removed, which makes up most of the changed lines.

We can now also exclude the tests in the PPR tests manifest, so that
they're not run twice in CI.

> [!NOTE]  
> This PR is best reviewed with hidden whitespace changes.
2025-05-17 20:50:29 +02:00
Jiachi Liu 0ca32b2b4a [devtool] initial support for segment explorer (#78858) 2025-05-16 12:10:59 +08:00
Janka Uryga 733e4d6413 test: fix snapshots in failing tests (#79254) 2025-05-15 20:53:15 +00:00
Hendrik Liebau bc7ce5d68d Reland: Fix false-positive "use cache" misplacement error (#79222)
_Relanding #79151, now ignoring TS AST nodes when checking whether all
exported module items are async functions._

This fixes an error where we incorrectly showed the following compiler
error when using Turbopack:

```sh
Ecmascript file had an error
> 1 | 'use cache'
    | ^^^^^^^^^^^
  2 |
  3 | import { useStuff } from './client-module'
  4 |

The "use cache" directive must be at the top of the file.
```

The directive was regarded as not being at the top of the file, because
the React transform (`EcmascriptInputTransform::React`) injects a
variable declaration for React Refresh (e.g. `var _s =
__turbopack_context__.k.signature`) at the top of the file, before the
`"use cache"` directive.

We can fix this by ensuring that the server action transform (should
really be called "server _function_ transform") runs first.

As a consequence, the transform now needs to be able to parse JSX AST
nodes, which was already explicitly implemented.

closes NAR-130

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

-->
2025-05-15 13:06:28 +02:00
Janka Uryga cb49b483f1 Reland "Ensure mangling is disabled for dev runtime builds (#75297)" (#79201)
Reapplies #75297

Also fixes some rspack tests which didn't await assertions properly so they might have looked like they're passing
2025-05-14 17:38:01 +02:00
Donny/강동윤 de89c8cd01 Revert "Fix false-positive "use cache" misplacement error" (#79160)
Reverts vercel/next.js#79151

It caused a regression like this
```
export type Foo =
     | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Only async functions are allowed to be exported in a "use server" file.
```
2025-05-13 17:21:49 +00:00
Hendrik Liebau c1262aa970 Fix false-positive "use cache" misplacement error (#79151)
This fixes an error where we incorrectly showed the following compiler
error when using Turbopack:

```sh
Ecmascript file had an error
> 1 | 'use cache'
    | ^^^^^^^^^^^
  2 |
  3 | import { useStuff } from './client-module'
  4 |

The "use cache" directive must be at the top of the file.
```

The directive was regarded as not being at the top of the file, because
the React transform (`EcmascriptInputTransform::React`) injects a
variable declaration for React Refresh (e.g. `var _s =
__turbopack_context__.k.signature`) at the top of the file, before the
`"use cache"` directive.

We can fix this by ensuring that the server action transform (should
really be called "server _function_ transform") runs first.

As a consequence, the transform now needs to be able to parse JSX AST
nodes, which was already explicitly implemented.

closes NAR-130
2025-05-13 14:58:02 +02:00
Sebastian "Sebbie" Silbermann 8ea7d4bb35 [dev-overlay] Move error.name to label (#78198) 2025-04-25 11:00:58 +02:00
Jiwon Choi fd438787f3 misc: use correct capitals for React terms (#78445)
- `Client/Server Component`
- `React Hooks`

---------

Co-authored-by: Sebastian "Sebbie" Silbermann <sebastian.silbermann@vercel.com>
2025-04-23 21:50:55 +09:00
Jiachi Liu 5855bdc1fb [errors] fix edge server initial error is not sent via hmr (#78415) 2025-04-23 13:47:00 +02:00
Benjamin Woodruff 8d11384379 fix(turbo-tasks-fs): Update notify-rs, handle recursive symlinks in realpath implementation, add an e2e test for symlinked files (#78220)
While working on filesystem watching stuff, I saw that `notify-rs` had a new `with_follow_symlinks` flag, which seems very relevant to us and how we handle symlinks.

When looking to enable this, I noticed that we lacked e2e tests for symlinks. I added a few tests, but found lots of other bugs...

- I ran into https://github.com/vercel/next.js/discussions/77463#discussioncomment-12847522, which I documented, but am not fixing, because it's too far out of scope.
- I ran into a bug with realpath, which is fixed here.
2025-04-16 10:00:18 +02:00
Sebastian "Sebbie" Silbermann c334056eeb [dev-overlay] Add dedicated label for recoverable errors (#78186) 2025-04-16 09:49:35 +02:00
Sebastian "Sebbie" Silbermann d6f9e080d7 [dev-overlay] Stop appending wrong Owner Stacks to SSR-only shell errors (#77302) 2025-04-15 20:58:26 +02:00
Sebastian "Sebbie" Silbermann 96bfee2c81 [dev-overlay] Stop squashing hydration related errors in App Router (#78140) 2025-04-15 09:56:36 +02:00
Sebastian "Sebbie" Silbermann 86fef73f3f [dev-overlay] Stop stashing React error details on error instances (#77975) 2025-04-14 09:42:43 +00:00
Sebastian "Sebbie" Silbermann 7a134ec8eb [test] Stop asserting on internal stackframes when features are working as intended (#78015) 2025-04-10 10:19:48 +00:00
Sebastian "Sebbie" Silbermann b9d65b8afe [test] Assert on all errors in Redbox matchers (#77907) 2025-04-10 10:00:42 +02:00
Tobias Koppers 664110c188 Turbopack: read asset entries strongly consistent (#77974)
### What?

Avoid eventual consistent results influencing the map state.
2025-04-09 18:38:57 +02:00
Jiachi Liu 45e8a6fcf0 [test] consolidate missing tag dev test (#77896)
This test is flaky in headless mode but passing in browser mode. It was
timeout on checking the toast. Adding an assertion for it seems resolve
the issue
2025-04-07 17:21:34 +02:00
Tim Neutkens 6e51845ac4 Rename process.env.TURBOPACK to process.env.IS_TURBOPACK_TEST for tests (#77892)
Preparation for removing `process.env.TURBOPACK` being added to
Turbopack tests. That way we can properly test `next start` without
`process.env.TURBOPACK` being set.

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

-->
2025-04-07 14:07:55 +02:00
Hendrik Liebau ce5206fa13 [dynamicIO] Fix dev warmup (#77829)
When `dynamicIO` is enabled, we're triggering a warmup request in dev mode. This ensures that replayed logs are associated with the correct environment (`Prerender` vs. `Server`), by seeding the caches before the actual render.

This PR fixes two issues with the dev warmup:
- Ensures that cache keys are identical between the warmup, the subsequent dynamic render, and the dynamic validation, by providing the HMR refresh hash (part of the cache key) for all dev render phases.
- Ensures that stale cache entries are discarded during the warmup, by providing the implicit tags also during the warmup (and the dynamic validation).
2025-04-04 22:52:14 +02:00
Hendrik Liebau d71da7706f Ignore an existing HMR refresh hash cookie with next start (#77714)
This is a follow-up fix for #75474.

When switching from `next dev` to `next start` locally, a user might
have an existing HMR refresh hash session cookie.

We need to make sure that the hash value is excluded from any `"use
cache"` cache keys, when running with `next start`. Otherwise, the cache
keys will be different when prerendering vs. handling a dynamic request,
e.g. when executing a server action.

In production, we now also omit the serialized `"$undefined"` value for
the HMR refresh hash from the cache keys to keep them shorter.
2025-04-03 19:59:39 +02:00
Andrew Clark 5195704e96 Track navigation timestamp on CacheNode (#77251)
Adds a field `navigatedAt` to the CacheNode type. It represents the
timestamp of the navigation that last updated the CacheNode's data.

This will be used to implement the `staleTimes.dynamic` configuration
option, which allows dynamic data to be stale in the UI up to the given
threshold. This first PR adds the field without changing any behavior.

Originally I was going to call this `requestedAt`, but I have
intentionally chosen not to distinguish between whether the data was
fetched from the network or from the prefetch cache. This means that
even fully static data will respect the `staleTimes.dynamic`
configuration option. In practice, this only matters if the dynamic
stale time is longer than the static one, although usually static stale
times will be larger anyway.
2025-03-31 23:22:46 +00:00
Tim Neutkens 8040cf8728 Turbopack build: Fix urlencoding test (#77622)
### What?
- Added additional debug logging for `customRoutes`,
`publicFolderItems`, and `nextStaticFolderItems` in the filesystem
router utils
- Improved the dynamic route interpolation test to check all script
sources instead of just the first matching one
- Fixed the Turbopack build test manifest to correctly mark the dynamic
route interpolation test as passing
- Updated the `to_string()` implementation in `ServerFileSystem` to use
a hyphenated format so that it behaves the same between urlencoded and
urldecoded.

### Why?

This PR improves debugging capabilities for the filesystem router and
fixes the dynamic route interpolation test to be more robust by checking
all script sources rather than just the first one that matches certain
criteria. The test now properly verifies that both encoded and decoded
paths work correctly.

### How?
- Added debug statements for additional route-related variables
- Refactored the test to collect all script sources and verify each one
works with both encoded and decoded paths
- Updated the Turbopack test manifest to reflect the fixed test
- Changed the server filesystem string representation to use hyphens
instead of spaces
2025-03-31 10:40:14 +02:00
Sebastian "Sebbie" Silbermann 855670e836 [dev-overlay] Remove "Unhandled Runtime Error" label (#77484) 2025-03-25 14:10:35 -07:00
Andrew Clark f6faf575bb Remove unnecessary indirections around dispatch-related methods (#77423)
Best to review commit by commit.

The App Router's state lives outside of React, so we don't need to pass
the dispatch method around via props/context. We can import it directly
into each module that needs it.

We have to be a bit clever and assign the dispatch method to a global
variable on initialization. This is more complicated than it should be
because of a known issue that requires us to decode Flight streams
during the render phase.

Ideally, we would store the action queue and dispatch method entirely
outside of React and pass the state into React as a prop using
`root.render`; conceptually, this is how we're modeling it despite the
weird implementation details.

(We were already using this approach in several places, so it's not new
to this PR; I'm just explaining it here for context.)

The first commit moves dispatch to a global. The rest of the PR cleans
up indirections that can be removed by importing and calling the
dispatch method directly.
2025-03-24 12:41:09 -04:00
Jiachi Liu 69776cc3e3 [dev-overlay] remove special handling for missing tag error (#77147)
### What

We had a few existing hacks for the missing html tag errors, we used a
lot of tricks and components to deal with it specifically. It was quite
a pain to handle on specific error across the entire codebase. This PR
leverage the existing SSR error template we sent through the rendering.
We now inject a open `<html>` tag to intercept the HTML. And then it
will be consumed as a SSR error. We added one more thing that we'll open
the error overlay automatically by default. It doesn't have to be build
error since the display was not ideal.

Now it's just one of the normal error, such like it can show the version
indicator as well. Except we had a little bit logic to make it pop up by
default.

The idea is to insert a piece of errored html like what we expect for
erroring rendered html. So it inserts a new start point of the html, and
then React will hydrate it with the error template.

```html
<!-- layout / page content -->
<meta .. />
<script .. />

<!-- we insert a html for missing tag error -->
<html id="__next_error__">
  <template data-next-error-message=".." ..></template>

<!-- next.js always render close tag -->
</body>
</html>
```


| After | Before |
|:-- |:--|
| <img width="1048" alt="image"
src="https://github.com/user-attachments/assets/713812cf-50cd-4b14-8906-44ed3795ef12"
/> | <img width="1020" alt="image"
src="https://github.com/user-attachments/assets/ac7614d9-da3b-48d1-bab1-c97355c27963"
/> |
2025-03-17 17:16:34 +01:00
Sebastian "Sebbie" Silbermann 7e7ddeb1a4 [dev-overlay] Stop grouping callstack frames into ignored vs. not ignored (#76861) 2025-03-07 11:09:47 +01:00
rauno 0704818681 [dev-overlay] Ignore animations on page load (#76834)
The current animation strategy for our Dev Tools surface does not work. 



https://github.com/user-attachments/assets/a0ca5459-9d5a-4d90-af00-b071d43581e0

On page load, several animations can be observed:
- Width growth from `0` → `auto`
- Issue count translates and fades, along with the plural `s` suffix
- A subtle scale bounce effect plays

All these animations are state transitions, and thus we should ignore
them completely on page load or on high-frequency updates where
animating is undesirable, e.g. sometimes `issueCount` will receive
updates faster than the animation can run.

This PR implements checks to guard the animations from being executed on
page load, _and only_ during state transitions.

To review, it is worth checking out the
[/animation-test](https://github.com/vercel/next.js/blob/a6e6fe635b712020d4ea2d027040d838eb5941c6/test/development/app-dir/hydration-error-count/app/animation-test/page.tsx)
fixture I've set up in this PR.

After these changes, the experience is as follows—no animations on page
load, but only on subsequent low-frequency updates (count change, or
collapse of the surface):



https://github.com/user-attachments/assets/7b2d5e0d-64ec-4165-b5e2-85489bd00a2c



_Note: I am not using Storybook for a page load reference, the apps
under `test/development/app-dir/*` are more reliable._
2025-03-05 06:27:52 -08:00
Sebastian "Sebbie" Silbermann df77469085 [test] Use new Redbox matchers in server-navigation-error (#76787) 2025-03-04 11:50:26 +01:00
Sebastian "Sebbie" Silbermann 92b18a95ee [test] Use new Redbox matchers in app/ hook-functuon-names (#76785) 2025-03-04 11:30:14 +01:00
Sebastian "Sebbie" Silbermann 235da189ca [test] Use new Redbox matchers in app/ owner-stack-invalid-element-type (#76786) 2025-03-04 11:30:08 +01:00
Sebastian "Sebbie" Silbermann 7bac0c49e5 [test] Use new Redbox matchers in app/ dynamic-error-trace (#76783) 2025-03-04 11:01:08 +01:00
Sebastian "Sebbie" Silbermann dbb19c5514 [test] Remove describeVariants helper (#76631) 2025-03-03 11:34:32 +01:00
Zack Tanner 56fe93b144 [dev-overlay]: add preference panel (#76522)
Adds user preferences for:

- Toggling theme (localstorage)
- Position (localstorage)
- Hiding the overlay (existing dev session heuristic)



https://github.com/user-attachments/assets/0f08ce66-4107-4751-80d3-a42d3315966a


![CleanShot 2025-02-25 at 17 59
11@2x](https://github.com/user-attachments/assets/e65fdfb0-23b3-4c47-b8af-f55dd60e7b95)

![CleanShot 2025-02-25 at 17 59
15@2x](https://github.com/user-attachments/assets/86d33590-18f7-44f6-acd2-9639c098476a)
2025-02-25 19:26:47 -08:00
Jiwon Choi 1c9e8af8bb [dev-overlay] hide dev indicator for server session or 1 day (#76430)
### Why?

When users want to hide the dev indicator, they might be frustrated if
it reappears every reload. Hence, make a default to hide it for the
current server session or a day.

Closes NDX-890

---------

Co-authored-by: Zack Tanner <1939140+ztanner@users.noreply.github.com>
2025-02-25 13:51:54 -08:00
Zack Tanner e071b839e4 [dev-overlay]: wire up ISR status for pages router (#76458)
The static indicator was added in the new dev overlay but wasn't hooked up to pages router. This wires that up so they're properly marked static/dynamic. 

Closes NDX-897
2025-02-25 12:05:45 -08:00
Vercel Release Bot 35eb671e0e Upgrade React from 25677265-20250224 to 22e39ea7-20250225 (#76481)
Co-authored-by: Sebastian Sebbie Silbermann <sebastian.silbermann@vercel.com>
2025-02-25 15:05:56 +01:00
Sebastian "Sebbie" Silbermann 86aef9d9bc Only log unrecoverable SSR shell errors once (#76484) 2025-02-25 14:45:10 +01:00