Skip to content

[Flight] Allow Temporary References to be awaited #34084

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
Aug 2, 2025

Conversation

sebmarkbage
Copy link
Collaborator

Fixes #33534.

.then method can be tested when you await a value that's not a Promise. For regular Client References we have a way to mark those as "async" and yield a reference to the unwrapped value in case it's a Promise on the Client.

However, the realization is that we never serialize Promises as opaque when passed from the client to the server. If a Promise is passed, then it would've been deserialized as a Promise (while still registered as a temporary reference) and not one of these Proxy objects.

Technically it could be a non-function value on the client which would be wrong but you're not supposed to dot into it in the first place.

So we can just assume it's undefined.

@meta-cla meta-cla bot added the CLA Signed label Aug 2, 2025
@github-actions github-actions bot added the React Core Team Opened by a member of the React Core Team label Aug 2, 2025
@sebmarkbage
Copy link
Collaborator Author

sebmarkbage commented Aug 2, 2025

Same as #33761 basically. I just saw it. I landed that one but rebased with my test/comment which has a bit more coverage.

@react-sizebot
Copy link

react-sizebot commented Aug 2, 2025

Comparing: 1d16396...9c79367

Critical size changes

Includes critical production bundles, as well as any change greater than 2%:

Name +/- Base Current +/- gzip Base gzip Current gzip
oss-stable/react-dom/cjs/react-dom.production.js = 6.68 kB 6.68 kB +0.05% 1.83 kB 1.83 kB
oss-stable/react-dom/cjs/react-dom-client.production.js = 530.04 kB 530.04 kB = 93.63 kB 93.63 kB
oss-experimental/react-dom/cjs/react-dom.production.js = 6.69 kB 6.69 kB = 1.83 kB 1.83 kB
oss-experimental/react-dom/cjs/react-dom-client.production.js = 654.48 kB 654.48 kB = 115.34 kB 115.34 kB
facebook-www/ReactDOM-prod.classic.js = 674.42 kB 674.42 kB = 118.68 kB 118.68 kB
facebook-www/ReactDOM-prod.modern.js = 664.84 kB 664.84 kB = 117.02 kB 117.03 kB

Significant size changes

Includes any change greater than 0.2%:

(No significant changes)

Generated by 🚫 dangerJS against 9c79367

@sebmarkbage sebmarkbage merged commit c499adf into facebook:main Aug 2, 2025
242 checks passed
Comment on lines -73 to +78
// Allow returning a temporary reference from an async function
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.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The actual diff is in #33761. This is just about adding an explainer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed React Core Team Opened by a member of the React Core Team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: Server functions error when returning a client reference
4 participants