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

useActionState: Transfer transition context #29694

Merged

Conversation

acdlite
Copy link
Collaborator

@acdlite acdlite commented May 31, 2024

Mini-refactor of useActionState to only wrap the action in a transition context if the dispatch is called during a transition. Conceptually, the action starts as soon as the dispatch is called, even if the action is queued until earlier ones finish.

We will also warn if an async action is dispatched outside of a transition, since that is almost certainly a mistake. Ideally we would automatically upgrade these to a transition, but we don't have a great way to tell if the action is async until after it's already run.

Mini-refactor of useActionState to only wrap the action in a transition
context if the dispatch is called during a transition. Conceptually, the
action starts as soon as the dispatch is called, even if the action is
queued until earlier ones finish.

We will also warn if an async action is dispatched outside of a
transition, since that is almost certainly a mistake. Ideally we would
automatically upgrade these to a transition, but we don't have a great
way to tell if the action is async until after it's already run.
Copy link

vercel bot commented May 31, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
react-compiler-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 31, 2024 7:49pm

@facebook-github-bot facebook-github-bot added CLA Signed React Core Team Opened by a member of the React Core Team labels May 31, 2024
@react-sizebot
Copy link

Comparing: 8bc81ca...5b49496

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.66 kB 6.66 kB +0.05% 1.82 kB 1.82 kB
oss-stable/react-dom/cjs/react-dom-client.production.js +0.18% 496.39 kB 497.26 kB +0.20% 88.84 kB 89.02 kB
oss-experimental/react-dom/cjs/react-dom.production.js = 6.67 kB 6.67 kB +0.05% 1.83 kB 1.83 kB
oss-experimental/react-dom/cjs/react-dom-client.production.js +0.18% 501.21 kB 502.08 kB +0.19% 89.54 kB 89.71 kB
facebook-www/ReactDOM-prod.classic.js +0.15% 593.88 kB 594.75 kB +0.20% 104.46 kB 104.67 kB
facebook-www/ReactDOM-prod.modern.js +0.15% 570.26 kB 571.14 kB +0.23% 100.87 kB 101.10 kB
test_utils/ReactAllWarnings.js Deleted 63.65 kB 0.00 kB Deleted 15.90 kB 0.00 kB

Significant size changes

Includes any change greater than 0.2%:

