Skip to content

Commit 20ce679

Browse files
committed
[test] Add tests for cyclic arrays in Flight and Flight Reply
We already had tests for cyclic objects, but not for cyclic arrays.
1 parent 80cb7a9 commit 20ce679

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

packages/react-client/src/__tests__/ReactFlight-test.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -727,6 +727,25 @@ describe('ReactFlight', () => {
727727
});
728728
});
729729

730+
it('can transport cyclic arrays', async () => {
731+
function ComponentClient({prop, obj}) {
732+
expect(prop[1]).toBe(prop);
733+
expect(prop[0]).toBe(obj);
734+
}
735+
const Component = clientReference(ComponentClient);
736+
737+
const obj = {};
738+
const cyclic = [obj];
739+
cyclic[1] = cyclic;
740+
const model = <Component prop={cyclic} obj={obj} />;
741+
742+
const transport = ReactNoopFlightServer.render(model);
743+
744+
await act(async () => {
745+
ReactNoop.render(await ReactNoopFlightClient.read(transport));
746+
});
747+
});
748+
730749
it('can render a lazy component as a shared component on the server', async () => {
731750
function SharedComponent({text}) {
732751
return (

packages/react-server-dom-webpack/src/__tests__/ReactFlightDOMReply-test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,17 @@ describe('ReactFlightDOMReply', () => {
650650
expect(root.prop.obj).toBe(root.prop);
651651
});
652652

653+
it('can transport cyclic arrays', async () => {
654+
const obj = {};
655+
const cyclic = [obj];
656+
cyclic[1] = cyclic;
657+
658+
const body = await ReactServerDOMClient.encodeReply({prop: cyclic, obj});
659+
const root = await ReactServerDOMServer.decodeReply(body, webpackServerMap);
660+
expect(root.prop[1]).toBe(root.prop);
661+
expect(root.prop[0]).toBe(root.obj);
662+
});
663+
653664
it('can abort an unresolved model and get the partial result', async () => {
654665
const promise = new Promise(r => {});
655666
const controller = new AbortController();

0 commit comments

Comments
 (0)