Skip to content

[pull] main from facebook:main #197

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

Merged
merged 1 commit into from
Jul 28, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
57 changes: 57 additions & 0 deletions packages/react-dom/src/__tests__/ReactDOMFizzServer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6340,6 +6340,63 @@ describe('ReactDOMFizzServer', () => {
expect(getVisibleChildren(container)).toEqual('Hi');
});

it('should correctly handle different promises in React.use() across lazy components', async () => {
let promise1;
let promise2;
let promiseLazy;

function Component1() {
promise1 ??= new Promise(r => setTimeout(() => r('value1'), 50));
const data = React.use(promise1);
return (
<div>
{data}
<Component2Lazy />
</div>
);
}

function Component2() {
promise2 ??= new Promise(r => setTimeout(() => r('value2'), 50));
const data = React.use(promise2);
return <div>{data}</div>;
}

const Component2Lazy = React.lazy(async () => {
promiseLazy ??= new Promise(r => setTimeout(r, 50));
await promiseLazy;
return {default: Component2};
});

function App() {
return <Component1 />;
}

await act(async () => {
const {pipe} = renderToPipeableStream(<App />);
pipe(writable);
});

// Wait for promise to resolve
await act(async () => {
await promise1;
});
await act(async () => {
await promiseLazy;
});
await act(async () => {
await promise2;
});

// Verify both components received the correct values
expect(getVisibleChildren(container)).toEqual(
<div>
value1
<div>value2</div>
</div>,
);
});

it('useActionState hydrates without a mismatch', async () => {
// This is testing an implementation detail: useActionState emits comment
// nodes into the SSR stream, so this checks that they are handled correctly
Expand Down
30 changes: 24 additions & 6 deletions packages/react-server/src/ReactFizzServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -4153,7 +4153,10 @@ function renderNode(
// $FlowFixMe[method-unbinding]
if (typeof x.then === 'function') {
const wakeable: Wakeable = (x: any);
const thenableState = getThenableStateAfterSuspending();
const thenableState =
thrownValue === SuspenseException
? getThenableStateAfterSuspending()
: null;
const newTask = spawnNewSuspendedReplayTask(
request,
// $FlowFixMe: Refined.
Expand Down Expand Up @@ -4186,7 +4189,10 @@ function renderNode(
// performance but it can lead to stack overflows in extremely deep trees.
// We do have the ability to create a trampoile if this happens which makes
// this kind of zero-cost.
const thenableState = getThenableStateAfterSuspending();
const thenableState =
thrownValue === SuspenseException
? getThenableStateAfterSuspending()
: null;
const newTask = spawnNewSuspendedReplayTask(
request,
// $FlowFixMe: Refined.
Expand Down Expand Up @@ -4246,7 +4252,10 @@ function renderNode(
// $FlowFixMe[method-unbinding]
if (typeof x.then === 'function') {
const wakeable: Wakeable = (x: any);
const thenableState = getThenableStateAfterSuspending();
const thenableState =
thrownValue === SuspenseException
? getThenableStateAfterSuspending()
: null;
const newTask = spawnNewSuspendedRenderTask(
request,
// $FlowFixMe: Refined.
Expand Down Expand Up @@ -4317,7 +4326,10 @@ function renderNode(
// performance but it can lead to stack overflows in extremely deep trees.
// We do have the ability to create a trampoile if this happens which makes
// this kind of zero-cost.
const thenableState = getThenableStateAfterSuspending();
const thenableState =
thrownValue === SuspenseException
? getThenableStateAfterSuspending()
: null;
const newTask = spawnNewSuspendedRenderTask(
request,
// $FlowFixMe: Refined.
Expand Down Expand Up @@ -5233,7 +5245,10 @@ function retryRenderTask(
if (typeof x.then === 'function') {
// Something suspended again, let's pick it back up later.
segment.status = PENDING;
task.thenableState = getThenableStateAfterSuspending();
task.thenableState =
thrownValue === SuspenseException
? getThenableStateAfterSuspending()
: null;
const ping = task.ping;
// We've asserted that x is a thenable above
(x: any).then(ping, ping);
Expand Down Expand Up @@ -5338,7 +5353,10 @@ function retryReplayTask(request: Request, task: ReplayTask): void {
// Something suspended again, let's pick it back up later.
const ping = task.ping;
x.then(ping, ping);
task.thenableState = getThenableStateAfterSuspending();
task.thenableState =
thrownValue === SuspenseException
? getThenableStateAfterSuspending()
: null;
return;
}
}
Expand Down
Loading