Skip to content

Commit 87b495f

Browse files
committed
Revert "Track Owner for Server Components in DEV (#28753)"
This reverts commit e0455fe.
1 parent e0455fe commit 87b495f

20 files changed

+158
-291
lines changed

packages/react-client/src/ReactFlightClient.js

+7-18
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,6 @@ function createElement(
483483
type: mixed,
484484
key: mixed,
485485
props: mixed,
486-
owner: null | ReactComponentInfo, // DEV-only
487486
): React$Element<any> {
488487
let element: any;
489488
if (__DEV__ && enableRefAsProp) {
@@ -493,7 +492,7 @@ function createElement(
493492
type,
494493
key,
495494
props,
496-
_owner: owner,
495+
_owner: null,
497496
}: any);
498497
Object.defineProperty(element, 'ref', {
499498
enumerable: false,
@@ -510,7 +509,7 @@ function createElement(
510509
props,
511510

512511
// Record the component responsible for creating this element.
513-
_owner: owner,
512+
_owner: null,
514513
}: any);
515514
}
516515

@@ -844,12 +843,7 @@ function parseModelTuple(
844843
if (tuple[0] === REACT_ELEMENT_TYPE) {
845844
// TODO: Consider having React just directly accept these arrays as elements.
846845
// Or even change the ReactElement type to be an array.
847-
return createElement(
848-
tuple[1],
849-
tuple[2],
850-
tuple[3],
851-
__DEV__ ? (tuple: any)[4] : null,
852-
);
846+
return createElement(tuple[1], tuple[2], tuple[3]);
853847
}
854848
return value;
855849
}
@@ -1127,14 +1121,12 @@ function resolveConsoleEntry(
11271121
);
11281122
}
11291123

1130-
const payload: [string, string, null | ReactComponentInfo, string, mixed] =
1131-
parseModel(response, value);
1124+
const payload: [string, string, string, mixed] = parseModel(response, value);
11321125
const methodName = payload[0];
11331126
// TODO: Restore the fake stack before logging.
11341127
// const stackTrace = payload[1];
1135-
// const owner = payload[2];
1136-
const env = payload[3];
1137-
const args = payload.slice(4);
1128+
const env = payload[2];
1129+
const args = payload.slice(3);
11381130
printToConsole(methodName, args, env);
11391131
}
11401132

