From 0bce339e9ff405890cedf0b1e67197b1ab284600 Mon Sep 17 00:00:00 2001 From: Dan Abramov Date: Tue, 8 Dec 2020 13:19:59 +0000 Subject: [PATCH] Fix module ID deduplication (#20406) --- packages/react-server/src/ReactFlightServer.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/react-server/src/ReactFlightServer.js b/packages/react-server/src/ReactFlightServer.js index e4f307998ba19..8a6ee64d4d8dc 100644 --- a/packages/react-server/src/ReactFlightServer.js +++ b/packages/react-server/src/ReactFlightServer.js @@ -432,7 +432,8 @@ export function resolveModelToJSON( if (isModuleReference(value)) { const moduleReference: ModuleReference = (value: any); const moduleKey: ModuleKey = getModuleKey(moduleReference); - const existingId = request.writtenModules.get(moduleKey); + const writtenModules = request.writtenModules; + const existingId = writtenModules.get(moduleKey); if (existingId !== undefined) { return serializeByValueID(existingId); } @@ -444,6 +445,7 @@ export function resolveModelToJSON( request.pendingChunks++; const moduleId = request.nextChunkId++; emitModuleChunk(request, moduleId, moduleMetaData); + writtenModules.set(moduleKey, moduleId); 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