Skip to content

Commit

Permalink
[Flight] Use lazy reference for existing modules (facebook#20445)
Browse files Browse the repository at this point in the history
  • Loading branch information
gaearon authored and koto committed Jun 15, 2021
1 parent e7023d8 commit 421014f
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 421014f

Please sign in to comment.