Remove DevTools dependency on Scheduler runWithPriority (#20967)
Brian Vaughn committed
Mar 10, 2021 at 08:52 UTC
ec372faefedd1932f45b2135122ad4bb306f2c7c
3 files changed
+5
-66
packages/react-devtools-shared/src/devtools/views/Components/TreeContext.js
+5
-10
@@ -34,12 +34,8 @@ import {
34
useMemo,
35
useReducer,
36
useRef,
37
+ unstable_startTransition as startTransition,
38
} from 'react';
38
-import {
39
- unstable_next as next,
40
- unstable_runWithPriority as runWithPriority,
41
- unstable_UserBlockingPriority as UserBlockingPriority,
42
-} from 'scheduler';
39
import {createRegExp} from '../utils';
40
import {BridgeContext, StoreContext} from '../context';
41
import Store from '../../store';
@@ -923,11 +919,10 @@ function TreeContextController({
919
920
const dispatchWrapper = useCallback(
921
(action: Action) => {
926
- // Run the first update at "user-blocking" priority in case dispatch is called from a non-React event.
927
- // In this case, the current (and "next") priorities would both be "normal",
928
- // and suspense would potentially block both updates.
929
- runWithPriority(UserBlockingPriority, () => dispatch(action));
930
- next(() => dispatch({type: 'UPDATE_INSPECTED_ELEMENT_ID'}));
922
+ dispatch(action);
923
+ startTransition(() => {
924
+ dispatch({type: 'UPDATE_INSPECTED_ELEMENT_ID'});
925
+ });
926
},
927
[dispatch],
928
);
packages/react-devtools-shell/src/app/PriorityLevels/index.js
deleted
-54
@@ -1,54 +0,0 @@
1
-/**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- * @flow
8
- */
9
-
10
-import * as React from 'react';
11
-import {Fragment, useCallback, useState} from 'react';
12
-import {
13
- unstable_IdlePriority as IdlePriority,
14
- unstable_LowPriority as LowPriority,
15
- unstable_runWithPriority as runWithPriority,
16
-} from 'scheduler';
17
-
18
-export default function PriorityLevels() {
19
- const [defaultPriority, setDefaultPriority] = useState<boolean>(false);
20
- const [idlePriority, setIdlePriority] = useState<boolean>(false);
21
- const [normalPriority, setLowPriority] = useState<boolean>(false);
22
-
23
- const resetSequence = useCallback(() => {
24
- setDefaultPriority(false);
25
- setLowPriority(false);
26
- setIdlePriority(false);
27
- }, []);
28
-
29
- const startSequence = useCallback(() => {
30
- setDefaultPriority(true);
31
- runWithPriority(LowPriority, () => setLowPriority(true));
32
- runWithPriority(IdlePriority, () => setIdlePriority(true));
33
- }, []);
34
-
35
- const labels = [];
36
- if (defaultPriority) {
37
- labels.push('(default priority)');
38
- }
39
- if (normalPriority) {
40
- labels.push('Low Priority');
41
- }
42
- if (idlePriority) {
43
- labels.push('Idle Priority');
44
- }
45
-
46
- return (
47
- <Fragment>
48
- <h1>Priority Levels</h1>
49
- <button onClick={resetSequence}>Reset</button>
50
- <button onClick={startSequence}>Start sequence</button>
51
- <span>{labels.join(', ')}</span>
52
- </Fragment>
53
- );
54
-}
packages/react-devtools-shell/src/app/index.js
-2
@@ -15,7 +15,6 @@ import Hydration from './Hydration';
15
import InlineWarnings from './InlineWarnings';
16
import InspectableElements from './InspectableElements';
17
import InteractionTracing from './InteractionTracing';
18
-import PriorityLevels from './PriorityLevels';
18
import ReactNativeWeb from './ReactNativeWeb';
19
import ToDoList from './ToDoList';
20
import Toggle from './Toggle';
@@ -55,7 +54,6 @@ function mountTestApp() {
54
mountHelper(ElementTypes);
55
mountHelper(EditableProps);
56
mountHelper(InlineWarnings);
58
- mountHelper(PriorityLevels);
57
mountHelper(ReactNativeWeb);
58
mountHelper(Toggle);
59
mountHelper(SuspenseTree);