Expand to show
Name +/- Base Current +/- gzip Base gzip Current gzip
oss-stable-semver/react-art/cjs/react-art.production.js +0.30% 290.81 kB 291.69 kB +0.44% 50.15 kB 50.37 kB
oss-stable/react-art/cjs/react-art.production.js +0.30% 290.86 kB 291.74 kB +0.44% 50.18 kB 50.40 kB
oss-experimental/react-art/cjs/react-art.production.js +0.30% 295.51 kB 296.39 kB +0.42% 50.92 kB 51.14 kB
oss-stable-semver/react-test-renderer/cjs/react-test-renderer.production.js +0.29% 298.78 kB 299.65 kB +0.42% 53.05 kB 53.27 kB
oss-stable/react-test-renderer/cjs/react-test-renderer.production.js +0.29% 298.82 kB 299.70 kB +0.42% 53.07 kB 53.30 kB
oss-experimental/react-test-renderer/cjs/react-test-renderer.production.js +0.29% 299.94 kB 300.82 kB +0.42% 53.24 kB 53.47 kB
facebook-react-native/react-test-renderer/cjs/ReactTestRenderer-prod.js +0.28% 318.80 kB 319.68 kB +0.41% 56.32 kB 56.55 kB
oss-stable-semver/react-test-renderer/cjs/react-test-renderer.development.js +0.27% 812.77 kB 814.98 kB +0.31% 177.76 kB 178.31 kB
oss-stable/react-test-renderer/cjs/react-test-renderer.development.js +0.27% 812.79 kB 815.00 kB +0.31% 177.78 kB 178.34 kB
oss-experimental/react-test-renderer/cjs/react-test-renderer.development.js +0.27% 814.05 kB 816.26 kB +0.32% 178.03 kB 178.60 kB
oss-stable-semver/react-art/cjs/react-art.development.js +0.27% 823.30 kB 825.51 kB +0.32% 179.33 kB 179.89 kB
oss-stable/react-art/cjs/react-art.development.js +0.27% 823.33 kB 825.54 kB +0.31% 179.35 kB 179.91 kB
oss-experimental/react-art/cjs/react-art.development.js +0.26% 839.14 kB 841.35 kB +0.30% 182.54 kB 183.09 kB
facebook-www/ReactTestRenderer-dev.modern.js +0.26% 852.08 kB 854.29 kB +0.32% 185.18 kB 185.77 kB
facebook-www/ReactTestRenderer-dev.classic.js +0.26% 852.08 kB 854.29 kB +0.32% 185.18 kB 185.77 kB
facebook-react-native/react-test-renderer/cjs/ReactTestRenderer-dev.js +0.26% 857.59 kB 859.80 kB +0.29% 186.10 kB 186.64 kB
facebook-react-native/react-test-renderer/cjs/ReactTestRenderer-profiling.js +0.26% 342.70 kB 343.57 kB +0.39% 59.82 kB 60.05 kB
facebook-www/ReactART-prod.modern.js +0.25% 346.84 kB 347.71 kB +0.38% 58.66 kB 58.88 kB
facebook-www/ReactART-dev.modern.js +0.24% 911.08 kB 913.29 kB +0.29% 194.97 kB 195.54 kB
react-native/implementations/ReactFabric-prod.fb.js +0.24% 364.83 kB 365.71 kB +0.35% 63.94 kB 64.16 kB
facebook-www/ReactART-prod.classic.js +0.24% 364.94 kB 365.82 kB +0.34% 61.57 kB 61.78 kB
oss-stable-semver/react-reconciler/cjs/react-reconciler.development.js +0.24% 925.82 kB 928.03 kB +0.26% 199.66 kB 200.19 kB
oss-stable/react-reconciler/cjs/react-reconciler.development.js +0.24% 925.84 kB 928.05 kB +0.27% 199.69 kB 200.22 kB
react-native/implementations/ReactNativeRenderer-prod.fb.js +0.24% 371.47 kB 372.35 kB +0.35% 65.15 kB 65.38 kB
facebook-www/ReactART-dev.classic.js +0.23% 940.52 kB 942.73 kB +0.28% 200.91 kB 201.47 kB
oss-experimental/react-reconciler/cjs/react-reconciler.development.js +0.23% 940.82 kB 943.03 kB +0.26% 202.89 kB 203.42 kB
react-native/implementations/ReactFabric-dev.fb.js +0.23% 957.88 kB 960.09 kB +0.28% 207.58 kB 208.16 kB
react-native/implementations/ReactNativeRenderer-dev.fb.js +0.23% 969.74 kB 971.95 kB +0.27% 211.18 kB 211.75 kB
oss-stable-semver/react-reconciler/cjs/react-reconciler.production.js +0.23% 375.58 kB 376.43 kB +0.31% 61.62 kB 61.81 kB
oss-stable/react-reconciler/cjs/react-reconciler.production.js +0.23% 375.60 kB 376.45 kB +0.30% 61.65 kB 61.83 kB
react-native/implementations/ReactFabric-profiling.fb.js +0.22% 392.13 kB 393.01 kB +0.34% 68.14 kB 68.37 kB
oss-experimental/react-reconciler/cjs/react-reconciler.production.js +0.22% 380.83 kB 381.68 kB +0.32% 62.39 kB 62.59 kB
react-native/implementations/ReactNativeRenderer-profiling.fb.js +0.22% 398.72 kB 399.60 kB +0.33% 69.50 kB 69.73 kB
facebook-www/ReactReconciler-dev.modern.js +0.22% 1,014.47 kB 1,016.68 kB +0.25% 215.51 kB 216.04 kB
facebook-www/ReactReconciler-dev.classic.js +0.21% 1,044.46 kB 1,046.67 kB +0.24% 221.39 kB 221.92 kB
oss-stable-semver/react-reconciler/cjs/react-reconciler.profiling.js +0.21% 403.82 kB 404.67 kB +0.30% 65.61 kB 65.81 kB
oss-stable/react-reconciler/cjs/react-reconciler.profiling.js +0.21% 403.84 kB 404.69 kB +0.30% 65.64 kB 65.84 kB
oss-experimental/react-reconciler/cjs/react-reconciler.profiling.js +0.21% 409.07 kB 409.92 kB +0.31% 66.44 kB 66.65 kB
test_utils/ReactAllWarnings.js Deleted 63.65 kB 0.00 kB Deleted 15.90 kB 0.00 kB