@@ -1283,10 +1275,7 @@ function processFullRow(
12831275
}
12841276
case 68 /* "D" */: {
12851277
if (__DEV__) {
1286-
const debugInfo: ReactComponentInfo | ReactAsyncInfo = parseModel(
1287-
response,
1288-
row,
1289-
);
1278+
const debugInfo = JSON.parse(row);
12901279
resolveDebugInfo(response, id, debugInfo);
12911280
return;
12921281
}

packages/react-client/src/__tests__/ReactFlight-test.js

+5-53
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ describe('ReactFlight', () => {
214214
const rootModel = await ReactNoopFlightClient.read(transport);
215215
const greeting = rootModel.greeting;
216216
expect(greeting._debugInfo).toEqual(
217-
__DEV__ ? [{name: 'Greeting', env: 'Server', owner: null}] : undefined,
217+
__DEV__ ? [{name: 'Greeting', env: 'Server'}] : undefined,
218218
);
219219
ReactNoop.render(greeting);
220220
});
@@ -241,7 +241,7 @@ describe('ReactFlight', () => {
241241
await act(async () => {
242242
const promise = ReactNoopFlightClient.read(transport);
243243
expect(promise._debugInfo).toEqual(
244-
__DEV__ ? [{name: 'Greeting', env: 'Server', owner: null}] : undefined,
244+
__DEV__ ? [{name: 'Greeting', env: 'Server'}] : undefined,
245245
);
246246
ReactNoop.render(await promise);
247247
});
@@ -2072,21 +2072,19 @@ describe('ReactFlight', () => {
20722072
await act(async () => {
20732073
const promise = ReactNoopFlightClient.read(transport);
20742074
expect(promise._debugInfo).toEqual(
2075-
__DEV__
2076-
? [{name: 'ServerComponent', env: 'Server', owner: null}]
2077-
: undefined,
2075+
__DEV__ ? [{name: 'ServerComponent', env: 'Server'}] : undefined,
20782076
);
20792077
const result = await promise;
20802078
const thirdPartyChildren = await result.props.children[1];
20812079
// We expect the debug info to be transferred from the inner stream to the outer.
20822080
expect(thirdPartyChildren[0]._debugInfo).toEqual(
20832081
__DEV__
2084-
? [{name: 'ThirdPartyComponent', env: 'third-party', owner: null}]
2082+
? [{name: 'ThirdPartyComponent', env: 'third-party'}]
20852083
: undefined,
20862084
);
20872085
expect(thirdPartyChildren[1]._debugInfo).toEqual(
20882086
__DEV__
2089-
? [{name: 'ThirdPartyLazyComponent', env: 'third-party', owner: null}]
2087+
? [{name: 'ThirdPartyLazyComponent', env: 'third-party'}]
20902088
: undefined,
20912089
);
20922090
ReactNoop.render(result);
@@ -2147,50 +2145,4 @@ describe('ReactFlight', () => {
21472145
expect(loggedFn).not.toBe(foo);
21482146
expect(loggedFn.toString()).toBe(foo.toString());
21492147
});
2150-
2151-
it('uses the server component debug info as the element owner in DEV', async () => {
2152-
function Container({children}) {
2153-
return children;
2154-
}
2155-
2156-
function Greeting({firstName}) {
2157-
// We can't use JSX here because it'll use the Client React.
2158-
return ReactServer.createElement(
2159-
Container,
2160-
null,
2161-
ReactServer.createElement('span', null, 'Hello, ', firstName),
2162-
);
2163-
}
2164-
2165-
const model = {
2166-
greeting: ReactServer.createElement(Greeting, {firstName: 'Seb'}),
2167-
};
2168-
2169-
const transport = ReactNoopFlightServer.render(model);
2170-
2171-
await act(async () => {
2172-
const rootModel = await ReactNoopFlightClient.read(transport);
2173-
const greeting = rootModel.greeting;
2174-
// We've rendered down to the span.
2175-
expect(greeting.type).toBe('span');
2176-
if (__DEV__) {
2177-
const greetInfo = {name: 'Greeting', env: 'Server', owner: null};
2178-
expect(greeting._debugInfo).toEqual([
2179-
greetInfo,
2180-
{name: 'Container', env: 'Server', owner: greetInfo},
2181-
]);
2182-
// The owner that created the span was the outer server component.
2183-
// We expect the debug info to be referentially equal to the owner.
2184-
expect(greeting._owner).toBe(greeting._debugInfo[0]);
2185-
} else {
2186-
expect(greeting._debugInfo).toBe(undefined);
2187-
expect(greeting._owner).toBe(
2188-
gate(flags => flags.disableStringRefs) ? undefined : null,
2189-
);
2190-
}
2191-
ReactNoop.render(greeting);
2192-
});
2193-
2194-
expect(ReactNoop).toMatchRenderedOutput(<span>Hello, Seb</span>);
2195-
});
21962148
});

packages/react-devtools-shared/src/__tests__/componentStacks-test.js

-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ describe('component stack', () => {
101101
{
102102
name: 'ServerComponent',
103103
env: 'Server',
104-
owner: null,
105104
},
106105
];
107106
const Parent = () => ChildPromise;

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

+17-5
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ import {
3333
import {disableLogs, reenableLogs} from './DevToolsConsolePatching';
3434

3535
let prefix;
36-
export function describeBuiltInComponentFrame(name: string): string {
36+
export function describeBuiltInComponentFrame(
37+
name: string,
38+
ownerFn: void | null | Function,
39+
): string {
3740
if (prefix === undefined) {
3841
// Extract the VM specific prefix used by each line.
3942
try {
@@ -48,7 +51,10 @@ export function describeBuiltInComponentFrame(name: string): string {
4851
}
4952

5053
export function describeDebugInfoFrame(name: string, env: ?string): string {
51-
return describeBuiltInComponentFrame(name + (env ? ' (' + env + ')' : ''));
54+
return describeBuiltInComponentFrame(
55+
name + (env ? ' (' + env + ')' : ''),
56+
null,
57+
);
5258
}
5359

5460
let reentry = false;
@@ -286,13 +292,15 @@ export function describeNativeComponentFrame(
286292

287293
export function describeClassComponentFrame(
288294
ctor: Function,
295+
ownerFn: void | null | Function,
289296
currentDispatcherRef: CurrentDispatcherRef,
290297
): string {
291298
return describeNativeComponentFrame(ctor, true, currentDispatcherRef);
292299
}
293300

294301
export function describeFunctionComponentFrame(
295302
fn: Function,
303+
ownerFn: void | null | Function,
296304
currentDispatcherRef: CurrentDispatcherRef,
297305
): string {
298306
return describeNativeComponentFrame(fn, false, currentDispatcherRef);
@@ -305,6 +313,7 @@ function shouldConstruct(Component: Function) {
305313

306314
export function describeUnknownElementTypeFrameInDEV(
307315
type: any,
316+
ownerFn: void | null | Function,
308317
currentDispatcherRef: CurrentDispatcherRef,
309318
): string {
310319
if (!__DEV__) {
@@ -321,29 +330,31 @@ export function describeUnknownElementTypeFrameInDEV(
321330
);
322331
}
323332
if (typeof type === 'string') {
324-
return describeBuiltInComponentFrame(type);
333+
return describeBuiltInComponentFrame(type, ownerFn);
325334
}
326335
switch (type) {
327336
case SUSPENSE_NUMBER:
328337
case SUSPENSE_SYMBOL_STRING:
329-
return describeBuiltInComponentFrame('Suspense');
338+
return describeBuiltInComponentFrame('Suspense', ownerFn);
330339
case SUSPENSE_LIST_NUMBER:
331340
case SUSPENSE_LIST_SYMBOL_STRING:
332-
return describeBuiltInComponentFrame('SuspenseList');
341+
return describeBuiltInComponentFrame('SuspenseList', ownerFn);
333342
}
334343
if (typeof type === 'object') {
335344
switch (type.$$typeof) {
336345
case FORWARD_REF_NUMBER:
337346
case FORWARD_REF_SYMBOL_STRING:
338347
return describeFunctionComponentFrame(
339348
type.render,
349+
ownerFn,
340350
currentDispatcherRef,
341351
);
342352
case MEMO_NUMBER:
343353
case MEMO_SYMBOL_STRING:
344354
// Memo may contain any component type so we recursively resolve it.
345355
return describeUnknownElementTypeFrameInDEV(
346356
type.type,
357+
ownerFn,
347358
currentDispatcherRef,
348359
);
349360
case LAZY_NUMBER:
@@ -355,6 +366,7 @@ export function describeUnknownElementTypeFrameInDEV(
355366
// Lazy may contain any component type so we recursively resolve it.
356367
return describeUnknownElementTypeFrameInDEV(
357368
init(payload),
369+
ownerFn,
358370
currentDispatcherRef,
359371
);
360372
} catch (x) {}

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

+12-4
Original file line numberDiff line numberDiff line change
@@ -39,30 +39,38 @@ export function describeFiber(
3939
ClassComponent,
4040
} = workTagMap;
4141

42+
const owner: null | Function = __DEV__
43+
? workInProgress._debugOwner
44+
? workInProgress._debugOwner.type
45+
: null
46+
: null;
4247
switch (workInProgress.tag) {
4348
case HostComponent:
44-
return describeBuiltInComponentFrame(workInProgress.type);
49+
return describeBuiltInComponentFrame(workInProgress.type, owner);
4550
case LazyComponent:
46-
return describeBuiltInComponentFrame('Lazy');
51+
return describeBuiltInComponentFrame('Lazy', owner);
4752
case SuspenseComponent:
48-
return describeBuiltInComponentFrame('Suspense');
53+
return describeBuiltInComponentFrame('Suspense', owner);
4954
case SuspenseListComponent:
50-
return describeBuiltInComponentFrame('SuspenseList');
55+
return describeBuiltInComponentFrame('SuspenseList', owner);
5156
case FunctionComponent:
5257
case IndeterminateComponent:
5358
case SimpleMemoComponent:
5459
return describeFunctionComponentFrame(
5560
workInProgress.type,
61+
owner,
5662
currentDispatcherRef,
5763
);
5864
case ForwardRef:
5965
return describeFunctionComponentFrame(
6066
workInProgress.type.render,
67+
owner,
6168
currentDispatcherRef,
6269
);
6370
case ClassComponent:
6471
return describeClassComponentFrame(
6572
workInProgress.type,
73+
owner,
6674
currentDispatcherRef,
6775
);
6876
default:

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

+18-35
Original file line numberDiff line numberDiff line change
@@ -1952,24 +1952,15 @@ export function attach(
19521952
const {key} = fiber;
19531953
const displayName = getDisplayNameForFiber(fiber);
19541954
const elementType = getElementTypeForFiber(fiber);
1955-
const debugOwner = fiber._debugOwner;
1955+
const {_debugOwner} = fiber;
19561956

19571957
// Ideally we should call getFiberIDThrows() for _debugOwner,
19581958
// since owners are almost always higher in the tree (and so have already been processed),
19591959
// but in some (rare) instances reported in open source, a descendant mounts before an owner.
19601960
// Since this is a DEV only field it's probably okay to also just lazily generate and ID here if needed.
19611961
// See https://github.com/facebook/react/issues/21445
1962-
let ownerID: number;
1963-
if (debugOwner != null) {
1964-
if (typeof debugOwner.tag === 'number') {
1965-
ownerID = getOrGenerateFiberID((debugOwner: any));
1966-
} else {
1967-
// TODO: Track Server Component Owners.
1968-
ownerID = 0;
1969-
}
1970-
} else {
1971-
ownerID = 0;
1972-
}
1962+
const ownerID =
1963+
_debugOwner != null ? getOrGenerateFiberID(_debugOwner) : 0;
19731964
const parentID = parentFiber ? getFiberIDThrows(parentFiber) : 0;
19741965

19751966
const displayNameStringID = getStringID(displayName);
@@ -3113,17 +3104,15 @@ export function attach(
31133104
return null;
31143105
}
31153106

3107+
const {_debugOwner} = fiber;
3108+
31163109
const owners: Array<SerializedElement> = [fiberToSerializedElement(fiber)];
31173110

3118-
let owner = fiber._debugOwner;
3119-
while (owner != null) {
3120-
if (typeof owner.tag === 'number') {
3121-
const ownerFiber: Fiber = (owner: any); // Refined
3122-
owners.unshift(fiberToSerializedElement(ownerFiber));
3123-
owner = ownerFiber._debugOwner;
3124-
} else {
3125-
// TODO: Track Server Component Owners.
3126-
break;
3111+
if (_debugOwner) {
3112+
let owner: null | Fiber = _debugOwner;
3113+
while (owner !== null) {
3114+
owners.unshift(fiberToSerializedElement(owner));
3115+
owner = owner._debugOwner || null;
31273116
}
31283117
}
31293118

@@ -3184,7 +3173,7 @@ export function attach(
31843173
}
31853174

31863175
const {
3187-
_debugOwner: debugOwner,
3176+
_debugOwner,
31883177
stateNode,
31893178
key,
31903179
memoizedProps,
@@ -3311,19 +3300,13 @@ export function attach(
33113300
context = {value: context};
33123301
}
33133302

3314-
let owners: null | Array<SerializedElement> = null;
3315-
let owner = debugOwner;
3316-
while (owner != null) {
3317-
if (typeof owner.tag === 'number') {
3318-
const ownerFiber: Fiber = (owner: any); // Refined
3319-
if (owners === null) {
3320-
owners = [];
3321-
}
3322-
owners.push(fiberToSerializedElement(ownerFiber));
3323-
owner = ownerFiber._debugOwner;
3324-
} else {
3325-
// TODO: Track Server Component Owners.
3326-
break;
3303+
let owners = null;
3304+
if (_debugOwner) {
3305+
owners = ([]: Array<SerializedElement>);
3306+
let owner: null | Fiber = _debugOwner;
3307+
while (owner !== null) {
3308+
owners.push(fiberToSerializedElement(owner));
3309+
owner = owner._debugOwner || null;
33273310
}
33283311
}
33293312

0 commit comments

Comments
 (0)