-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Capture state changes scheduled between render and effect (#38509)
* Add failing useSelect test case when state updates before subscription In the event that a child component dispatched an action modifying the store, the changes in the store were lost due to `useSelect`'s `useIsomorphicLayoutEffect` referencing a stale value. * Capture state changes before useSelect subscription In the event that a child component dispatched an action modifying the store, the changes in the store were lost due to `useSelect`'s `useIsomorphicLayoutEffect` referencing a stale value. This change ensures the `useIsomorphicLayoutEffect` references the latest `mapOutput` when setting the related `latestMapOutput.current` value. * Revert native editor workaround for stale useSelect value Store updates triggered from within the post title component's `componentDidUpdate` hook resulted in stale `isTitledSelected` values returned from the memoized `useSelect`. This reverts a workaround that avoided memoization by splitting the `useSelect` hook usage in two. * refactor: Simplify and improve useSelect test * refactor: Delay mapping selector output until selector is called This avoids stale mappings overwriting new values in specific contexts where `onStoreChange` updates the value before the effect writes the original mapping. * fix: Rename test description This test focuses upon the order in which state is read and written. It is not related to when the subscription is set. * refactor: Group related selector output mapping logic Reduce cognitive load of code by grouping related logic.
- Loading branch information
Showing
3 changed files
with
84 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters