From 421014fdf5688cf3f943d3ac0d8a5970c25e3452 Mon Sep 17 00:00:00 2001 From: Dan Abramov Date: Fri, 11 Dec 2020 22:45:18 +0000 Subject: [PATCH] [Flight] Use lazy reference for existing modules (#20445) --- packages/react-server/src/ReactFlightServer.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/packages/react-server/src/ReactFlightServer.js b/packages/react-server/src/ReactFlightServer.js index 8a6ee64d4d8dc..d6717a0830760 100644 --- a/packages/react-server/src/ReactFlightServer.js +++ b/packages/react-server/src/ReactFlightServer.js @@ -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 {