Generated by 🚫 dangerJS against 5b49496

@acdlite acdlite merged commit 67b05be into facebook:main Jun 3, 2024
40 checks passed
github-actions bot pushed a commit that referenced this pull request Jun 3, 2024
Mini-refactor of useActionState to only wrap the action in a transition
context if the dispatch is called during a transition. Conceptually, the
action starts as soon as the dispatch is called, even if the action is
queued until earlier ones finish.

We will also warn if an async action is dispatched outside of a
transition, since that is almost certainly a mistake. Ideally we would
automatically upgrade these to a transition, but we don't have a great
way to tell if the action is async until after it's already run.

DiffTrain build for commit 67b05be.
github-actions bot pushed a commit that referenced this pull request Jun 3, 2024
Mini-refactor of useActionState to only wrap the action in a transition
context if the dispatch is called during a transition. Conceptually, the
action starts as soon as the dispatch is called, even if the action is
queued until earlier ones finish.

We will also warn if an async action is dispatched outside of a
transition, since that is almost certainly a mistake. Ideally we would
automatically upgrade these to a transition, but we don't have a great
way to tell if the action is async until after it's already run.

DiffTrain build for [67b05be](67b05be)
acdlite added a commit that referenced this pull request Jun 3, 2024
Based on

- #29694 

---

If an action in the useActionState queue errors, we shouldn't run any
subsequent actions. The contract of useActionState is that the actions
run in sequence, and that one action can assume that all previous
actions have completed successfully.

For example, in a shopping cart UI, you might dispatch an "Add to cart"
action followed by a "Checkout" action. If the "Add to cart" action
errors, the "Checkout" action should not run.

An implication of this change is that once useActionState falls into an
error state, the only way to recover is to reset the component tree,
i.e. by unmounting and remounting. The way to customize the error
handling behavior is to wrap the action body in a try/catch.
github-actions bot pushed a commit that referenced this pull request Jun 3, 2024
Based on

- #29694

---

If an action in the useActionState queue errors, we shouldn't run any
subsequent actions. The contract of useActionState is that the actions
run in sequence, and that one action can assume that all previous
actions have completed successfully.

For example, in a shopping cart UI, you might dispatch an "Add to cart"
action followed by a "Checkout" action. If the "Add to cart" action
errors, the "Checkout" action should not run.

An implication of this change is that once useActionState falls into an
error state, the only way to recover is to reset the component tree,
i.e. by unmounting and remounting. The way to customize the error
handling behavior is to wrap the action body in a try/catch.

DiffTrain build for commit 9598c41.
github-actions bot pushed a commit that referenced this pull request Jun 3, 2024
Based on

- #29694

---

If an action in the useActionState queue errors, we shouldn't run any
subsequent actions. The contract of useActionState is that the actions
run in sequence, and that one action can assume that all previous
actions have completed successfully.

For example, in a shopping cart UI, you might dispatch an "Add to cart"
action followed by a "Checkout" action. If the "Add to cart" action
errors, the "Checkout" action should not run.

An implication of this change is that once useActionState falls into an
error state, the only way to recover is to reset the component tree,
i.e. by unmounting and remounting. The way to customize the error
handling behavior is to wrap the action body in a try/catch.

DiffTrain build for [9598c41](9598c41)
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.

3 participants