Skip to content

Commit

Permalink
[Flight] Use lazy reference for existing modules (#20445)
Browse files Browse the repository at this point in the history
  • Loading branch information
gaearon authored Dec 11, 2020
1 parent 3f9205c commit daf38ec
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions packages/react-server/src/ReactFlightServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,14 @@ export function resolveModelToJSON(
const writtenModules = request.writtenModules;
const existingId = writtenModules.get(moduleKey);
if (existingId !== undefined) {
if (parent[0] === REACT_ELEMENT_TYPE && key === '1') {
// If we're encoding the "type" of an element, we can refer
// to that by a lazy reference instead of directly since React
// knows how to deal with lazy values. This lets us suspend
// on this component rather than its parent until the code has
// loaded.
return serializeByRefID(existingId);
}
return serializeByValueID(existingId);
}
try {
Expand Down

0 comments on commit daf38ec

Please sign in to comment.