Skip to content

Commit 02bcec4

Browse files
committed
[Flight] Only use debug component info for parent stacks
1 parent 3a067e5 commit 02bcec4

File tree

2 files changed

+92
-66
lines changed

2 files changed

+92
-66
lines changed

packages/react-client/src/ReactFlightClient.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1794,13 +1794,21 @@ function transferReferencedDebugInfo(
17941794
existingDebugInfo.push.apply(existingDebugInfo, referencedDebugInfo);
17951795
}
17961796
}
1797-
// We also add it to the initializing chunk since the resolution of that promise is
1798-
// also blocked by these. By adding it to both we can track it even if the array/element
1797+
// We also add the debug info to the initializing chunk since the resolution of that promise is
1798+
// also blocked by the referenced debug info. By adding it to both we can track it even if the array/element
17991799
// is extracted, or if the root is rendered as is.
18001800
if (parentChunk !== null) {
18011801
const parentDebugInfo = parentChunk._debugInfo;
1802-
// $FlowFixMe[method-unbinding]
1803-
parentDebugInfo.push.apply(parentDebugInfo, referencedDebugInfo);
1802+
for (let i = 0; i < referencedDebugInfo.length; ++i) {
1803+
const debugInfoEntry = referencedDebugInfo[i];
1804+
if (debugInfoEntry.name != null) {
1805+
(debugInfoEntry: ReactComponentInfo);
1806+
// We're not transferring Component info since we use Component info
1807+
// in Debug info to fill in gaps between Fibers for the parent stack.
1808+
} else {
1809+
parentDebugInfo.push(debugInfoEntry);
1810+
}
1811+
}
18041812
}
18051813
}
18061814
}

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

Lines changed: 80 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -2957,6 +2957,12 @@ describe('ReactFlight', () => {
29572957
transport: expect.arrayContaining([]),
29582958
},
29592959
},
2960+
{
2961+
time: 16,
2962+
},
2963+
{
2964+
time: 16,
2965+
},
29602966
{time: 17},
29612967
]
29622968
: undefined,
@@ -2976,6 +2982,12 @@ describe('ReactFlight', () => {
29762982
children: {},
29772983
},
29782984
},
2985+
{
2986+
time: 19,
2987+
},
2988+
{
2989+
time: 19,
2990+
},
29792991
{time: 19},
29802992
]
29812993
: undefined,
@@ -3822,6 +3834,7 @@ describe('ReactFlight', () => {
38223834
expect(ReactNoop).toMatchRenderedOutput(<div>not using props</div>);
38233835
});
38243836

3837+
// @gate !__DEV__ || enableComponentPerformanceTrack
38253838
it('produces correct parent stacks', async () => {
38263839
function Container() {
38273840
return ReactServer.createElement('div', null);
@@ -3849,71 +3862,76 @@ describe('ReactFlight', () => {
38493862
expect(root.type).toBe('main');
38503863
if (__DEV__) {
38513864
const div = root.props.children;
3852-
expect(getDebugInfo(div)).toMatchInlineSnapshot(`
3853-
[
3854-
{
3855-
"time": 14,
3856-
},
3857-
{
3858-
"env": "Server",
3859-
"key": null,
3860-
"name": "ContainerParent",
3861-
"owner": {
3862-
"env": "Server",
3863-
"key": null,
3864-
"name": "App",
3865-
"props": {},
3866-
"stack": " in Object.<anonymous> (at **)",
3867-
},
3868-
"props": {},
3869-
"stack": " in App (at **)",
3870-
},
3871-
{
3872-
"time": 15,
3865+
expect(getDebugInfo(div)).toEqual([
3866+
{
3867+
time: 14,
3868+
},
3869+
{
3870+
env: 'Server',
3871+
key: null,
3872+
name: 'ContainerParent',
3873+
owner: {
3874+
env: 'Server',
3875+
key: null,
3876+
name: 'App',
3877+
props: {},
3878+
stack: ' in Object.<anonymous> (at **)',
38733879
},
3874-
{
3875-
"env": "Server",
3876-
"key": null,
3877-
"name": "Container",
3878-
"owner": {
3879-
"env": "Server",
3880-
"key": null,
3881-
"name": "ContainerParent",
3882-
"owner": {
3883-
"env": "Server",
3884-
"key": null,
3885-
"name": "App",
3886-
"props": {},
3887-
"stack": " in Object.<anonymous> (at **)",
3888-
},
3889-
"props": {},
3890-
"stack": " in App (at **)",
3880+
props: {},
3881+
stack: ' in App (at **)',
3882+
},
3883+
{
3884+
time: 15,
3885+
},
3886+
{
3887+
env: 'Server',
3888+
key: null,
3889+
name: 'Container',
3890+
owner: {
3891+
env: 'Server',
3892+
key: null,
3893+
name: 'ContainerParent',
3894+
owner: {
3895+
env: 'Server',
3896+
key: null,
3897+
name: 'App',
3898+
props: {},
3899+
stack: ' in Object.<anonymous> (at **)',
38913900
},
3892-
"props": {},
3893-
"stack": " in ContainerParent (at **)",
3894-
},
3895-
{
3896-
"time": 16,
3897-
},
3898-
]
3899-
`);
3900-
expect(getDebugInfo(root)).toMatchInlineSnapshot(`
3901-
[
3902-
{
3903-
"time": 12,
3904-
},
3905-
{
3906-
"env": "Server",
3907-
"key": null,
3908-
"name": "App",
3909-
"props": {},
3910-
"stack": " in Object.<anonymous> (at **)",
3901+
props: {},
3902+
stack: ' in App (at **)',
39113903
},
3912-
{
3913-
"time": 13,
3914-
},
3915-
]
3916-
`);
3904+
props: {},
3905+
stack: ' in ContainerParent (at **)',
3906+
},
3907+
{
3908+
time: 16,
3909+
},
3910+
]);
3911+
expect(getDebugInfo(root)).toEqual([
3912+
{
3913+
time: 12,
3914+
},
3915+
{
3916+
env: 'Server',
3917+
key: null,
3918+
name: 'App',
3919+
props: {},
3920+
stack: ' in Object.<anonymous> (at **)',
3921+
},
3922+
{
3923+
time: 13,
3924+
},
3925+
{
3926+
time: 14,
3927+
},
3928+
{
3929+
time: 15,
3930+
},
3931+
{
3932+
time: 16,
3933+
},
3934+
]);
39173935
} else {
39183936
expect(root._debugInfo).toBe(undefined);
39193937
expect(root._owner).toBe(undefined);

0 commit comments

Comments
 (0)