Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix resolving of references to deduped props in lazy elements #30441

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions packages/react-client/src/ReactFlightClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -1003,6 +1003,16 @@ function getOutlinedModel<T>(
let value = chunk.value;
for (let i = 1; i < path.length; i++) {
value = value[path[i]];
if (value.$$typeof === REACT_LAZY_TYPE) {
return waitForReference(
unstubbable marked this conversation as resolved.
Show resolved Hide resolved
value._payload,
parentObject,
key,
response,
map,
path.slice(i),
);
}
}
const chunkValue = map(response, value);
if (__DEV__ && chunk._debugInfo) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,75 @@ describe('ReactFlightDOMBrowser', () => {
expect(container.innerHTML).toBe('{}');
});

it('should resolve deduped objects in blocked models referencing other blocked models with blocked references', async () => {
let resolveFooClientComponentChunk;
let resolveBarClientComponentChunk;

function PassthroughServerComponent({children}) {
return children;
}

const FooClient = clientExports(
function FooClient({children}) {
return JSON.stringify(children);
},
'1',
'/foo.js',
new Promise(resolve => (resolveFooClientComponentChunk = resolve)),
);

const BarClient = clientExports(
function BarClient() {
return 'not used';
},
'2',
'/bar.js',
new Promise(resolve => (resolveBarClientComponentChunk = resolve)),
);

const shared = {foo: 1};

function Server() {
return (
<>
<PassthroughServerComponent>
<FooClient key="first" bar={BarClient}>
{shared}
</FooClient>
</PassthroughServerComponent>
<FooClient key="second" bar={BarClient}>
{shared}
</FooClient>
</>
);
}

const stream = await serverAct(() =>
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(() => {
resolveFooClientComponentChunk();
resolveBarClientComponentChunk();
});

expect(container.innerHTML).toBe('{"foo":1}{"foo":1}');
});

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

Expand Down
Loading