Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DevTools: Don't fallback to nearest host descendants when tracing updates #32475

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions packages/react-devtools-shared/src/backend/fiber/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3419,18 +3419,6 @@ export function attach(
// I.e. we just restore them by undoing what we did above.
fiberInstance.firstChild = remainingReconcilingChildren;
remainingReconcilingChildren = null;

if (traceUpdatesEnabled) {
// If we're tracing updates and we've bailed out before reaching a host node,
// we should fall back to recursively marking the nearest host descendants for highlight.
if (traceNearestHostComponentUpdate) {
const hostInstances =
findAllCurrentHostInstances(fiberInstance);
hostInstances.forEach(hostInstance => {
traceUpdatesForNodes.add(hostInstance);
});
}
}
} else {
// If this fiber is filtered there might be changes to this set elsewhere so we have
// to visit each child to place it back in the set. We let the child bail out instead.
Expand Down
46 changes: 46 additions & 0 deletions packages/react-devtools-shell/src/app/TraceUpdateRepro/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import * as React from 'react';
import {useEffect, useRef, useState} from 'react';

function ShouldReRender() {
// Used just to trigger the re-render
const [, setCount] = useState(0);

const renders = useRef(0);
renders.current += 1;

useEffect(() => {
const interval = setInterval(() => {
setCount(value => value + 1);
}, 500);
return () => clearInterval(interval);
}, [setCount]);

return <p>Should re-render count: {renders.current}x</p>;
}

function ShouldNotReRender() {
const renders = useRef(0);
renders.current += 1;
return <p>Should not re-render count: {renders.current}x</p>;
}

export default function TraceUpdateRepro() {
return (
<>
<ShouldReRender />

{/* This one isn't highlighted... */}
<ShouldNotReRender />

{/* These ones are highlighted. I wonder if there is some sort of tree depth check?*/}
<div>
<ShouldNotReRender />
</div>
<div>
<div>
<ShouldNotReRender />
</div>
</div>
</>
);
}
2 changes: 2 additions & 0 deletions packages/react-devtools-shell/src/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import Toggle from './Toggle';
import ErrorBoundaries from './ErrorBoundaries';
import PartiallyStrictApp from './PartiallyStrictApp';
import SuspenseTree from './SuspenseTree';
import TraceUpdateRepro from './TraceUpdateRepro';
import {ignoreErrors, ignoreLogs, ignoreWarnings} from './console';

import './styles.css';
Expand Down Expand Up @@ -112,6 +113,7 @@ function mountTestApp() {
mountApp(SuspenseTree);
mountApp(DeeplyNestedComponents);
mountApp(Iframe);
mountApp(TraceUpdateRepro);

if (shouldRenderLegacy) {
mountLegacyApp(PartiallyStrictApp);
Expand Down
Loading