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