Skip to content

Commit 0ba4d7b

Browse files
authored
DevTools: Inline references to fiber flags (#26542)
We shouldn't be referencing internal fields like fiber's `flag` directly of DevTools. It's an implementation detail. However, over the years a few of these have snuck in. Because of how DevTools is currently shipped, where it's expected to be backwards compatible with older versions of React, this prevents us from refactoring those fields inside the reconciler. The plan we have to address this is to fix how DevTools is shipped: DevTools will be released in lockstep with each version of React. Until then, though, I need a temporary solution because it's blocking a feature I'm working on. So in meantime, I'm going to have to fork the DevTool's code based on the React version, like we already do with the fiber TypeOfWork enum. As a first step, I've inlined all the references to fiber flags into the specific call sites where they are used. Eventually we'll import these functions from the reconciler so they stay in sync, rather than maintaining duplicate copies of the logic.
1 parent da94e8b commit 0ba4d7b

File tree

2 files changed

+19
-30
lines changed

2 files changed

+19
-30
lines changed

packages/react-devtools-shared/src/backend/ReactFiberFlags.js

Lines changed: 0 additions & 17 deletions
This file was deleted.

packages/react-devtools-shared/src/backend/renderer.js

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,6 @@ import {
8888
MEMO_SYMBOL_STRING,
8989
SERVER_CONTEXT_SYMBOL_STRING,
9090
} from './ReactSymbols';
91-
import {
92-
DidCapture,
93-
NoFlags,
94-
PerformedWork,
95-
Placement,
96-
Hydrating,
97-
} from './ReactFiberFlags';
9891
import {format} from './utils';
9992
import {
10093
enableProfilerChangedHookIndices,
@@ -1555,7 +1548,10 @@ export function attach(
15551548
case ForwardRef:
15561549
// For types that execute user code, we check PerformedWork effect.
15571550
// We don't reflect bailouts (either referential or sCU) in DevTools.
1558-
// eslint-disable-next-line no-bitwise
1551+
// TODO: This flag is a leaked implementation detail. Once we start
1552+
// releasing DevTools in lockstep with React, we should import a
1553+
// function from the reconciler instead.
1554+
const PerformedWork = 0b000000000000000000000000001;
15591555
return (getFiberFlags(nextFiber) & PerformedWork) === PerformedWork;
15601556
// Note: ContextConsumer only gets PerformedWork effect in 16.3.3+
15611557
// so it won't get highlighted with React 16.3.0 to 16.3.2.
@@ -2843,7 +2839,12 @@ export function attach(
28432839
let nextNode: Fiber = node;
28442840
do {
28452841
node = nextNode;
2846-
if ((node.flags & (Placement | Hydrating)) !== NoFlags) {
2842+
// TODO: This function, and these flags, are a leaked implementation
2843+
// detail. Once we start releasing DevTools in lockstep with React, we
2844+
// should import a function from the reconciler instead.
2845+
const Placement = 0b000000000000000000000000010;
2846+
const Hydrating = 0b000000000000001000000000000;
2847+
if ((node.flags & (Placement | Hydrating)) !== 0) {
28472848
// This is an insertion or in-progress hydration. The nearest possible
28482849
// mounted fiber is the parent but we need to continue to figure out
28492850
// if that one is still mounted.
@@ -3300,16 +3301,21 @@ export function attach(
33003301
const errors = fiberIDToErrorsMap.get(id) || new Map();
33013302
const warnings = fiberIDToWarningsMap.get(id) || new Map();
33023303

3303-
const isErrored =
3304-
(fiber.flags & DidCapture) !== NoFlags ||
3305-
forceErrorForFiberIDs.get(id) === true;
3306-
3304+
let isErrored = false;
33073305
let targetErrorBoundaryID;
33083306
if (isErrorBoundary(fiber)) {
33093307
// if the current inspected element is an error boundary,
33103308
// either that we want to use it to toggle off error state
33113309
// or that we allow to force error state on it if it's within another
33123310
// error boundary
3311+
//
3312+
// TODO: This flag is a leaked implementation detail. Once we start
3313+
// releasing DevTools in lockstep with React, we should import a function
3314+
// from the reconciler instead.
3315+
const DidCapture = 0b000000000000000000010000000;
3316+
isErrored =
3317+
(fiber.flags & DidCapture) !== 0 ||
3318+
forceErrorForFiberIDs.get(id) === true;
33133319
targetErrorBoundaryID = isErrored ? id : getNearestErrorBoundaryID(fiber);
33143320
} else {
33153321
targetErrorBoundaryID = getNearestErrorBoundaryID(fiber);

0 commit comments

Comments
 (0)