Skip to content

Commit c54e354

Browse files
authored
[DevTools] bug fix for Hydrating fibers (#25663)
## Summary This PR is to fix a bug: an "element cannot be found" error when hydrating Server Components ### The problem <img width="1061" alt="image" src="https://user-images.githubusercontent.com/1001890/201206046-ac32a5e3-b08a-4dc2-99f4-221dad504b28.png"> To reproduce: 1. setting up a vercel next.js 13 playground locally https://github.com/vercel/app-playground 2. visit http://localhost:3000/loading 3. click "electronics" button to navigate to http://localhost:3000/loading/electronics to trigger hydrating 4. inspect one of the skeleton card UI from React DevTools extension ### The root cause & fix This bug was introduced in #22527. When syncing reconciler changes, the value of `Hydrating` was copied from another variable `Visibility` (one more zero in the binary number). To avoid this kind of issue in the future, a new file `ReactFiberFlags` is created following the same format of the one in reconciler, so that it's easier to sync the number without making mistakes. The reconciler fiber flag file is also updated to reflect which of the flags are used in devtools ## How did you test this change? I build it locally and the bug no longer exist on http://localhost:3000/loading
1 parent d1e35c7 commit c54e354

File tree

3 files changed

+28
-32
lines changed

3 files changed

+28
-32
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow
8+
*/
9+
10+
// This list of flags must be synced with the following file:
11+
// https://github.com/facebook/react/blob/main/packages/react-reconciler/src/ReactFiberFlags.js
12+
13+
export const NoFlags = /* */ 0b00000000000000000000000000;
14+
export const PerformedWork = /* */ 0b00000000000000000000000001;
15+
export const Placement = /* */ 0b00000000000000000000000010;
16+
export const DidCapture = /* */ 0b00000000000000000001000000;
17+
export const Hydrating = /* */ 0b00000000000000100000000000;

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

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,13 @@ 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';
9198
import {format} from './utils';
9299
import {
93100
enableProfilerChangedHookIndices,
@@ -135,15 +142,6 @@ type ReactPriorityLevelsType = {
135142
NoPriority: number,
136143
};
137144

138-
type ReactTypeOfSideEffectType = {
139-
DidCapture: number,
140-
NoFlags: number,
141-
PerformedWork: number,
142-
Placement: number,
143-
Incomplete: number,
144-
Hydrating: number,
145-
};
146-
147145
function getFiberFlags(fiber: Fiber): number {
148146
// The name of this field changed from "effectTag" to "flags"
149147
return fiber.flags !== undefined ? fiber.flags : (fiber: any).effectTag;
@@ -162,19 +160,9 @@ export function getInternalReactConstants(
162160
getDisplayNameForFiber: getDisplayNameForFiberType,
163161
getTypeSymbol: getTypeSymbolType,
164162
ReactPriorityLevels: ReactPriorityLevelsType,
165-
ReactTypeOfSideEffect: ReactTypeOfSideEffectType,
166163
ReactTypeOfWork: WorkTagMap,
167164
StrictModeBits: number,
168165
} {
169-
const ReactTypeOfSideEffect: ReactTypeOfSideEffectType = {
170-
DidCapture: 0b10000000,
171-
NoFlags: 0b00,
172-
PerformedWork: 0b01,
173-
Placement: 0b10,
174-
Incomplete: 0b10000000000000,
175-
Hydrating: 0b1000000000000,
176-
};
177-
178166
// **********************************************************
179167
// The section below is copied from files in React repo.
180168
// Keep it in sync, and add version guards if it changes.
@@ -562,7 +550,6 @@ export function getInternalReactConstants(
562550
getTypeSymbol,
563551
ReactPriorityLevels,
564552
ReactTypeOfWork,
565-
ReactTypeOfSideEffect,
566553
StrictModeBits,
567554
};
568555
}
@@ -595,16 +582,8 @@ export function attach(
595582
getTypeSymbol,
596583
ReactPriorityLevels,
597584
ReactTypeOfWork,
598-
ReactTypeOfSideEffect,
599585
StrictModeBits,
600586
} = getInternalReactConstants(version);
601-
const {
602-
DidCapture,
603-
Hydrating,
604-
NoFlags,
605-
PerformedWork,
606-
Placement,
607-
} = ReactTypeOfSideEffect;
608587
const {
609588
CacheComponent,
610589
ClassComponent,

packages/react-reconciler/src/ReactFiberFlags.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,22 @@ import {enableCreateEventHandleAPI} from 'shared/ReactFeatureFlags';
1111

1212
export type Flags = number;
1313

14-
// Don't change these two values. They're used by React Dev Tools.
14+
// Don't change these values. They're used by React Dev Tools.
1515
export const NoFlags = /* */ 0b00000000000000000000000000;
1616
export const PerformedWork = /* */ 0b00000000000000000000000001;
17+
export const Placement = /* */ 0b00000000000000000000000010;
18+
export const DidCapture = /* */ 0b00000000000000000001000000;
19+
export const Hydrating = /* */ 0b00000000000000100000000000;
1720

1821
// You can change the rest (and add more).
19-
export const Placement = /* */ 0b00000000000000000000000010;
2022
export const Update = /* */ 0b00000000000000000000000100;
2123
export const ChildDeletion = /* */ 0b00000000000000000000001000;
2224
export const ContentReset = /* */ 0b00000000000000000000010000;
2325
export const Callback = /* */ 0b00000000000000000000100000;
24-
export const DidCapture = /* */ 0b00000000000000000001000000;
2526
export const ForceClientRender = /* */ 0b00000000000000000010000000;
2627
export const Ref = /* */ 0b00000000000000000100000000;
2728
export const Snapshot = /* */ 0b00000000000000001000000000;
2829
export const Passive = /* */ 0b00000000000000010000000000;
29-
export const Hydrating = /* */ 0b00000000000000100000000000;
3030
export const Visibility = /* */ 0b00000000000001000000000000;
3131
export const StoreConsistency = /* */ 0b00000000000010000000000000;
3232

0 commit comments

Comments
 (0)