Skip to content

Commit b44d302

Browse files
committed
Include the owner of a Server Component which must also be another Server Component
1 parent d290097 commit b44d302

File tree

6 files changed

+25
-11
lines changed

6 files changed

+25
-11
lines changed

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

Lines changed: 10 additions & 7 deletions
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'}] : undefined,
217+
__DEV__ ? [{name: 'Greeting', env: 'Server', owner: null}] : 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'}] : undefined,
244+
__DEV__ ? [{name: 'Greeting', env: 'Server', owner: null}] : undefined,
245245
);
246246
ReactNoop.render(await promise);
247247
});
@@ -2072,19 +2072,21 @@ describe('ReactFlight', () => {
20722072
await act(async () => {
20732073
const promise = ReactNoopFlightClient.read(transport);
20742074
expect(promise._debugInfo).toEqual(
2075-
__DEV__ ? [{name: 'ServerComponent', env: 'Server'}] : undefined,
2075+
__DEV__
2076+
? [{name: 'ServerComponent', env: 'Server', owner: null}]
2077+
: undefined,
20762078
);
20772079
const result = await promise;
20782080
const thirdPartyChildren = await result.props.children[1];
20792081
// We expect the debug info to be transferred from the inner stream to the outer.
20802082
expect(thirdPartyChildren[0]._debugInfo).toEqual(
20812083
__DEV__
2082-
? [{name: 'ThirdPartyComponent', env: 'third-party'}]
2084+
? [{name: 'ThirdPartyComponent', env: 'third-party', owner: null}]
20832085
: undefined,
20842086
);
20852087
expect(thirdPartyChildren[1]._debugInfo).toEqual(
20862088
__DEV__
2087-
? [{name: 'ThirdPartyLazyComponent', env: 'third-party'}]
2089+
? [{name: 'ThirdPartyLazyComponent', env: 'third-party', owner: null}]
20882090
: undefined,
20892091
);
20902092
ReactNoop.render(result);
@@ -2172,9 +2174,10 @@ describe('ReactFlight', () => {
21722174
// We've rendered down to the span.
21732175
expect(greeting.type).toBe('span');
21742176
if (__DEV__) {
2177+
const greetInfo = {name: 'Greeting', env: 'Server', owner: null};
21752178
expect(greeting._debugInfo).toEqual([
2176-
{name: 'Greeting', env: 'Server'},
2177-
{name: 'Container', env: 'Server'},
2179+
greetInfo,
2180+
{name: 'Container', env: 'Server', owner: greetInfo},
21782181
]);
21792182
// The owner that created the span was the outer server component.
21802183
// We expect the debug info to be referentially equal to the owner.

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ describe('component stack', () => {
101101
{
102102
name: 'ServerComponent',
103103
env: 'Server',
104+
owner: null,
104105
},
105106
];
106107
const Parent = () => ChildPromise;

packages/react-server-dom-webpack/src/__tests__/ReactFlightDOMEdge-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ describe('ReactFlightDOMEdge', () => {
290290
<ServerComponent recurse={20} />,
291291
);
292292
const serializedContent = await readResult(stream);
293-
const expectedDebugInfoSize = __DEV__ ? 42 * 20 : 0;
293+
const expectedDebugInfoSize = __DEV__ ? 64 * 20 : 0;
294294
expect(serializedContent.length).toBeLessThan(150 + expectedDebugInfoSize);
295295
});
296296

packages/react-server/src/ReactFlightServer.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,7 @@ function renderFunctionComponent<Props>(
596596
key: null | string,
597597
Component: (p: Props, arg: void) => any,
598598
props: Props,
599+
owner: null | ReactComponentInfo,
599600
): ReactJSONValue {
600601
// Reset the task's thenable state before continuing, so that if a later
601602
// component suspends we can reuse the same task object. If the same
@@ -624,6 +625,7 @@ function renderFunctionComponent<Props>(
624625
componentDebugInfo = {
625626
name: componentName,
626627
env: request.environmentName,
628+
owner: owner,
627629
};
628630
// We outline this model eagerly so that we can refer to by reference as an owner.
629631
// If we had a smarter way to dedupe we might not have to do this if there ends up
@@ -832,7 +834,7 @@ function renderElement(
832834
return renderClientElement(task, type, key, props, owner);
833835
}
834836
// This is a Server Component.
835-
return renderFunctionComponent(request, task, key, type, props);
837+
return renderFunctionComponent(request, task, key, type, props, owner);
836838
} else if (typeof type === 'string') {
837839
// This is a host element. E.g. HTML.
838840
return renderClientElement(task, type, key, props, owner);
@@ -878,7 +880,14 @@ function renderElement(
878880
);
879881
}
880882
case REACT_FORWARD_REF_TYPE: {
881-
return renderFunctionComponent(request, task, key, type.render, props);
883+
return renderFunctionComponent(
884+
request,
885+
task,
886+
key,
887+
type.render,
888+
props,
889+
owner,
890+
);
882891
}
883892
case REACT_MEMO_TYPE: {
884893
return renderElement(request, task, type.type, key, ref, props, owner);

packages/react/src/__tests__/ReactFetch-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ describe('ReactFetch', () => {
8686
const promise = render(Component);
8787
expect(await promise).toMatchInlineSnapshot(`"GET world []"`);
8888
expect(promise._debugInfo).toEqual(
89-
__DEV__ ? [{name: 'Component', env: 'Server'}] : undefined,
89+
__DEV__ ? [{name: 'Component', env: 'Server', owner: null}] : undefined,
9090
);
9191
expect(fetchCount).toBe(1);
9292
});

packages/shared/ReactTypes.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ export type Awaited<T> = T extends null | void
181181
export type ReactComponentInfo = {
182182
+name?: string,
183183
+env?: string,
184+
+owner?: null | ReactComponentInfo,
184185
};
185186

186187
export type ReactAsyncInfo = {

0 commit comments

Comments
 (0)