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

Unwrap sync resolved thenables without suspending #25615

Merged
merged 2 commits into from
Nov 2, 2022

Conversation

acdlite
Copy link
Collaborator

@acdlite acdlite commented Nov 2, 2022

If a thenable resolves synchronously, use should unwrap its result without suspending or interrupting the component's execution.

If a thenable resolves synchronously, `use` should unwrap its result
without suspending or interrupting the component's execution.
Synchronously resolved thenables are now unwrapped directly inside
`use`. So we don't need this extra logic in the work loop anymore.
@facebook-github-bot facebook-github-bot added CLA Signed React Core Team Opened by a member of the React Core Team labels Nov 2, 2022
@sizebot
Copy link

sizebot commented Nov 2, 2022

Comparing: 4ea063b...9e09e09

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.min.js = 153.64 kB 153.66 kB = 48.90 kB 48.89 kB
oss-experimental/react-dom/cjs/react-dom.production.min.js = 155.57 kB 155.58 kB = 49.52 kB 49.50 kB
facebook-www/ReactDOM-prod.classic.js = 530.64 kB 530.48 kB = 94.68 kB 94.67 kB
facebook-www/ReactDOM-prod.modern.js = 515.89 kB 515.74 kB = 92.51 kB 92.49 kB
facebook-www/ReactDOMForked-prod.classic.js = 530.64 kB 530.48 kB = 94.68 kB 94.67 kB

Significant size changes

Includes any change greater than 0.2%:

Expand to show
Name +/- Base Current +/- gzip Base gzip Current gzip
facebook-relay/flight/ReactFlightNativeRelayServer-prod.js +0.77% 29.28 kB 29.50 kB +0.41% 7.06 kB 7.09 kB
oss-experimental/react-server/cjs/react-server-flight.development.js +0.73% 59.81 kB 60.25 kB +0.46% 14.66 kB 14.73 kB
oss-stable-semver/react-server/cjs/react-server-flight.development.js +0.73% 59.81 kB 60.25 kB +0.46% 14.66 kB 14.73 kB
oss-stable/react-server/cjs/react-server-flight.development.js +0.73% 59.81 kB 60.25 kB +0.46% 14.66 kB 14.73 kB
facebook-relay/flight/ReactFlightNativeRelayServer-dev.js +0.66% 57.10 kB 57.47 kB +0.41% 14.24 kB 14.30 kB
facebook-www/ReactFlightDOMRelayServer-prod.classic.js +0.64% 34.79 kB 35.01 kB +0.33% 8.84 kB 8.87 kB
facebook-www/ReactFlightDOMRelayServer-prod.modern.js +0.64% 34.87 kB 35.09 kB +0.32% 8.87 kB 8.90 kB
oss-experimental/react-server/cjs/react-server-flight.production.min.js +0.59% 13.80 kB 13.88 kB +0.18% 5.14 kB 5.15 kB
oss-stable-semver/react-server/cjs/react-server-flight.production.min.js +0.59% 13.80 kB 13.88 kB +0.18% 5.14 kB 5.15 kB
oss-stable/react-server/cjs/react-server-flight.production.min.js +0.59% 13.80 kB 13.88 kB +0.18% 5.14 kB 5.15 kB
oss-stable-semver/react-server-dom-webpack/umd/react-server-dom-webpack-server.browser.development.js +0.53% 86.71 kB 87.17 kB +0.32% 21.00 kB 21.07 kB
oss-stable/react-server-dom-webpack/umd/react-server-dom-webpack-server.browser.development.js +0.53% 86.71 kB 87.17 kB +0.32% 21.00 kB 21.07 kB
oss-experimental/react-server-dom-webpack/umd/react-server-dom-webpack-server.browser.development.js +0.53% 86.77 kB 87.23 kB +0.32% 21.02 kB 21.09 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-server.browser.development.js +0.53% 82.57 kB 83.00 kB +0.33% 20.75 kB 20.82 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-server.browser.development.js +0.53% 82.57 kB 83.00 kB +0.33% 20.75 kB 20.82 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-server.browser.development.js +0.53% 82.62 kB 83.06 kB +0.33% 20.77 kB 20.84 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-server.node.development.js +0.52% 83.76 kB 84.19 kB +0.34% 20.81 kB 20.88 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-server.node.development.js +0.52% 83.76 kB 84.19 kB +0.34% 20.81 kB 20.88 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-server.node.development.js +0.52% 83.81 kB 84.25 kB +0.34% 20.83 kB 20.90 kB
facebook-www/ReactFlightDOMRelayServer-dev.classic.js +0.51% 73.05 kB 73.43 kB +0.34% 18.11 kB 18.17 kB
facebook-www/ReactFlightDOMRelayServer-dev.modern.js +0.51% 73.10 kB 73.48 kB +0.34% 18.13 kB 18.20 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-server.browser.production.min.js +0.36% 22.48 kB 22.56 kB +0.12% 8.01 kB 8.02 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-server.browser.production.min.js +0.36% 22.48 kB 22.56 kB +0.12% 8.01 kB 8.02 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-server.browser.production.min.js +0.36% 22.52 kB 22.60 kB +0.11% 8.03 kB 8.04 kB
oss-stable-semver/react-server-dom-webpack/umd/react-server-dom-webpack-server.browser.production.min.js +0.36% 22.67 kB 22.75 kB +0.15% 8.11 kB 8.12 kB
oss-stable/react-server-dom-webpack/umd/react-server-dom-webpack-server.browser.production.min.js +0.36% 22.67 kB 22.75 kB +0.15% 8.11 kB 8.12 kB
oss-experimental/react-server-dom-webpack/umd/react-server-dom-webpack-server.browser.production.min.js +0.36% 22.71 kB 22.79 kB +0.16% 8.13 kB 8.14 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-server.node.production.min.js +0.36% 22.85 kB 22.93 kB +0.09% 8.10 kB 8.11 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-server.node.production.min.js +0.36% 22.85 kB 22.93 kB +0.09% 8.10 kB 8.11 kB
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-server.node.production.min.js +0.36% 22.90 kB 22.98 kB +0.09% 8.12 kB 8.12 kB
oss-stable-semver/react-server/cjs/react-server.production.min.js +0.34% 24.16 kB 24.24 kB +0.07% 8.29 kB 8.29 kB
oss-stable/react-server/cjs/react-server.production.min.js +0.34% 24.16 kB 24.24 kB +0.07% 8.29 kB 8.29 kB
oss-experimental/react-server/cjs/react-server.production.min.js +0.34% 24.41 kB 24.49 kB +0.06% 8.38 kB 8.38 kB
oss-stable-semver/react-server/cjs/react-server.development.js +0.30% 144.52 kB 144.95 kB +0.20% 36.05 kB 36.12 kB
oss-stable/react-server/cjs/react-server.development.js +0.30% 144.52 kB 144.95 kB +0.20% 36.05 kB 36.12 kB
oss-experimental/react-server/cjs/react-server.development.js +0.30% 145.14 kB 145.57 kB +0.21% 36.24 kB 36.31 kB

