Commit Graph
62 Commits
Author SHA1 Message Date
Andrew Clark d5b6b4b865 Expand act warning to cover all APIs that might schedule React work (#22607)
* Move isActEnvironment check to function that warns

I'm about to fork the behavior in legacy roots versus concurrent roots
even further, so I'm lifting this up so I only have to fork once.

* Lift `mode` check, too

Similar to previous commit. I only want to check this once. Not for
performance reasons, but so the logic is easier to follow.

* Expand act warning to include non-hook APIs

In a test environment, React warns if an update isn't wrapped with act
— but only if the update originates from a hook API, like useState.

We did it this way for backwards compatibility with tests that were
written before the act API was introduced. Those tests didn't require
act, anyway, because in a legacy root, all tasks are synchronous except
for `useEffect`.

However, in a concurrent root, nearly every task is asynchronous. Even
tasks that are synchronous may spawn additional asynchronous work. So
all updates need to be wrapped with act, regardless of whether they
originate from a hook, a class, a root, or any other type of component.

This commit expands the act warning to include any API that triggers
an update.

It does not currently account for renders that are caused by a Suspense
promise resolving; those are modelled slightly differently from updates.
I'll fix that in the next step.

I also removed the check for whether an update is batched. It shouldn't
matter, because even a batched update can spawn asynchronous work, which
needs to be flushed by act.

This change only affects concurrent roots. The behavior in legacy roots
is the same.

* Expand act warning to include Suspense resolutions

For the same reason we warn when an update is not wrapped with act,
we should warn if a Suspense promise resolution is not wrapped with act.
Both "pings" and "retries".

Legacy root behavior is unchanged.
2021-10-21 15:31:26 -07:00
Brian Vaughn bfb40225b5 Scheduling Profiler does not warn about long transitions (#22614) 2021-10-21 15:16:26 -04:00
Brian Vaughn 0e8a5aff3d Scheduling Profiler: Add marks for component effects (mount and unmount) (#22578)
DevTools (and its profilers) should not require users to be familiar with React internals. Although the scheduling profiler includes a CPU sample flame graph, it's there for advanced use cases and shouldn't be required to identify common performance issues.

This PR proposes adding new marks around component effects. This will enable users to identify components with slow effect create/destroy functions without requiring them to dig through the call stack. (Once #22529 lands, these new marks will also include component stacks, making them more useful still.)

For example, here's a profile with a long-running effect. Without this change, it's not clear why the effects phase takes so long. After this change, it's more clear why that the phase is longer because of a specific component.

We may consider adding similar marks around render phase hooks like useState, useReducer, useMemo. I avoided doing that in this PR because it would be a pretty pervasive change to the ReactFiberHooks file.

Note that this change should have no effect on production bundles since everything is guarded behind a profiling feature flag.

Going to tag more people than I normally would for this pR, since it touches both reconciler and DevTools packages. Feel free to ignore though if you don't have strong feelings.

Note that although this PR adds new marks to the scheduling profiler, it's done in a way that's backwards compatible for older profiles.
2021-10-21 14:41:44 -04:00
Brian Vaughn 4ba20579da Scheduling Profiler: De-emphasize React internal frames (#22588)
This commit adds code to all React bundles to explicitly register the beginning and ending of the module. This is done by creating Error objects (which capture the file name, line number, and column number) and passing them explicitly to a DevTools hook (when present).

Next, as the Scheduling Profiler logs metadata to the User Timing API, it prints these module ranges along with other metadata (like Lane values and profiler version number).

Lastly, the Scheduling Profiler UI compares stack frames to these ranges when drawing the flame graph and dims or de-emphasizes frames that fall within an internal module.

The net effect of this is that user code (and 3rd party code) stands out clearly in the flame graph while React internal modules are dimmed.

Internal module ranges are completely optional. Older profiling samples, or ones recorded without the React DevTools extension installed, will simply not dim the internal frames.
2021-10-21 14:40:41 -04:00
Juan c213030b49 React DevTools 4.20.1 -> 4.20.2 (#22605) 2021-10-20 16:00:13 -04:00
Juan b81de86332 React DevTools 4.20.0 -> 4.20.1 (#22583) 2021-10-19 10:55:39 -04:00
Andrew Clark 996da67b29 Replace global jest heuristic with IS_REACT_ACT_ENVIRONMENT (#22562)
* Remove `jest` global check in concurrent roots

In concurrent mode, instead of checking `jest`, we check the new
`IS_REACT_ACT_ENVIRONMENT` global. The default behavior is `false`.

Legacy mode behavior is unchanged.

React's own internal test suite use a custom version of `act` that works
by mocking the Scheduler — rather than the "real" act used publicly. So
we don't enable the flag in our repo.

* Warn if `act` is called in wrong environment

Adds a warning if `act` is called but `IS_REACT_ACT_ENVIRONMENT` is not
enabled. The goal is to prompt users to correctly configure their
testing environment, so that if they forget to use `act` in a different
test, we can detect and warn about.

It's expected that the environment flag will be configured by the
testing framework. For example, a Jest plugin. We will link to the
relevant documentation page, once it exists.

The warning only fires in concurrent mode. Legacy roots will keep the
existing behavior.
2021-10-18 08:59:18 -07:00
Juan e5f486b5a8 React DevTools 4.19.2 -> 4.20.2 (#22569) 2021-10-15 12:50:17 -04:00
Brian Vaughn 20ca9b565a React DevTools 4.19.1 -> 4.19.2 2021-10-08 13:51:25 -04:00
Brian Vaughn bdd6d5064d React DevTools 4.19.0 -> 4.19.1 (#22480) 2021-10-01 11:50:05 -04:00
Luna Ruan 0883c4cd3a React DevTools 4.18.0 -> 4.19.0 (#22461) 2021-09-29 12:06:13 -04:00
Brian Vaughn 9175f4d15e Scheduling Profiler: Show Suspense resource .displayName (#22451) 2021-09-28 11:29:33 -04:00
Brian Vaughn 1c73ceed5f Scheduling Profiler marks should include thrown Errors (#22419) 2021-09-24 12:56:27 -04:00
BIKI DAS b0803f255b VerticalScrollView -> fixed typos (#22341) 2021-09-17 09:05:09 -04:00
Ikko Ashimine a7da457e6b Scheduling profiler: Fix typo in View.js (#22337) 2021-09-17 09:04:51 -04:00
Luna Ruan 3385b377f7 React DevTools 4.17.0 -> 4.18.0 (#22234) 2021-09-01 13:39:36 -07:00
Brian Vaughn 582858083e React DevTools 4.16.0 -> 4.17.0 2021-08-24 11:12:42 -07:00
Byron LukandBrian Vaughn bd5bf555e1 add more detailed error handling if profiling data does not have any React marks (#22157)
Co-authored-by: Brian Vaughn <brian.david.vaughn@gmail.com>
2021-08-23 11:01:00 -04:00
Konstantin Popov f5e529176e Fix typo in preprocessData.js (#22150)
Fix typo:

SUSPEND_DURING_UPATE  ->  SUSPEND_DURING_UPDATE
2021-08-22 13:37:36 -04:00
Brian Vaughn aa25824f3e Scheduling profiler: Fix tooltip wheel event regression (#22130)
Panning horizontally via mouse wheel used to allow you to scrub over snapshot images. This was accidentally broken by a recent change. The core of the fix for this was to update `useSmartTooltip()` to remove the dependencies array so that a newly rendered tooltip is positioned even if the mouseX/mouseY coordinates don't change (as they don't when panning via wheel).

I also cleaned a couple of unrelated things up while doing this:
* Consolidated hover reset logic formerly split between `CanvasPage` and `Surface` into the `Surface` `handleInteraction()` function.
* Cleaned up redundant ref setting code in EventTooltip.
2021-08-18 19:51:34 -04:00
Brian Vaughn f51579fffe Scheduling Profiler: Add network measures (#22112) 2021-08-18 12:17:59 -04:00
Luna Ruan 152ecce117 DevTools 4.15.0 -> 4.16.0 (#22104) 2021-08-16 14:55:47 -07:00
Brian Vaughn 55d01aa0f3 Scheduling profiler: Canvas views clip by default (#22100) 2021-08-16 13:20:07 -04:00
Tommy Groshong bc4e751121 Typo: 'occured' -> 'occurred' in comment (#22094) 2021-08-15 17:25:22 -04:00
Brian Vaughn 89910635f7 Scheduling Profiler: Inline snapshots (#22091) 2021-08-14 11:10:36 -04:00
Brian Vaughn 54e170c794 [DevTools] Add screenshots to Scheduling Profiler (#22088) 2021-08-13 17:14:29 -04:00
Brian Vaughn e4e8226c62 Fixed Components tree indentation bug for Chrome extension (#22083)
By upgrading react-virtualized-auto-sizer to 1.0.6

See https://github.com/bvaughn/react-virtualized-auto-sizer/pull/39
2021-08-12 20:41:56 -04:00
Juan c6f2188ed6 DevTools 4.14.0 -> 4.15.0 2021-08-11 16:47:20 -04:00
Brian Vaughn ad150533d6 Updated @reach packages to fix unmount bug (#22075) 2021-08-11 14:43:25 -04:00
Brian VaughnandE-Liang Tan 280e3f936f DevTools: Scheduling profiler: Add vertical scroll bar (#22005)
Co-authored-by: E-Liang Tan <eliang@eliangtan.com>
2021-08-11 14:19:45 -04:00
Brian Vaughn 5634ed16aa Scheduling Profiler: Misc UX and performance improvements (#22043) 2021-08-09 17:11:33 -04:00
Brian Vaughn 2edf449803 Scheduling Profiler: Renamed a misnamed variable 2021-08-06 15:03:35 -04:00
Brian Vaughn 5660c52b89 Scheduling Profiler: Improve warnings and add unit tests (#22038)
* Scheduling Profiler: Updated instructions to mentioned v18+ requirement

* Moved long-event warning to post processing

This lets us rule out non-React work or React work that started before the event and finished quickly during the event.

Also added unit tests for this warning and the various cases.

* Moved long-event warning to post processing

This lets us rule out non-React work or React work that started before the event and finished quickly during the event.

Also added unit tests for this warning and the various cases.

* Updated nested update warning text

* Udpate warning about suspending outside of a transition

Handle edge case where component suspends before the first commit (and label metadata) has been logged.

Add unit tests.

* Fixed logic error in getBatchRange() with minStartTime

* PR feedback: Combined a conditional statement
2021-08-06 14:57:52 -04:00
Brian Vaughn a8725a3e62 Scheduling profiler: Added lane labels and durations to React measures (#22029) 2021-08-05 13:50:39 -04:00
Brian Vaughn e3049bb850 DevTools scheduling profiler: Add React component measures (#22013) 2021-08-03 13:03:29 -04:00
Brian Vaughn 42251331d8 DevTools: Scheduling profiler (#22006) 2021-08-02 14:30:43 -04:00
houssemchebebandBrian Vaughn e3b76a85c5 Devtools: Refactor imperative theme code (#21950)
Co-authored-by: Brian Vaughn <bvaughn@fb.com>
2021-08-02 11:20:04 -04:00
Brian Vaughn 27bf6f9a83 Scheduling profiler UX changes (#21990) 2021-08-02 09:23:48 -04:00
Brian Vaughn cdccdbe171 Display warnings in tooltips for native events that render sync updates (#21975) 2021-07-27 17:22:44 -04:00
Brian Vaughn d95434082f Scheduling profiler: UX tweaks (#21971) 2021-07-27 14:34:05 -04:00
Brian Vaughn 87239321b0 Sceduling profiler: Added custom view cursors (#21970) 2021-07-27 12:23:01 -04:00
Brian Vaughn c21e8fccad Scheduling profiler: Improve native events UI (#21966)
Also highlight events that have synchronous updates inside of them. (We may want to relax this highlighting later to not warn about event handlers that are still fast enough.)
2021-07-26 19:30:43 -04:00
Brian Vaughn b1811ebf01 [DevTools] Add native events to the scheduling profiler (#21947) 2021-07-26 10:36:16 -04:00
Brian Vaughn c76e4dbbc1 Removed an accidental console.log from DevTools source code 2021-07-22 16:11:37 -04:00
Brian Vaughn f4161c3ec7 [DRAFT] Import scheduling profiler into DevTools Profiler (#21897) 2021-07-22 13:58:57 -04:00
Brian Vaughn d483463bc8 Updated scripts and config to replace "master" with "main" branch (#21768) 2021-06-29 14:26:24 -04:00
Brian Vaughn 2bf4805e4b Update entry point exports (#21488)
The following APIs have been added to the `react` stable entry point:
* `SuspenseList`
* `startTransition`
* `unstable_createMutableSource`
* `unstable_useMutableSource`
* `useDeferredValue`
* `useTransition`

The following APIs have been added or removed from the `react-dom` stable entry point:
* `createRoot`
* `unstable_createPortal` (removed)

The following APIs have been added to the `react-is` stable entry point:
* `SuspenseList`
* `isSuspenseList`

The following feature flags have been changed from experimental to true:
* `enableLazyElements`
* `enableSelectiveHydration`
* `enableSuspenseServerRenderer`
2021-05-12 11:28:14 -04:00
Andrew Clark 3ba5c87377 Remove Scheduler indirection (#21107)
* Bump version number

* Remove Scheduler indirection

I originally kept the React PriorityLevel and Scheduler PriorityLevel
types separate in case there was a versioning mismatch between the two
modules. However, it looks like we're going to keep the Scheduler module
private in the short to medium term, and longer term the public
interface will match postTask. So, I've removed the extra indirection
(the switch statements that convert between the two types).
2021-03-28 14:13:38 -07:00
Ricky a63f0953be Delete SyncBatchedLane (#21061)
* Delete SyncBatchedLane

* Go back to 31 lanes
2021-03-24 15:04:19 -04:00
Andrew Clark dcdf8de7e1 Remove discrete lanes and priorities (#21040)
We use SyncLane everywhere we used to use InputDiscreteLane or
InputDiscreteHydrationLane. So we can delete them now, along with their
associated lane priority levels.
2021-03-22 09:51:40 -07:00