Skip to content

Commit

Permalink
[Flight] Add failing test for dedupe resolution on blocked models
Browse files Browse the repository at this point in the history
Triggered by vercel/next.js#66033

I was suspecting that the bug was introduced with #28996, but I could not make the test succeed on a commit before that PR, so maybe this assumption is wrong.
  • Loading branch information
unstubbable committed May 21, 2024
1 parent 5cc9f69 commit 00af602
Showing 1 changed file with 49 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,55 @@ describe('ReactFlightDOMBrowser', () => {
expect(container.innerHTML).toBe('<span>Hello, World!</span>');
});

it('should resolve deduped objects within the same model root when it is blocked', async () => {
let resolveClientComponentChunk;

const ClientOuter = clientExports(function ClientOuter({Component, value}) {
return <Component value={value} />;
});

const ClientInner = clientExports(
function ClientInner({value}) {
return <pre>{JSON.stringify(value)}</pre>;
},
'42',
'/test.js',
new Promise(resolve => (resolveClientComponentChunk = resolve)),
);

function Server({value}) {
return <ClientOuter Component={ClientInner} value={value} />;
}

const shared = [1, 2, 3];
const value = [shared, shared];

const stream = ReactServerDOMServer.renderToReadableStream(
<Server value={value} />,
webpackMap,
);

function ClientRoot({response}) {
return use(response);
}

const response = ReactServerDOMClient.createFromReadableStream(stream);
const container = document.createElement('div');
const root = ReactDOMClient.createRoot(container);

await act(() => {
root.render(<ClientRoot response={response} />);
});

expect(container.innerHTML).toBe('');

await act(() => {
resolveClientComponentChunk();
});

expect(container.innerHTML).toBe('<pre>[[1,2,3],[1,2,3]]</pre>');
});

it('should progressively reveal server components', async () => {
let reportedErrors = [];

Expand Down

0 comments on commit 00af602

Please sign in to comment.