@samitouri / QOS-React-2 / commits / daf38ecdfc

[Flight] Use lazy reference for existing modules (#20445)

Dan Abramov committed Dec 11, 2020 at 22:45 UTC daf38ecdfcda32a1050231fcc6dea364f8b102e3
1 file changed +8
packages/react-server/src/ReactFlightServer.js
+8
@@ -435,6 +435,14 @@ export function resolveModelToJSON(
435 const writtenModules = request.writtenModules;
436 const existingId = writtenModules.get(moduleKey);
437 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 + }
446 return serializeByValueID(existingId);
447 }
448 try {