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

Formalize the Wakeable and Thenable types #18391

Merged
merged 3 commits into from Mar 25, 2020

Conversation

sebmarkbage
Copy link
Collaborator

We use two subsets of Promises throughout React APIs. This introduces the smallest subset - Wakeable. It's the thing that you can throw to suspend. It's something that can ping.

I also use a shared type for Thenable in the cases where we expect a value so we can be a bit more rigid with our us of them.

I also made Flight use fake Promises as the Wakeable that it throws.

We use two subsets of Promises throughout React APIs. This introduces
the smallest subset - Wakeable. It's the thing that you can throw to
suspend. It's something that can ping.

I also use a shared type for Thenable in the cases where we expect a value
so we can be a bit more rigid with our us of them.
This value is just going from here to React so we can keep it a lighter
abstraction throughout.
@facebook-github-bot facebook-github-bot added CLA Signed React Core Team Opened by a member of the React Core Team labels Mar 25, 2020
@sizebot
Copy link

sizebot commented Mar 25, 2020

Details of bundled changes.

Comparing: a6924d7...a910e62

react-flight-dom-webpack

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-flight-dom-webpack-server.node.production.min.js 0.0% -0.1% 3.45 KB 3.45 KB 1.56 KB 1.56 KB NODE_PROD
react-flight-dom-webpack.development.js +2.7% +2.0% 12.67 KB 13 KB 3.81 KB 3.89 KB NODE_DEV
react-flight-dom-webpack.production.min.js 🔺+2.1% 🔺+1.1% 3.45 KB 3.53 KB 1.53 KB 1.55 KB NODE_PROD
react-flight-dom-webpack-server.node.development.js 0.0% -0.0% 10.64 KB 10.64 KB 3.21 KB 3.21 KB NODE_DEV
react-flight-dom-webpack-server.browser.production.min.js 0.0% -0.2% 3.47 KB 3.47 KB 1.63 KB 1.63 KB UMD_PROD
react-flight-dom-webpack-server.browser.production.min.js 0.0% -0.1% 3.29 KB 3.29 KB 1.55 KB 1.55 KB NODE_PROD
react-flight-dom-webpack.development.js +2.6% +2.0% 13.68 KB 14.03 KB 3.93 KB 4.01 KB UMD_DEV
react-flight-dom-webpack.production.min.js 🔺+2.0% 🔺+1.4% 3.64 KB 3.71 KB 1.62 KB 1.64 KB UMD_PROD

react-flight-dom-relay

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
ReactFlightDOMRelayClient-dev.js +4.2% +4.1% 8.14 KB 8.48 KB 2.6 KB 2.71 KB FB_WWW_DEV
ReactFlightDOMRelayClient-prod.js 🔺+0.3% 🔺+1.4% 4.5 KB 4.51 KB 1.45 KB 1.47 KB FB_WWW_PROD

react-client

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-client-flight.development.js +3.2% +3.4% 10.65 KB 11 KB 3.29 KB 3.41 KB NODE_DEV
react-client-flight.production.min.js 🔺+2.4% 🔺+2.5% 3.05 KB 3.13 KB 1.34 KB 1.38 KB NODE_PROD

Size changes (stable)

Generated by 🚫 dangerJS against a910e62


// The subset of a Thenable required by things thrown by Suspense.
// This doesn't require a value to be passed to either handler.
export interface Wakeable {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thenable is called that way because you can call then on it.

Maybe this should be Waker or something. The walkable thing is what you pass to the then method. Something that can be woken.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I guess in Rust, a Waker is the thing you call to then (essentially). It's the thing to be woken up.

So I guess Wakeable is fine. It's the thing that will at some point trigger to wake up the Waker.

@sizebot
Copy link

sizebot commented Mar 25, 2020

Details of bundled changes.

Comparing: a6924d7...a910e62

react-flight-dom-webpack

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-flight-dom-webpack-server.browser.production.min.js 0.0% -0.2% 3.48 KB 3.48 KB 1.64 KB 1.63 KB UMD_PROD
react-flight-dom-webpack.development.js +2.6% +2.0% 13.7 KB 14.05 KB 3.93 KB 4.01 KB UMD_DEV
react-flight-dom-webpack.production.min.js 🔺+2.0% 🔺+1.3% 3.65 KB 3.72 KB 1.63 KB 1.65 KB UMD_PROD
react-flight-dom-webpack.development.js +2.7% +2.0% 12.68 KB 13.02 KB 3.82 KB 3.9 KB NODE_DEV
react-flight-dom-webpack.production.min.js 🔺+2.1% 🔺+1.1% 3.47 KB 3.54 KB 1.54 KB 1.56 KB NODE_PROD
react-flight-dom-webpack-server.node.production.min.js 0.0% -0.1% 3.46 KB 3.46 KB 1.57 KB 1.57 KB NODE_PROD
react-flight-dom-webpack-server.browser.development.js 0.0% -0.0% 9.71 KB 9.71 KB 2.95 KB 2.95 KB NODE_DEV
react-flight-dom-webpack-server.browser.production.min.js 0.0% -0.1% 3.3 KB 3.3 KB 1.56 KB 1.55 KB NODE_PROD

react-client

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-client-flight.development.js +3.2% +3.4% 10.67 KB 11.01 KB 3.3 KB 3.42 KB NODE_DEV
react-client-flight.production.min.js 🔺+2.4% 🔺+2.5% 3.07 KB 3.14 KB 1.35 KB 1.38 KB NODE_PROD

react-flight-dom-relay

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
ReactFlightDOMRelayClient-dev.js +4.2% +4.1% 8.14 KB 8.48 KB 2.6 KB 2.71 KB FB_WWW_DEV
ReactFlightDOMRelayClient-prod.js 🔺+0.3% 🔺+1.4% 4.5 KB 4.51 KB 1.45 KB 1.47 KB FB_WWW_PROD

Size changes (experimental)

Generated by 🚫 dangerJS against a910e62

Copy link
Collaborator

@gaearon gaearon left a comment

Choose a reason for hiding this comment

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

Screenshot 2020-03-25 at 23 09 25

@sebmarkbage sebmarkbage merged commit 64ed221 into facebook:master Mar 25, 2020
if (chunk._status === RESOLVED) {
return chunk._value;
} else if (chunk._status === PENDING) {
// eslint-disable-next-line no-throw-literal
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Btw this seems like a bug in the no-throw-literal lint. It gets confused by the Flow annotation.

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.

None yet

4 participants