[Flight] Don't hang after resolving cyclic references (#34988)

This commit is contained in:
Hendrik Liebau
2025-10-27 22:06:28 +01:00
committed by GitHub
parent d3d0ce329e
commit 0d721b60c2
2 changed files with 41 additions and 0 deletions

View File

@@ -624,6 +624,22 @@ function wakeChunkIfInitialized<T>(
rejectListeners.splice(rejectionIdx, 1);
}
}
// The status might have changed after fulfilling the reference.
switch ((chunk: SomeChunk<T>).status) {
case INITIALIZED:
const initializedChunk: InitializedChunk<T> = (chunk: any);
wakeChunk(
resolveListeners,
initializedChunk.value,
initializedChunk,
);
return;
case ERRORED:
if (rejectListeners !== null) {
rejectChunk(rejectListeners, chunk.reason);
}
return;
}
}
}
}

View File

@@ -2196,4 +2196,29 @@ describe('ReactFlightDOMEdge', () => {
'Switched to client rendering because the server rendering errored:\n\nssr-throw',
);
});
it('should properly resolve with deduped objects', async () => {
const obj = {foo: 'hi'};
function Test(props) {
return props.obj.foo;
}
const root = {
obj: obj,
node: <Test obj={obj} />,
};
const stream = ReactServerDOMServer.renderToReadableStream(root);
const response = ReactServerDOMClient.createFromReadableStream(stream, {
serverConsumerManifest: {
moduleMap: null,
moduleLoading: null,
},
});
const result = await response;
expect(result).toEqual({obj: obj, node: 'hi'});
});
});