Skip to content

Commit 5807d57

Browse files
committed
Handle owner and stack when resolving partially deduped elements
This is a follow-up from #30528 to not only handle props (the critical change), but also the owner and stack of a referenced element. Handling stacks here is rather academic because the Flight Server currently does not deduplicate owner stacks. And if they are really identical, we should probably just dedupe the whole element.
1 parent 2b00018 commit 5807d57

File tree

2 files changed

+30
-9
lines changed

2 files changed

+30
-9
lines changed

packages/react-client/src/ReactFlightClient.js

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -907,26 +907,41 @@ function waitForReference<T>(
907907
}
908908
value = value[path[i]];
909909
}
910-
parentObject[key] = map(response, value);
910+
const mappedValue = map(response, value);
911+
parentObject[key] = mappedValue;
911912

912913
// If this is the root object for a model reference, where `handler.value`
913914
// is a stale `null`, the resolved value can be used directly.
914915
if (key === '' && handler.value === null) {
915-
handler.value = parentObject[key];
916+
handler.value = mappedValue;
916917
}
917918

918-
// If the parent object is an unparsed React element tuple and its outlined
919-
// props have now been resolved, we also need to update the props of the
920-
// parsed element object (i.e. handler.value).
919+
// If the parent object is an unparsed React element tuple, we also need to
920+
// update the props, owner, and stack of the parsed element object (i.e.
921+
// handler.value).
921922
if (
922923
parentObject[0] === REACT_ELEMENT_TYPE &&
923-
key === '3' &&
924924
typeof handler.value === 'object' &&
925925
handler.value !== null &&
926-
handler.value.$$typeof === REACT_ELEMENT_TYPE &&
927-
handler.value.props === null
926+
handler.value.$$typeof === REACT_ELEMENT_TYPE
928927
) {
929-
handler.value.props = parentObject[key];
928+
const element: any = handler.value;
929+
switch (key) {
930+
case '3':
931+
element.props = mappedValue;
932+
break;
933+
case '4':
934+
element._owner = mappedValue;
935+
break;
936+
case '5':
937+
Object.defineProperty(element, '_debugStack', {
938+
configurable: false,
939+
enumerable: false,
940+
writable: true,
941+
value: mappedValue,
942+
});
943+
break;
944+
}
930945
}
931946

932947
handler.deps--;

packages/react-server/src/ReactFlightServer.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2468,6 +2468,12 @@ function renderModelDestructive(
24682468
case '3':
24692469
propertyName = 'props';
24702470
break;
2471+
case '4':
2472+
propertyName = '_owner';
2473+
break;
2474+
case '5':
2475+
propertyName = '_debugStack';
2476+
break;
24712477
}
24722478
}
24732479
writtenObjects.set(value, parentReference + ':' + propertyName);

0 commit comments

Comments
 (0)