Skip to content

Commit daf38ec

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

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

‎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
constwrittenModules=request.writtenModules;
436436
constexistingId=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+
returnserializeByRefID(existingId);
445+
}
438446
returnserializeByValueID(existingId);
439447
}
440448
try{

0 commit comments

Comments
 (0)