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

useTransition improvements #17411

Closed
wants to merge 3 commits into from
Closed

Conversation

acdlite
Copy link
Collaborator

@acdlite acdlite commented Nov 20, 2019

(I closed and and re-opened this as #17418)

The `isPending` state managed by the `useTransition` queue can be
modeled using the same queue as useState/useReducer; that's how it's
implemented today. However, since there's only ever a single pending
transition per `useTransition` hook, and the most recent one always
wins, we don't really need to maintain an entire queue structure.

This replaces the internal `useState` queue with a specialized
implementation. It tracks the most recent transition expiration time
on shared instance object, and the last processed expiration time on
each hook copy. When the processed expiration time catches up to the
pending one, we know that the transition is no longer pending. At a
high level, this is also how the `useState` queue works, but without
the overhead of an actual queue.

The implementation is also inspired by Suspense boundaries, which also
have an internal state for whether the boundary is displaying a
fallback, but does not use an actual queue to manage that state.
When multiple transitions update the same queue, only the most recent
one should be considered pending.

Example: If I switch tabs multiple times, only the last tab I click
should display a pending state (e.g. an inline spinner).
@sizebot
Copy link

sizebot commented Nov 20, 2019

Details of bundled changes.

Comparing: a7d07ff...162454b

react-dom

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-dom.profiling.min.js +1.2% +1.5% 123.53 KB 124.97 KB 38.84 KB 39.42 KB NODE_PROFILING
react-dom-server.browser.development.js 0.0% -0.0% 140.46 KB 140.46 KB 36.91 KB 36.91 KB UMD_DEV
react-dom-server.browser.production.min.js 0.0% 0.0% 20.39 KB 20.39 KB 7.48 KB 7.48 KB UMD_PROD
react-dom-unstable-fizz.browser.development.js 0.0% +0.2% 3.88 KB 3.88 KB 1.55 KB 1.55 KB UMD_DEV
react-dom-test-utils.production.min.js 0.0% 0.0% 11.18 KB 11.18 KB 4.15 KB 4.15 KB UMD_PROD
react-dom-unstable-fizz.browser.production.min.js 0.0% 🔺+0.3% 1.21 KB 1.21 KB 710 B 712 B UMD_PROD
ReactDOMServer-dev.js 0.0% -0.0% 139.73 KB 139.73 KB 35.46 KB 35.46 KB FB_WWW_DEV
ReactDOMServer-prod.js 0.0% 0.0% 48.91 KB 48.91 KB 11.18 KB 11.18 KB FB_WWW_PROD
react-dom-unstable-fizz.browser.development.js 0.0% +0.1% 3.71 KB 3.71 KB 1.5 KB 1.5 KB NODE_DEV
react-dom-test-utils.production.min.js 0.0% -0.0% 10.95 KB 10.95 KB 4.09 KB 4.09 KB NODE_PROD
react-dom-unstable-fizz.browser.production.min.js 0.0% 🔺+0.3% 1.05 KB 1.05 KB 641 B 643 B NODE_PROD
react-dom.development.js +1.1% +1.2% 953.95 KB 964.05 KB 215.71 KB 218.32 KB UMD_DEV
react-dom.production.min.js 🔺+1.2% 🔺+1.6% 119.59 KB 121 KB 38.41 KB 39.03 KB UMD_PROD
react-dom.profiling.min.js +1.2% +1.5% 123.27 KB 124.69 KB 39.52 KB 40.11 KB UMD_PROFILING
react-dom.development.js +1.1% +1.2% 948.01 KB 958.12 KB 214.13 KB 216.75 KB NODE_DEV
react-dom-server.node.development.js 0.0% -0.0% 137.5 KB 137.5 KB 36.14 KB 36.14 KB NODE_DEV
react-dom.production.min.js 🔺+1.2% 🔺+1.5% 119.73 KB 121.16 KB 37.79 KB 38.35 KB NODE_PROD
react-dom-server.node.production.min.js 0.0% 0.0% 20.72 KB 20.72 KB 7.61 KB 7.61 KB NODE_PROD
react-dom-server.browser.development.js 0.0% -0.0% 136.39 KB 136.39 KB 35.91 KB 35.91 KB NODE_DEV
react-dom-server.browser.production.min.js 0.0% 0.0% 20.31 KB 20.31 KB 7.46 KB 7.46 KB NODE_PROD
react-dom-unstable-native-dependencies.development.js 0.0% 0.0% 60.14 KB 60.14 KB 15.8 KB 15.8 KB UMD_DEV
react-dom-unstable-native-dependencies.production.min.js 0.0% 🔺+0.1% 10.73 KB 10.73 KB 3.67 KB 3.68 KB UMD_PROD
ReactDOM-dev.js +1.1% +1.2% 976.09 KB 986.44 KB 216.67 KB 219.38 KB FB_WWW_DEV
ReactDOM-prod.js 🔺+1.2% 🔺+1.2% 402.73 KB 407.41 KB 73.37 KB 74.25 KB FB_WWW_PROD
react-dom-unstable-native-dependencies.development.js 0.0% 0.0% 59.82 KB 59.82 KB 15.66 KB 15.67 KB NODE_DEV
react-dom-unstable-fizz.node.development.js 0.0% +0.1% 4.42 KB 4.42 KB 1.65 KB 1.65 KB NODE_DEV
ReactDOM-profiling.js +1.2% +1.3% 403.69 KB 408.37 KB 73.91 KB 74.89 KB FB_WWW_PROFILING
react-dom-unstable-native-dependencies.production.min.js 0.0% 🔺+0.1% 10.48 KB 10.48 KB 3.57 KB 3.58 KB NODE_PROD
react-dom-unstable-fizz.node.production.min.js 0.0% 🔺+0.3% 1.21 KB 1.21 KB 697 B 699 B NODE_PROD

react-native-renderer

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
ReactFabric-prod.js 🔺+2.1% 🔺+2.9% 268.98 KB 274.7 KB 46.11 KB 47.43 KB RN_FB_PROD
ReactNativeRenderer-dev.js +1.4% +1.7% 749.57 KB 759.93 KB 158.71 KB 161.37 KB RN_OSS_DEV
ReactFabric-profiling.js +2.0% +2.5% 279.11 KB 284.77 KB 47.99 KB 49.17 KB RN_FB_PROFILING
ReactNativeRenderer-prod.js 🔺+2.1% 🔺+2.3% 277.32 KB 283.04 KB 47.54 KB 48.62 KB RN_FB_PROD
ReactNativeRenderer-profiling.js +2.0% +2.3% 286.28 KB 291.94 KB 49.27 KB 50.39 KB RN_FB_PROFILING
ReactFabric-dev.js +1.4% +1.7% 754.99 KB 765.34 KB 159.53 KB 162.2 KB RN_OSS_DEV
ReactFabric-prod.js 🔺+2.1% 🔺+2.9% 268.63 KB 274.35 KB 46.04 KB 47.35 KB RN_OSS_PROD
ReactFabric-profiling.js +2.0% +2.5% 278.76 KB 284.43 KB 47.92 KB 49.09 KB RN_OSS_PROFILING
ReactFabric-dev.js +1.4% +1.7% 755.17 KB 765.52 KB 159.61 KB 162.28 KB RN_FB_DEV
ReactNativeRenderer-prod.js 🔺+2.1% 🔺+2.3% 276.93 KB 282.65 KB 47.47 KB 48.54 KB RN_OSS_PROD
ReactNativeRenderer-profiling.js +2.0% +2.3% 285.89 KB 291.56 KB 49.2 KB 50.32 KB RN_OSS_PROFILING
ReactNativeRenderer-dev.js +1.4% +1.7% 749.75 KB 760.1 KB 158.79 KB 161.45 KB RN_FB_DEV

react-test-renderer

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-test-renderer.development.js +1.6% +2.0% 618.49 KB 628.6 KB 131.85 KB 134.51 KB UMD_DEV
react-test-renderer.production.min.js 🔺+2.0% 🔺+2.6% 71.65 KB 73.07 KB 21.95 KB 22.51 KB UMD_PROD
ReactTestRenderer-dev.js +1.6% +2.1% 629.3 KB 639.65 KB 131.05 KB 133.74 KB FB_WWW_DEV
react-test-renderer-shallow.development.js 0.0% 0.0% 39.11 KB 39.11 KB 10.01 KB 10.01 KB UMD_DEV
react-test-renderer-shallow.production.min.js 0.0% 🔺+0.1% 11.6 KB 11.6 KB 3.58 KB 3.58 KB UMD_PROD
react-test-renderer-shallow.development.js 0.0% 0.0% 33.07 KB 33.07 KB 8.54 KB 8.54 KB NODE_DEV
react-test-renderer-shallow.production.min.js 0.0% 🔺+0.1% 11.73 KB 11.73 KB 3.69 KB 3.69 KB NODE_PROD
react-test-renderer.development.js +1.6% +2.1% 613.76 KB 623.87 KB 130.66 KB 133.35 KB NODE_DEV
react-test-renderer.production.min.js 🔺+2.0% 🔺+3.0% 71.35 KB 72.78 KB 21.56 KB 22.21 KB NODE_PROD

react-art

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
ReactART-dev.js +1.7% +2.1% 617.63 KB 627.99 KB 128.49 KB 131.15 KB FB_WWW_DEV
ReactART-prod.js 🔺+2.4% 🔺+2.5% 236.04 KB 241.78 KB 39.79 KB 40.79 KB FB_WWW_PROD
react-art.development.js +1.5% +1.8% 673.59 KB 683.69 KB 146.16 KB 148.85 KB UMD_DEV
react-art.production.min.js 🔺+1.3% 🔺+1.6% 106.67 KB 108.09 KB 32.42 KB 32.92 KB UMD_PROD
react-art.development.js +1.7% +2.1% 604.22 KB 614.32 KB 128.77 KB 131.43 KB NODE_DEV
react-art.production.min.js 🔺+2.0% 🔺+2.6% 71.64 KB 73.07 KB 21.48 KB 22.04 KB NODE_PROD

react-reconciler

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-reconciler-persistent.development.js +1.7% +2.1% 602.71 KB 612.82 KB 126.86 KB 129.54 KB NODE_DEV
react-reconciler-persistent.production.min.js 🔺+2.0% 🔺+2.9% 72.4 KB 73.83 KB 21.35 KB 21.97 KB NODE_PROD
react-reconciler-reflection.production.min.js 0.0% 🔺+0.1% 2.86 KB 2.86 KB 1.24 KB 1.24 KB NODE_PROD
react-reconciler.development.js +1.7% +2.1% 605.24 KB 615.35 KB 127.96 KB 130.61 KB NODE_DEV
react-reconciler.production.min.js 🔺+1.9% 🔺+2.6% 74.67 KB 76.1 KB 21.9 KB 22.47 KB NODE_PROD

ReactDOM: size: 0.0%, gzip: 0.0%

Size changes (experimental)

Generated by 🚫 dangerJS against 162454b

@sizebot
Copy link

sizebot commented Nov 20, 2019

Details of bundled changes.

Comparing: a7d07ff...162454b

react-reconciler

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-reconciler.production.min.js 🔺+2.0% 🔺+2.9% 72.37 KB 73.8 KB 21.34 KB 21.95 KB NODE_PROD
react-reconciler-reflection.production.min.js 0.0% 🔺+0.1% 2.85 KB 2.85 KB 1.24 KB 1.24 KB NODE_PROD
react-reconciler-persistent.development.js +1.7% +2.1% 602.7 KB 612.8 KB 126.85 KB 129.53 KB NODE_DEV
react-reconciler-persistent.production.min.js 🔺+2.0% 🔺+2.9% 72.38 KB 73.81 KB 21.34 KB 21.96 KB NODE_PROD
react-reconciler.development.js +1.7% +2.1% 605.23 KB 615.33 KB 127.95 KB 130.61 KB NODE_DEV

react-dom

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-dom-unstable-native-dependencies.production.min.js 0.0% 🔺+0.1% 10.46 KB 10.46 KB 3.57 KB 3.57 KB NODE_PROD
react-dom.development.js +1.1% +1.2% 953.92 KB 964.03 KB 215.69 KB 218.3 KB UMD_DEV
react-dom-server.browser.production.min.js 0.0% 0.0% 19.85 KB 19.85 KB 7.38 KB 7.38 KB NODE_PROD
react-dom-unstable-fizz.browser.development.js 0.0% +0.2% 3.87 KB 3.87 KB 1.54 KB 1.54 KB UMD_DEV
react-dom.production.min.js 🔺+1.2% 🔺+1.7% 116.18 KB 117.59 KB 37.45 KB 38.07 KB UMD_PROD
react-dom-unstable-fizz.browser.production.min.js 0.0% 🔺+0.3% 1.2 KB 1.2 KB 702 B 704 B UMD_PROD
react-dom.profiling.min.js +1.2% +1.6% 119.75 KB 121.17 KB 38.55 KB 39.18 KB UMD_PROFILING
react-dom.development.js +1.1% +1.2% 947.99 KB 958.09 KB 214.11 KB 216.73 KB NODE_DEV
react-dom-unstable-fizz.browser.development.js 0.0% +0.2% 3.7 KB 3.7 KB 1.49 KB 1.5 KB NODE_DEV
react-dom.production.min.js 🔺+1.2% 🔺+1.6% 116.29 KB 117.72 KB 36.86 KB 37.44 KB NODE_PROD
react-dom-unstable-native-dependencies.development.js 0.0% 0.0% 60.13 KB 60.13 KB 15.79 KB 15.79 KB UMD_DEV
react-dom-unstable-fizz.browser.production.min.js 0.0% 🔺+0.3% 1.04 KB 1.04 KB 633 B 635 B NODE_PROD
react-dom.profiling.min.js +1.2% +1.5% 119.98 KB 121.42 KB 37.86 KB 38.43 KB NODE_PROFILING
react-dom-unstable-native-dependencies.production.min.js 0.0% 🔺+0.1% 10.72 KB 10.72 KB 3.67 KB 3.67 KB UMD_PROD
react-dom-unstable-native-dependencies.development.js 0.0% 0.0% 59.8 KB 59.8 KB 15.66 KB 15.66 KB NODE_DEV
react-dom-server.node.development.js 0.0% -0.0% 137.48 KB 137.48 KB 36.13 KB 36.13 KB NODE_DEV
react-dom-test-utils.development.js 0.0% 0.0% 56.2 KB 56.2 KB 15.55 KB 15.55 KB UMD_DEV
react-dom-server.node.production.min.js 0.0% 0.0% 20.26 KB 20.26 KB 7.53 KB 7.53 KB NODE_PROD
react-dom-test-utils.production.min.js 0.0% 🔺+0.1% 11.17 KB 11.17 KB 4.14 KB 4.14 KB UMD_PROD
react-dom-unstable-fizz.node.development.js 0.0% +0.1% 4.4 KB 4.4 KB 1.64 KB 1.64 KB NODE_DEV
react-dom-server.browser.development.js 0.0% -0.0% 140.44 KB 140.44 KB 36.91 KB 36.91 KB UMD_DEV
react-dom-unstable-fizz.node.production.min.js 0.0% 🔺+0.3% 1.2 KB 1.2 KB 689 B 691 B NODE_PROD
react-dom-server.browser.production.min.js 0.0% 0.0% 19.93 KB 19.93 KB 7.38 KB 7.39 KB UMD_PROD

react-art

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-art.development.js +1.5% +1.8% 673.56 KB 683.67 KB 146.16 KB 148.84 KB UMD_DEV
react-art.production.min.js 🔺+1.4% 🔺+1.7% 104.59 KB 106.01 KB 31.82 KB 32.37 KB UMD_PROD
react-art.development.js +1.7% +2.1% 604.2 KB 614.3 KB 128.77 KB 131.42 KB NODE_DEV
react-art.production.min.js 🔺+2.1% 🔺+2.9% 69.61 KB 71.04 KB 21.03 KB 21.64 KB NODE_PROD

react-test-renderer

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-test-renderer.development.js +1.6% +2.0% 618.47 KB 628.57 KB 131.84 KB 134.5 KB UMD_DEV
react-test-renderer.production.min.js 🔺+2.0% 🔺+2.6% 71.62 KB 73.04 KB 21.93 KB 22.5 KB UMD_PROD
react-test-renderer.development.js +1.6% +2.1% 613.74 KB 623.84 KB 130.65 KB 133.34 KB NODE_DEV
react-test-renderer.production.min.js 🔺+2.0% 🔺+3.0% 71.33 KB 72.76 KB 21.54 KB 22.19 KB NODE_PROD
react-test-renderer-shallow.development.js 0.0% 0.0% 39.1 KB 39.1 KB 10 KB 10 KB UMD_DEV
react-test-renderer-shallow.production.min.js 0.0% 🔺+0.1% 11.58 KB 11.58 KB 3.57 KB 3.58 KB UMD_PROD
react-test-renderer-shallow.development.js 0.0% 0.0% 33.05 KB 33.05 KB 8.53 KB 8.53 KB NODE_DEV
react-test-renderer-shallow.production.min.js 0.0% 🔺+0.1% 11.72 KB 11.72 KB 3.68 KB 3.68 KB NODE_PROD

react-native-renderer

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
ReactNativeRenderer-dev.js +1.4% +1.7% 749.74 KB 760.09 KB 158.78 KB 161.45 KB RN_FB_DEV
ReactNativeRenderer-prod.js 🔺+2.1% 🔺+2.3% 277.31 KB 283.03 KB 47.54 KB 48.61 KB RN_FB_PROD
ReactNativeRenderer-profiling.js +2.0% +2.3% 286.26 KB 291.93 KB 49.26 KB 50.38 KB RN_FB_PROFILING
ReactFabric-dev.js +1.4% +1.7% 755.16 KB 765.51 KB 159.61 KB 162.27 KB RN_FB_DEV
ReactFabric-prod.js 🔺+2.1% 🔺+2.9% 268.96 KB 274.69 KB 46.1 KB 47.42 KB RN_FB_PROD
ReactFabric-profiling.js +2.0% +2.5% 279.1 KB 284.76 KB 47.98 KB 49.16 KB RN_FB_PROFILING
ReactNativeRenderer-dev.js +1.4% +1.7% 749.56 KB 759.91 KB 158.7 KB 161.36 KB RN_OSS_DEV
ReactNativeRenderer-prod.js 🔺+2.1% 🔺+2.3% 276.92 KB 282.64 KB 47.46 KB 48.53 KB RN_OSS_PROD
ReactNativeRenderer-profiling.js +2.0% +2.3% 285.88 KB 291.54 KB 49.19 KB 50.31 KB RN_OSS_PROFILING
ReactFabric-dev.js +1.4% +1.7% 754.97 KB 765.33 KB 159.52 KB 162.19 KB RN_OSS_DEV
ReactFabric-prod.js 🔺+2.1% 🔺+2.9% 268.62 KB 274.34 KB 46.03 KB 47.34 KB RN_OSS_PROD
ReactFabric-profiling.js +2.0% +2.5% 278.75 KB 284.42 KB 47.91 KB 49.08 KB RN_OSS_PROFILING

ReactDOM: size: 🔺+1.2%, gzip: 🔺+1.7%

Size changes (stable)

Generated by 🚫 dangerJS against 162454b

@acdlite acdlite force-pushed the transitions branch 2 times, most recently from ce6ac38 to 10ea752 Compare November 21, 2019 00:08
When multiple transitions update the same queue, only the most recent
one should be allowed to finish. Do not display intermediate states.

For example, if you click on multiple tabs in quick succession, we
should not switch to any tab that isn't the last one you clicked.
@@ -1299,6 +1309,16 @@ function handleError(root, thrownValue) {
stopProfilerTimerIfRunningAndRecordDelta(workInProgress, true);
}

// TODO: I think it's fine to use instanceof here because this exception
// is always thrown by the renderer? Or use a brand check.
if (thrownValue instanceof SuspendOnTask) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@sebmarkbage I assume you won't like this but I legit don't know what the best approach is. A brand check seems unnecessary since this is always thrown by the renderer and not across realms or packages.

@acdlite acdlite marked this pull request as ready for review November 21, 2019 06:46
@acdlite
Copy link
Collaborator Author

acdlite commented Nov 21, 2019

For some reason the CodeSandbox CI job didn't run? Perhaps because I opened it as a draft? I'm going to close and re-open to see if that works.

@acdlite acdlite closed this Nov 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants