-
Notifications
You must be signed in to change notification settings - Fork 45.7k
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
useMutableSource hook #18000
useMutableSource hook #18000
Commits on Mar 10, 2020
-
useMutableSource() enables React components to safely and efficiently read from a mutable external source in Concurrent Mode. The API will detect mutations that occur during a render to avoid tearing and it will automatically schedule updates when the source is mutated. RFC: reactjs/rfcs#147
Brian Vaughn committedMar 10, 2020 Configuration menu - View commit details
-
Copy full SHA for 0eb26dd - Browse repository at this point
Copy the full SHA 0eb26ddView commit details -
Refactored useMutableSource to use update queue
This commit changes useMutableSource to use an update queue by composing useEffect and useState internally. This ended up being a little bigger than I would have expected due to the need to create mount, update, and rerender implementations, but that's probably okay for now. This commit also makes a few orthogonal changes as the result of discussions with Relay, Redux, etc: 1. Snapshots are eagerly evaluated so components can bailout early even when 'scoped subscriptions' are not possible. 2. The subscribe callback function now expects to be passed the updated snapshot value.
Brian Vaughn committedMar 10, 2020 Configuration menu - View commit details
-
Copy full SHA for 8e751b2 - Browse repository at this point
Copy the full SHA 8e751b2View commit details -
Changed subscribe callback signature to not require the latest snapsh…
…ot value This is being done to reduce how frequently we potentially deopt during render. I also tidied up the useMutableSource mount/update/rerender implementations to reduce their overall file size.
Brian Vaughn committedMar 10, 2020 Configuration menu - View commit details
-
Copy full SHA for 06a571e - Browse repository at this point
Copy the full SHA 06a571eView commit details -
Handle errors that occur during eager snapshot evaluation
A selector might throw after a source mutation. e.g. it might try to read from a part of the store that no longer exists. In this case we should still schedule an update with React. Worst case the selector will throw again and then an error boundary will handle it.
Brian Vaughn committedMar 10, 2020 Configuration menu - View commit details
-
Copy full SHA for 2caa4e9 - Browse repository at this point
Copy the full SHA 2caa4e9View commit details -
Fixed a typo/bug in setState updater function
Brian Vaughn committedMar 10, 2020 Configuration menu - View commit details
-
Copy full SHA for 6263c97 - Browse repository at this point
Copy the full SHA 6263c97View commit details -
Avoid deopt on changed getSnapshot function unless snapshot also changes
getSnapshot should be memoized to only change when its inputs change, but if that memoization is done incorrectly (or if the new snapshot just happens to be the same regardless of a changed dependency) then we can avoid deopting to a root re-render.
Brian Vaughn committedMar 10, 2020 Configuration menu - View commit details
-
Copy full SHA for 905a9c0 - Browse repository at this point
Copy the full SHA 905a9c0View commit details -
Read mutable source composed hooks from current dispatcher
Rather than passing them in explicitly. This removes the extra function call.
Brian Vaughn committedMar 10, 2020 Configuration menu - View commit details
-
Copy full SHA for 112ace4 - Browse repository at this point
Copy the full SHA 112ace4View commit details -
Split useMutableSource tests into separate suite
Brian Vaughn committedMar 10, 2020 Configuration menu - View commit details
-
Copy full SHA for 6d1dd6a - Browse repository at this point
Copy the full SHA 6d1dd6aView commit details -
Refactor useMutableSource to be more efficient
Remove unnecessary useRef in favor of hook state. Directly mutate composed state hook queue to reset in the case of a new subscribe or source.
Brian Vaughn committedMar 10, 2020 Configuration menu - View commit details
-
Copy full SHA for 73b2628 - Browse repository at this point
Copy the full SHA 73b2628View commit details -
Added createMutableSource and useMutableSource exports to new ES entr…
…ypoints
Brian Vaughn committedMar 10, 2020 Configuration menu - View commit details
-
Copy full SHA for 5f37cba - Browse repository at this point
Copy the full SHA 5f37cbaView commit details -
Added React debug tools test for new hook
Brian Vaughn committedMar 10, 2020 Configuration menu - View commit details
-
Copy full SHA for 8f16725 - Browse repository at this point
Copy the full SHA 8f16725View commit details -
Added a (disabled) test to cover uSM throwing during sync update
Brian Vaughn committedMar 10, 2020 Configuration menu - View commit details
-
Copy full SHA for 8596425 - Browse repository at this point
Copy the full SHA 8596425View commit details -
Use a second effect to sync getSnapshot and stateHook values on commit
This prevents the subscription callback from closing over stale values.
Brian Vaughn committedMar 10, 2020 Configuration menu - View commit details
-
Copy full SHA for bf9025b - Browse repository at this point
Copy the full SHA bf9025bView commit details -
Always reset state queue when getSnapshot changes
Even if the current snapshot value is the same, there may be pending, lower priority updates that we no longer want to eventually render.
Brian Vaughn committedMar 10, 2020 Configuration menu - View commit details
-
Copy full SHA for 38a2044 - Browse repository at this point
Copy the full SHA 38a2044View commit details -
Always treat reads from source as unsafe when getSnapshot changes
I initially thought that we could treat them as safe if the returned snapshot value was the same, but this ignored the case where the underlying source was mutated between when the state update was scheduled and when the component later rendered with a new getSnapshot function. (This commit includes a test that failed without this fix.)
Brian Vaughn committedMar 10, 2020 Configuration menu - View commit details
-
Copy full SHA for bf8949e - Browse repository at this point
Copy the full SHA bf8949eView commit details -
Pass underlying source to getVersion fn
Brian Vaughn committedMar 10, 2020 Configuration menu - View commit details
-
Copy full SHA for f231a4b - Browse repository at this point
Copy the full SHA f231a4bView commit details -
Removed unused 'isMount' param from uMS
Brian Vaughn committedMar 10, 2020 Configuration menu - View commit details
-
Copy full SHA for 0c61fed - Browse repository at this point
Copy the full SHA 0c61fedView commit details -
1. Reset mutable source WIP version in complete and unwind work (rather than prepare fresh stack). 2. Add check to warn about multiple primary/secondary renderers using the same mutable source. (Patterned after our current context warning.) 3. Changed the way I'm calculating expiration time for mutated sources to use computeExpirationForFiber(). 4. Changed undefined unsubscribe function from invariant to warning. 5. Replaced !== checks with Object.is() checks to be more consistent with precedent. 6. Added a couple of new warning tests. (One of them has a pending TODO.)
Brian Vaughn committedMar 10, 2020 Configuration menu - View commit details
-
Copy full SHA for 160b0a5 - Browse repository at this point
Copy the full SHA 160b0a5View commit details -
Brian Vaughn committed
Mar 10, 2020 Configuration menu - View commit details
-
Copy full SHA for 7327787 - Browse repository at this point
Copy the full SHA 7327787View commit details -
Reenabled a pending disabled mutable source test
Brian Vaughn committedMar 10, 2020 Configuration menu - View commit details
-
Copy full SHA for 9c6dd03 - Browse repository at this point
Copy the full SHA 9c6dd03View commit details -
Removed createMutableSource and useMutableSource exports from React s…
…table release
Brian Vaughn committedMar 10, 2020 Configuration menu - View commit details
-
Copy full SHA for cd2ef30 - Browse repository at this point
Copy the full SHA cd2ef30View commit details -
Defer getWorkInProgressRoot() call unless root is needed
Brian Vaughn committedMar 10, 2020 Configuration menu - View commit details
-
Copy full SHA for 153a8f1 - Browse repository at this point
Copy the full SHA 153a8f1View commit details -
1. Use currentlyRenderingFiber to calculate expiration time rather than using a ref. 2. Use polyfilled is() rather than Object.is() 3. Add __EXPERIMENTAL__ guard to test since new APIs aren't in stable build 4. Removed error code that was changed to warning.
Brian Vaughn committedMar 10, 2020 Configuration menu - View commit details
-
Copy full SHA for 293aa74 - Browse repository at this point
Copy the full SHA 293aa74View commit details -
Replaced .warn() with .error() for mutable source unsubscribe check
Brian Vaughn committedMar 10, 2020 Configuration menu - View commit details
-
Copy full SHA for aa46144 - Browse repository at this point
Copy the full SHA aa46144View commit details -
Added an additional muti renderer test
If a mutation happens between the first and second renderer to use a source, we need to explicitly reset the source before restarting the second renderer.
Brian Vaughn committedMar 10, 2020 Configuration menu - View commit details
-
Copy full SHA for 0ef4bdb - Browse repository at this point
Copy the full SHA 0ef4bdbView commit details -
Added new failing tests (pending a separate fix to React)
Brian Vaughn committedMar 10, 2020 Configuration menu - View commit details
-
Copy full SHA for 45ed506 - Browse repository at this point
Copy the full SHA 45ed506View commit details
Commits on Mar 11, 2020
-
Merged master and resolved useEvent conflicts
I am being a little lazy here and merging instead of rebasing because practically every commit conflicted with Dominic's recent useEvent PR. If anyone feel strongly about this, I will revert the commit and rebase. Since the commit will be squashes away during the merge though, I don't think it matters much at this point.
Brian Vaughn committedMar 11, 2020 Configuration menu - View commit details
-
Copy full SHA for dee1164 - Browse repository at this point
Copy the full SHA dee1164View commit details