Generated by 🚫 dangerJS against 9e09e09

@acdlite acdlite merged commit 1a90262 into facebook:main Nov 2, 2022
GrinZero added a commit to GrinZero/react that referenced this pull request Nov 7, 2022
* 'main' of ssh://github.com/GrinZero/react: (163 commits)
  Do not unmount layout effects if ancestor Offscreen is hidden (facebook#25628)
  Remove check in renderDidSuspendDelayIfPossible (facebook#25630)
  [ServerRenderer] Move fizz external runtime implementation to react-dom-bindings (facebook#25617)
  Unwrap sync resolved thenables without suspending  (facebook#25615)
  refactor isHostResourceType to not receive the context from reconciler and not leak types (facebook#25610)
  Make host context use null as empty and only error in dev (facebook#25609)
  [Float] handle resource Resource creation inside svg context (facebook#25599)
  Allow uncached IO to stablize (facebook#25561)
  [ServerRenderer] Setup for adding data attributes streaming format (facebook#25567)
  Do not unmount layout effects on initial Offscreen mount (facebook#25592)
  Fix type check for null (facebook#25595)
  Clean up vestige of useOpaqueIdentifier (facebook#25587)
  Extract logic for detecting bad fallback to helper
  Split suspended work loop logic into separate functions
  In work loop, add enum of reasons for suspending
  Strict Mode: Reuse memoized result from first pass (facebook#25583)
  Detect and warn if use(promise) is wrapped with try/catch block (facebook#25543)
  Remove old react-fetch, react-fs and react-pg libraries (facebook#25577)
  Try assigning fetch to globalThis if global assignment fails (facebook#25571)
  [Float] handle noscript context for Resources (facebook#25559)
  ...

# Conflicts:
#	scripts/rollup/build.js
facebook-github-bot pushed a commit to facebook/react-native that referenced this pull request Nov 7, 2022
Summary:
This sync includes the following changes:
- **[4bd245e9e](facebook/react@4bd245e9e )**: Do not unmount layout effects if ancestor Offscreen is hidden ([#25628](facebook/react#25628)) //<Samuel Susla>//
- **[df61e708c](facebook/react@df61e708c )**: Remove check in renderDidSuspendDelayIfPossible ([#25630](facebook/react#25630)) //<Andrew Clark>//
- **[1a08f1478](facebook/react@1a08f1478 )**: [ServerRenderer] Move fizz external runtime implementation to react-dom-bindings ([#25617](facebook/react#25617)) //<mofeiZ>//
- **[1a902623a](facebook/react@1a902623a )**: Unwrap sync resolved thenables without suspending  ([#25615](facebook/react#25615)) //<Andrew Clark>//
- **[4ea063b56](facebook/react@4ea063b56 )**: refactor isHostResourceType to not receive the context from reconciler and not leak types ([#25610](facebook/react#25610)) //<Josh Story>//
- **[8e69bc45a](facebook/react@8e69bc45a )**: Make host context use null as empty and only error in dev ([#25609](facebook/react#25609)) //<Sebastian Markbåge>//
- **[5f7ef8c4c](facebook/react@5f7ef8c4c )**: [Float] handle resource Resource creation inside svg context ([#25599](facebook/react#25599)) //<Josh Story>//
- **[36426e6cb](facebook/react@36426e6cb )**: Allow uncached IO to stablize ([#25561](facebook/react#25561)) //<Andrew Clark>//
- **[6883d7944](facebook/react@6883d7944 )**: [ServerRenderer] Setup for adding data attributes streaming format ([#25567](facebook/react#25567)) //<mofeiZ>//

Changelog:
[General][Changed] - React Native sync for revisions ab075a2...4bd245e

jest_e2e[run_all_tests]

Reviewed By: GijsWeterings

Differential Revision: D41028209

fbshipit-source-id: a67fdcd441ddd50784f7c1ce402eaecdb5e3126d
rejectedThenable.status = 'rejected';
rejectedThenable.reason = error;
}
},
);

// Check one more time in case the thenable resolved synchronously
switch (thenable.status) {
Copy link

@XiNiHa XiNiHa Nov 8, 2022

Choose a reason for hiding this comment

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

@acdlite this never gets hit, since this always results in 'pending':

const syncThen = (p) => {
  let status = 'pending'
  p.then(() => status = 'fulfilled')
  console.log(status)
}
syncThen(Promise.resolve()) // 'pending'
syncThen(new Promise(r => r())) // 'pending'
const resolved = new Promise(r => r())
syncThen(resolved) // 'pending'
setTimeout(() => syncThen(resolved), 0) // 'pending'

I believe it's because .then always gets executed asynchronously, like setTimeout(..., 0)

(I found this while testing with use(Promise.resolve()) in the experimental version)

rickhanlonii pushed a commit that referenced this pull request Dec 3, 2022
If a thenable resolves synchronously, `use` should unwrap its result
without suspending or interrupting the component's execution.
acdlite added a commit to acdlite/react that referenced this pull request Dec 5, 2022
…5615)"

This reverts commit 1a90262.

If a thenable resolves synchronously, `use` should unwrap its result
without suspending or interrupting the component's execution.
OlimpiaZurek pushed a commit to OlimpiaZurek/react-native that referenced this pull request May 22, 2023
Summary:
This sync includes the following changes:
- **[4bd245e9e](facebook/react@4bd245e9e )**: Do not unmount layout effects if ancestor Offscreen is hidden ([facebook#25628](facebook/react#25628)) //<Samuel Susla>//
- **[df61e708c](facebook/react@df61e708c )**: Remove check in renderDidSuspendDelayIfPossible ([facebook#25630](facebook/react#25630)) //<Andrew Clark>//
- **[1a08f1478](facebook/react@1a08f1478 )**: [ServerRenderer] Move fizz external runtime implementation to react-dom-bindings ([facebook#25617](facebook/react#25617)) //<mofeiZ>//
- **[1a902623a](facebook/react@1a902623a )**: Unwrap sync resolved thenables without suspending  ([facebook#25615](facebook/react#25615)) //<Andrew Clark>//
- **[4ea063b56](facebook/react@4ea063b56 )**: refactor isHostResourceType to not receive the context from reconciler and not leak types ([facebook#25610](facebook/react#25610)) //<Josh Story>//
- **[8e69bc45a](facebook/react@8e69bc45a )**: Make host context use null as empty and only error in dev ([facebook#25609](facebook/react#25609)) //<Sebastian Markbåge>//
- **[5f7ef8c4c](facebook/react@5f7ef8c4c )**: [Float] handle resource Resource creation inside svg context ([facebook#25599](facebook/react#25599)) //<Josh Story>//
- **[36426e6cb](facebook/react@36426e6cb )**: Allow uncached IO to stablize ([facebook#25561](facebook/react#25561)) //<Andrew Clark>//
- **[6883d7944](facebook/react@6883d7944 )**: [ServerRenderer] Setup for adding data attributes streaming format ([facebook#25567](facebook/react#25567)) //<mofeiZ>//

Changelog:
[General][Changed] - React Native sync for revisions ab075a2...4bd245e

jest_e2e[run_all_tests]

Reviewed By: GijsWeterings

Differential Revision: D41028209

fbshipit-source-id: a67fdcd441ddd50784f7c1ce402eaecdb5e3126d
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.

5 participants