mirror of
https://github.com/zebrajr/react.git
synced 2026-01-15 12:15:22 +00:00
[Flight] Don't hang after resolving cyclic references (#34988)
This commit is contained in:
16
packages/react-client/src/ReactFlightClient.js
vendored
16
packages/react-client/src/ReactFlightClient.js
vendored
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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'});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user