@samitouri / QOS-React / commits / 64bc49d523

Run first setState with explicit priority in case of non-React event handlers

Brian Vaughn committed Apr 22, 2019 at 15:11 UTC 64bc49d523c05e9fb23bd7b90c0969c0fb72edd2
1 file changed +9 -2
src/devtools/views/Components/TreeContext.js
+9 -2
@@ -27,7 +27,11 @@ import React, {
27 useReducer,
28 useRef,
29 } from 'react';
30 -import { unstable_next as next } from 'scheduler';
30 +import {
31 + unstable_next as next,
32 + unstable_runWithPriority as runWithPriority,
33 + unstable_UserBlockingPriority as UserBlockingPriority,
34 +} from 'scheduler';
35 import { createRegExp } from '../utils';
36 import { BridgeContext, StoreContext } from '../context';
37 import Store from '../../store';
@@ -699,7 +703,10 @@ function TreeContextController({ children }: Props) {
703
704 const dispatchWrapper = useCallback(
705 (action: Action) => {
702 - dispatch(action);
706 + // Run the first update at "user-blocking" priority in case dispatch is called from a non-React event.
707 + // In this case, the current (and "next") priorities would both be "normal",
708 + // and suspense would potentially block both updates.
709 + runWithPriority(UserBlockingPriority, () => dispatch(action));
710 next(() => dispatch({ type: 'UPDATE_INSPECTED_ELEMENT_ID' }));
711 },
712 [dispatch]