[test] Add tests for cyclic arrays in Flight and Flight Reply (#35347)

We already had tests for cyclic objects, but not for cyclic arrays.
This commit is contained in:
Hendrik Liebau
2025-12-17 18:08:16 +01:00
committed by GitHub
parent f93b9fd44b
commit 454fc41fc7
2 changed files with 30 additions and 0 deletions

View File

@@ -724,6 +724,25 @@ describe('ReactFlight', () => {
});
});
it('can transport cyclic arrays', async () => {
function ComponentClient({prop, obj}) {
expect(prop[1]).toBe(prop);
expect(prop[0]).toBe(obj);
}
const Component = clientReference(ComponentClient);
const obj = {};
const cyclic = [obj];
cyclic[1] = cyclic;
const model = <Component prop={cyclic} obj={obj} />;
const transport = ReactNoopFlightServer.render(model);
await act(async () => {
ReactNoop.render(await ReactNoopFlightClient.read(transport));
});
});
it('can render a lazy component as a shared component on the server', async () => {
function SharedComponent({text}) {
return (

View File

@@ -650,6 +650,17 @@ describe('ReactFlightDOMReply', () => {
expect(root.prop.obj).toBe(root.prop);
});
it('can transport cyclic arrays', async () => {
const obj = {};
const cyclic = [obj];
cyclic[1] = cyclic;
const body = await ReactServerDOMClient.encodeReply({prop: cyclic, obj});
const root = await ReactServerDOMServer.decodeReply(body, webpackServerMap);
expect(root.prop[1]).toBe(root.prop);
expect(root.prop[0]).toBe(root.obj);
});
it('can abort an unresolved model and get the partial result', async () => {
const promise = new Promise(r => {});
const controller = new AbortController();