Skip to content

Commit daf38ec

Browse files
authored
[Flight] Use lazy reference for existing modules (#20445)
1 parent 3f9205c commit daf38ec

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

packages/react-server/src/ReactFlightServer.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,14 @@ export function resolveModelToJSON(
435435
const writtenModules = request.writtenModules;
436436
const existingId = writtenModules.get(moduleKey);
437437
if (existingId !== undefined) {
438+
if (parent[0] === REACT_ELEMENT_TYPE && key === '1') {
439+
// If we're encoding the "type" of an element, we can refer
440+
// to that by a lazy reference instead of directly since React
441+
// knows how to deal with lazy values. This lets us suspend
442+
// on this component rather than its parent until the code has
443+
// loaded.
444+
return serializeByRefID(existingId);
445+
}
438446
return serializeByValueID(existingId);
439447
}
440448
try {

0 commit comments

Comments
 (0)