From ec372faefedd1932f45b2135122ad4bb306f2c7c Mon Sep 17 00:00:00 2001 From: Brian Vaughn Date: Wed, 10 Mar 2021 08:52:19 -0500 Subject: [PATCH] Remove DevTools dependency on Scheduler runWithPriority (#20967) --- .../devtools/views/Components/TreeContext.js | 15 ++---- .../src/app/PriorityLevels/index.js | 54 ------------------- .../react-devtools-shell/src/app/index.js | 2 - 3 files changed, 5 insertions(+), 66 deletions(-) delete mode 100644 packages/react-devtools-shell/src/app/PriorityLevels/index.js diff --git a/packages/react-devtools-shared/src/devtools/views/Components/TreeContext.js b/packages/react-devtools-shared/src/devtools/views/Components/TreeContext.js index a824bd493ff84..0ab6e57c4b414 100644 --- a/packages/react-devtools-shared/src/devtools/views/Components/TreeContext.js +++ b/packages/react-devtools-shared/src/devtools/views/Components/TreeContext.js @@ -34,12 +34,8 @@ import { useMemo, useReducer, useRef, + unstable_startTransition as startTransition, } from 'react'; -import { - unstable_next as next, - unstable_runWithPriority as runWithPriority, - unstable_UserBlockingPriority as UserBlockingPriority, -} from 'scheduler'; import {createRegExp} from '../utils'; import {BridgeContext, StoreContext} from '../context'; import Store from '../../store'; @@ -923,11 +919,10 @@ function TreeContextController({ const dispatchWrapper = useCallback( (action: Action) => { - // Run the first update at "user-blocking" priority in case dispatch is called from a non-React event. - // In this case, the current (and "next") priorities would both be "normal", - // and suspense would potentially block both updates. - runWithPriority(UserBlockingPriority, () => dispatch(action)); - next(() => dispatch({type: 'UPDATE_INSPECTED_ELEMENT_ID'})); + dispatch(action); + startTransition(() => { + dispatch({type: 'UPDATE_INSPECTED_ELEMENT_ID'}); + }); }, [dispatch], ); diff --git a/packages/react-devtools-shell/src/app/PriorityLevels/index.js b/packages/react-devtools-shell/src/app/PriorityLevels/index.js deleted file mode 100644 index 32858eb08a04f..0000000000000 --- a/packages/react-devtools-shell/src/app/PriorityLevels/index.js +++ /dev/null @@ -1,54 +0,0 @@ -/** - * Copyright (c) Facebook, Inc. and its affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - * - * @flow - */ - -import * as React from 'react'; -import {Fragment, useCallback, useState} from 'react'; -import { - unstable_IdlePriority as IdlePriority, - unstable_LowPriority as LowPriority, - unstable_runWithPriority as runWithPriority, -} from 'scheduler'; - -export default function PriorityLevels() { - const [defaultPriority, setDefaultPriority] = useState(false); - const [idlePriority, setIdlePriority] = useState(false); - const [normalPriority, setLowPriority] = useState(false); - - const resetSequence = useCallback(() => { - setDefaultPriority(false); - setLowPriority(false); - setIdlePriority(false); - }, []); - - const startSequence = useCallback(() => { - setDefaultPriority(true); - runWithPriority(LowPriority, () => setLowPriority(true)); - runWithPriority(IdlePriority, () => setIdlePriority(true)); - }, []); - - const labels = []; - if (defaultPriority) { - labels.push('(default priority)'); - } - if (normalPriority) { - labels.push('Low Priority'); - } - if (idlePriority) { - labels.push('Idle Priority'); - } - - return ( - -

Priority Levels

- - - {labels.join(', ')} -
- ); -} diff --git a/packages/react-devtools-shell/src/app/index.js b/packages/react-devtools-shell/src/app/index.js index b3c7b9be228c1..f5683b69a82f0 100644 --- a/packages/react-devtools-shell/src/app/index.js +++ b/packages/react-devtools-shell/src/app/index.js @@ -15,7 +15,6 @@ import Hydration from './Hydration'; import InlineWarnings from './InlineWarnings'; import InspectableElements from './InspectableElements'; import InteractionTracing from './InteractionTracing'; -import PriorityLevels from './PriorityLevels'; import ReactNativeWeb from './ReactNativeWeb'; import ToDoList from './ToDoList'; import Toggle from './Toggle'; @@ -55,7 +54,6 @@ function mountTestApp() { mountHelper(ElementTypes); mountHelper(EditableProps); mountHelper(InlineWarnings); - mountHelper(PriorityLevels); mountHelper(ReactNativeWeb); mountHelper(Toggle); mountHelper(SuspenseTree);