Skip to content

Commit

Permalink
chore[DevTools]: don't use batchedUpdate (facebook#32074)
Browse files Browse the repository at this point in the history
  • Loading branch information
hoxyq authored Jan 15, 2025
1 parent 0597605 commit b158439
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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]
Expand All @@ -192,10 +189,8 @@ function Row({
isValid = true;
} catch (error) {}

batchedUpdates(() => {
setLocalValue(newValue);
setIsValueValid(isValid);
});
setLocalValue(newValue);
setIsValueValid(isValid);
};

const resetAttribute = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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] =
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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: <DialogContent />,
});
setState('show-dialog');
dispatch({
canBeDismissed: true,
id: 'UnsupportedVersionDialog',
type: 'SHOW',
content: <DialogContent />,
});
};

Expand Down

0 comments on commit b158439

Please sign in to comment.