Commit Graph
46 Commits
Author SHA1 Message Date
Andrew ClarkandGitHub 723ac64ce7 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 VaughnandGitHub 8d41a28842 Scheduling Profiler does not warn about long transitions (#22614) 2021-10-21 15:16:26 -04:00
Brian VaughnandGitHub bad2318c4a 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 VaughnandGitHub b2dac7d39b 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
Andrew ClarkandGitHub d026357db3 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
Brian VaughnandGitHub 8dc1d44765 Scheduling Profiler: Show Suspense resource .displayName (#22451) 2021-09-28 11:29:33 -04:00
Brian VaughnandGitHub c9cf7d4b5f Scheduling Profiler marks should include thrown Errors (#22419) 2021-09-24 12:56:27 -04:00
BIKI DASandGitHub f2726b65ac VerticalScrollView -> fixed typos (#22341) 2021-09-17 09:05:09 -04:00
Ikko AshimineandGitHub 93a9933f6f Scheduling profiler: Fix typo in View.js (#22337) 2021-09-17 09:04:51 -04:00
7aebc1e77d add more detailed error handling if profiling data does not have any React marks (#22157)
Co-authored-by: Brian Vaughn <[email protected]>
2021-08-23 11:01:00 -04:00
Konstantin PopovandGitHub f1701f0e02 Fix typo in preprocessData.js (#22150)
Fix typo:

SUSPEND_DURING_UPATE  ->  SUSPEND_DURING_UPDATE
2021-08-22 13:37:36 -04:00
Brian VaughnandGitHub d47143cf1a 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 VaughnandGitHub b54e67dc6c Scheduling Profiler: Add network measures (#22112) 2021-08-18 12:17:59 -04:00
Brian VaughnandGitHub c709be51d0 Scheduling profiler: Canvas views clip by default (#22100) 2021-08-16 13:20:07 -04:00
Tommy GroshongandGitHub b435f8d421 Typo: 'occured' -> 'occurred' in comment (#22094) 2021-08-15 17:25:22 -04:00
Brian VaughnandGitHub 07c1004733 Scheduling Profiler: Inline snapshots (#22091) 2021-08-14 11:10:36 -04:00
Brian VaughnandGitHub ba7922eb0d [DevTools] Add screenshots to Scheduling Profiler (#22088) 2021-08-13 17:14:29 -04:00
690f0f8d31 DevTools: Scheduling profiler: Add vertical scroll bar (#22005)
Co-authored-by: E-Liang Tan <[email protected]>
2021-08-11 14:19:45 -04:00
Brian VaughnandGitHub 43cd906694 Scheduling Profiler: Misc UX and performance improvements (#22043) 2021-08-09 17:11:33 -04:00
Brian Vaughn f075c6759f Scheduling Profiler: Renamed a misnamed variable 2021-08-06 15:03:35 -04:00
Brian VaughnandGitHub 9b26242921 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 VaughnandGitHub 104cd23817 Scheduling profiler: Added lane labels and durations to React measures (#22029) 2021-08-05 13:50:39 -04:00
Brian VaughnandGitHub abcc0fc26e DevTools scheduling profiler: Add React component measures (#22013) 2021-08-03 13:03:29 -04:00
Brian VaughnandGitHub c6ec6b99f1 DevTools: Scheduling profiler (#22006) 2021-08-02 14:30:43 -04:00
40d345be50 Devtools: Refactor imperative theme code (#21950)
Co-authored-by: Brian Vaughn <[email protected]>
2021-08-02 11:20:04 -04:00
Brian VaughnandGitHub 6c5dd58d02 Scheduling profiler UX changes (#21990) 2021-08-02 09:23:48 -04:00
Brian VaughnandGitHub 2daf8df086 Display warnings in tooltips for native events that render sync updates (#21975) 2021-07-27 17:22:44 -04:00
Brian VaughnandGitHub 7e7b85c8bb Scheduling profiler: UX tweaks (#21971) 2021-07-27 14:34:05 -04:00
Brian VaughnandGitHub c65c6904ce Sceduling profiler: Added custom view cursors (#21970) 2021-07-27 12:23:01 -04:00
Brian VaughnandGitHub 146ac21caf 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 VaughnandGitHub 30af515939 [DevTools] Add native events to the scheduling profiler (#21947) 2021-07-26 10:36:16 -04:00
Brian Vaughn 313015fa15 Removed an accidental console.log from DevTools source code 2021-07-22 16:11:37 -04:00
Brian VaughnandGitHub ff12ccb0e2 [DRAFT] Import scheduling profiler into DevTools Profiler (#21897) 2021-07-22 13:58:57 -04:00
Brian VaughnandGitHub 78f9773c62 Updated scripts and config to replace "master" with "main" branch (#21768) 2021-06-29 14:26:24 -04:00
Brian VaughnandGitHub b86ad519ba 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 ClarkandGitHub 78b51e97c2 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
RickyandGitHub e69a6516b3 Delete SyncBatchedLane (#21061)
* Delete SyncBatchedLane

* Go back to 31 lanes
2021-03-24 15:04:19 -04:00
Andrew ClarkandGitHub dbd8ac4a0b 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
RickyandGitHub 9205ea2804 Fix react-devtools-scheduling-profiler tests on main (#20885) 2021-02-25 19:10:25 -05:00
Brian VaughnandGitHub ba7f5ce1b2 Add Lane labels to scheduling profiler marks (#20808)
This commit changes scheduling profiler marks from a format like '--schedule-render-1' to '--schedule-render-1-Sync' (where 1 is the numeric value of the Sync lane). This will enable the profiler itself to show more meaningful labels for updates and render work.

The commit also refactors and adds additional tests for the scheduling profiler package.

It also updates the preprocessor to 'support' instant events. These are no-ops for us, but adding recognition of the event type will prevent profiles imported from e.g. Chrome Canary from throwing with an 'unrecognized event' error. (This will resolve issue #20767.)
2021-02-23 11:31:29 -05:00
E-Liang TanandGitHub 18f5522989 Scheduling Profiler: Move preprocessing to web worker and add loading indicator (#19759)
* Move preprocessData into a web worker
* Add UI feedback for loading/import error states
* Terminate worker when done handling profile
* Add display density CSS variables
2020-09-04 10:57:32 -04:00
e388fe3fd8 Scheduling Profiler: Redesign with DevTools styling (#19707)
Co-authored-by: Brian Vaughn <[email protected]>
2020-09-03 12:08:40 -04:00
E-Liang TanandGitHub 73a1268be7 Scheduling Profiler: Extract and test scroll state from horizontal pan and zoom view (#19682)
* Extract reusable scroll logic from HorizontalPanAndZoomView

* Change VerticalScrollView to use scrollState

* Clarify test name
2020-09-03 10:27:35 -04:00
b3a8666a23 Tweaked landing page styles (#19665)
* Tweaked landing page styles

* Update GitHub link

Co-authored-by: E-Liang Tan <[email protected]>
2020-08-21 14:06:01 -04:00
Brian VaughnandGitHub 921d63fe74 Visually distinguish user timing marks from React events (#19663) 2020-08-20 14:43:40 -04:00
7d0dee6981 Import React Concurrent Mode Profiler (#19634)
Co-authored-by: Brian Vaughn <[email protected]>
Co-authored-by: Kartik Choudhary <[email protected]>
2020-08-20 14:06:28 -04:00