From b158439a5bfac90289e63cd51e8064c455bea27c Mon Sep 17 00:00:00 2001 From: Ruslan Lesiutin Date: Wed, 15 Jan 2025 14:32:33 +0000 Subject: [PATCH] chore[DevTools]: don't use batchedUpdate (#32074) It is no-op for concurrent mode now and React DevTools is using experimental version of React: https://github.com/facebook/react/blob/886c5ad936428f168e50e077bd37fe9472ff8d3e/packages/react-dom/src/shared/ReactDOM.js#L51-L54 https://github.com/facebook/react/blob/540efebcc34357c98412a96805bfd9244d6aa678/packages/react-reconciler/src/ReactFiberWorkLoop.js#L1646-L1651 --- .../NativeStyleEditor/StyleEditor.js | 13 ++-- .../Components/NativeStyleEditor/context.js | 7 +-- .../views/Profiler/ProfilerContext.js | 60 +++++++++---------- .../views/UnsupportedVersionDialog.js | 15 ++--- 4 files changed, 39 insertions(+), 56 deletions(-) diff --git a/packages/react-devtools-shared/src/devtools/views/Components/NativeStyleEditor/StyleEditor.js b/packages/react-devtools-shared/src/devtools/views/Components/NativeStyleEditor/StyleEditor.js index 8967ea68c913f..47c8a0aaa8322 100644 --- a/packages/react-devtools-shared/src/devtools/views/Components/NativeStyleEditor/StyleEditor.js +++ b/packages/react-devtools-shared/src/devtools/views/Components/NativeStyleEditor/StyleEditor.js @@ -9,7 +9,6 @@ import * as React from 'react'; import {useContext, useMemo, useRef, useState} from 'react'; -import {unstable_batchedUpdates as batchedUpdates} from 'react-dom'; import {copy} from 'clipboard-js'; import { BridgeContext, @@ -178,10 +177,8 @@ function Row({ validAttributes === null || validAttributes.indexOf(newAttribute) >= 0; - batchedUpdates(() => { - setLocalAttribute(newAttribute); - setIsAttributeValid(isValid); - }); + setLocalAttribute(newAttribute); + setIsAttributeValid(isValid); }; // $FlowFixMe[missing-local-annot] @@ -192,10 +189,8 @@ function Row({ isValid = true; } catch (error) {} - batchedUpdates(() => { - setLocalValue(newValue); - setIsValueValid(isValid); - }); + setLocalValue(newValue); + setIsValueValid(isValid); }; const resetAttribute = () => { diff --git a/packages/react-devtools-shared/src/devtools/views/Components/NativeStyleEditor/context.js b/packages/react-devtools-shared/src/devtools/views/Components/NativeStyleEditor/context.js index 7170864ab35fe..85905666cb33a 100644 --- a/packages/react-devtools-shared/src/devtools/views/Components/NativeStyleEditor/context.js +++ b/packages/react-devtools-shared/src/devtools/views/Components/NativeStyleEditor/context.js @@ -18,7 +18,6 @@ import { useMemo, useState, } from 'react'; -import {unstable_batchedUpdates as batchedUpdates} from 'react-dom'; import {createResource} from 'react-devtools-shared/src/devtools/cache'; import { BridgeContext, @@ -120,10 +119,8 @@ function NativeStyleContextController({children}: Props): React.Node { const request = inProgressRequests.get(element); if (request != null) { inProgressRequests.delete(element); - batchedUpdates(() => { - request.resolveFn(styleAndLayout); - setCurrentStyleAndLayout(styleAndLayout); - }); + request.resolveFn(styleAndLayout); + setCurrentStyleAndLayout(styleAndLayout); } else { resource.write(element, styleAndLayout); diff --git a/packages/react-devtools-shared/src/devtools/views/Profiler/ProfilerContext.js b/packages/react-devtools-shared/src/devtools/views/Profiler/ProfilerContext.js index 38203175136b0..a9225c3c8fef1 100644 --- a/packages/react-devtools-shared/src/devtools/views/Profiler/ProfilerContext.js +++ b/packages/react-devtools-shared/src/devtools/views/Profiler/ProfilerContext.js @@ -11,7 +11,6 @@ import type {ReactContext} from 'shared/ReactTypes'; import * as React from 'react'; import {createContext, useCallback, useContext, useMemo, useState} from 'react'; -import {unstable_batchedUpdates as batchedUpdates} from 'react-dom'; import {useLocalStorage, useSubscription} from '../hooks'; import { TreeDispatcherContext, @@ -166,31 +165,28 @@ function ProfilerContextController({children}: Props): React.Node { ); if (prevProfilingData !== profilingData) { - batchedUpdates(() => { - setPrevProfilingData(profilingData); - - const dataForRoots = - profilingData !== null ? profilingData.dataForRoots : null; - if (dataForRoots != null) { - const firstRootID = dataForRoots.keys().next().value || null; - - if (rootID === null || !dataForRoots.has(rootID)) { - let selectedElementRootID = null; - if (inspectedElementID !== null) { - selectedElementRootID = - store.getRootIDForElement(inspectedElementID); - } - if ( - selectedElementRootID !== null && - dataForRoots.has(selectedElementRootID) - ) { - setRootIDAndClearFiber(selectedElementRootID); - } else { - setRootIDAndClearFiber(firstRootID); - } + setPrevProfilingData(profilingData); + + const dataForRoots = + profilingData !== null ? profilingData.dataForRoots : null; + if (dataForRoots != null) { + const firstRootID = dataForRoots.keys().next().value || null; + + if (rootID === null || !dataForRoots.has(rootID)) { + let selectedElementRootID = null; + if (inspectedElementID !== null) { + selectedElementRootID = store.getRootIDForElement(inspectedElementID); + } + if ( + selectedElementRootID !== null && + dataForRoots.has(selectedElementRootID) + ) { + setRootIDAndClearFiber(selectedElementRootID); + } else { + setRootIDAndClearFiber(firstRootID); } } - }); + } } const [isCommitFilterEnabled, setIsCommitFilterEnabled] = @@ -229,15 +225,13 @@ function ProfilerContextController({children}: Props): React.Node { ); if (isProfiling) { - batchedUpdates(() => { - if (selectedCommitIndex !== null) { - selectCommitIndex(null); - } - if (selectedFiberID !== null) { - selectFiberID(null); - selectFiberName(null); - } - }); + if (selectedCommitIndex !== null) { + selectCommitIndex(null); + } + if (selectedFiberID !== null) { + selectFiberID(null); + selectFiberName(null); + } } const value = useMemo( diff --git a/packages/react-devtools-shared/src/devtools/views/UnsupportedVersionDialog.js b/packages/react-devtools-shared/src/devtools/views/UnsupportedVersionDialog.js index 7f2421893003c..717019df431a1 100644 --- a/packages/react-devtools-shared/src/devtools/views/UnsupportedVersionDialog.js +++ b/packages/react-devtools-shared/src/devtools/views/UnsupportedVersionDialog.js @@ -9,7 +9,6 @@ import * as React from 'react'; import {Fragment, useContext, useEffect, useState} from 'react'; -import {unstable_batchedUpdates as batchedUpdates} from 'react-dom'; import {ModalDialogContext} from './ModalDialog'; import {StoreContext} from './context'; import {UNSUPPORTED_VERSION_URL} from '../constants'; @@ -26,14 +25,12 @@ export default function UnsupportedVersionDialog(_: {}): null { useEffect(() => { if (state === 'dialog-not-shown') { const showDialog = () => { - batchedUpdates(() => { - setState('show-dialog'); - dispatch({ - canBeDismissed: true, - id: 'UnsupportedVersionDialog', - type: 'SHOW', - content: , - }); + setState('show-dialog'); + dispatch({ + canBeDismissed: true, + id: 'UnsupportedVersionDialog', + type: 'SHOW', + content: , }); };