Skip to content

Commit

Permalink
[Flight] Add failing test to reproduce issue with Object.freeze
Browse files Browse the repository at this point in the history
  • Loading branch information
unstubbable committed May 17, 2024
1 parent 3f1436c commit e52afc3
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,62 @@ describe('ReactFlightDOMBrowser', () => {
});
});

it('should resolve client components (with async chunks) when referenced in props', async () => {
let resolve;
const chunkPromise = new Promise(r => (resolve = r));

function ClientOuter({Component, children}) {
return <Component>{children}</Component>;
}

function ClientInner({children}) {
return <span>{children}</span>;
}

const ClientOuterRef = clientExports(ClientOuter);

const ClientInnerRef = clientExports(
ClientInner,
'42',
'/test.js',
chunkPromise,
);

function Server() {
return (
<ClientOuterRef Component={ClientInnerRef}>
Hello, World!
</ClientOuterRef>
);
}

const stream = ReactServerDOMServer.renderToReadableStream(
<Server />,
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(() => {
// Resolve async client component chunks.
resolve();
});

expect(container.innerHTML).toBe('<span>Hello, World!</span>');
});

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,15 @@ exports.clientExports = function clientExports(
moduleExports,
chunkId,
chunkFilename,
blockOnChunk,
) {
const chunks = [];
if (chunkId) {
chunks.push(chunkId, chunkFilename);

if (blockOnChunk) {
webpackChunkMap[chunkId] = blockOnChunk;
}
}
const idx = '' + webpackModuleIdx++;
webpackClientModules[idx] = moduleExports;
Expand Down

0 comments on commit e52afc3

Please sign in to comment.