Skip to content

[pull] main from facebook:main #209

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 2 commits into from
Aug 3, 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
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,50 @@ describe('ReactFlightDOMReply', () => {
expect(response.obj).toBe(obj);
});

it('can return an opaque object through an async function', async () => {
function fn() {
return 'this is a client function';
}

const args = [fn];

const temporaryReferences =
ReactServerDOMClient.createTemporaryReferenceSet();
const body = await ReactServerDOMClient.encodeReply(args, {
temporaryReferences,
});

const temporaryReferencesServer =
ReactServerDOMServer.createTemporaryReferenceSet();
const serverPayload = await ReactServerDOMServer.decodeReply(
body,
webpackServerMap,
{temporaryReferences: temporaryReferencesServer},
);

async function action(arg) {
return arg;
}

const stream = await serverAct(() =>
ReactServerDOMServer.renderToReadableStream(
{
result: action.apply(null, serverPayload),
},
null,
{temporaryReferences: temporaryReferencesServer},
),
);
const response = await ReactServerDOMClient.createFromReadableStream(
stream,
{
temporaryReferences,
},
);

expect(await response.result).toBe(fn);
});

it('should supports streaming ReadableStream with objects', async () => {
let controller1;
let controller2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ const proxyHandlers = {
`Instead, you can export a Client Component wrapper ` +
`that itself renders a Client Context Provider.`,
);
case 'then':
// Allow returning a temporary reference from an async function
// Unlike regular Client References, a Promise would never have been serialized as
// an opaque Temporary Reference, but instead would have been serialized as a
// Promise on the server and so doesn't hit this path. So we can assume this wasn't
// a Promise on the client.
return undefined;
}
throw new Error(
// eslint-disable-next-line react-internal/safe-string-coercion
Expand Down
Loading