feat: remove uSES usages and support strict mode #86
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
React 18 broke
useAtomSelector
in strict mode. This is because of lots of quirks withuseSyncExternalStore
that I coded circles around in React 17.Stop fighting with
useSyncExternalStore
. It still has many quirks, doesn't solve any of the problems we wanted it to solve, and most importantly looks to be poorly supported by the React team - for example, transitions will likely never be supported.Remove
useSyncExternalStore
usages. Instead,useAtomInstance
, handling strict mode double-renders and double-effect-invocations specifically. The impure operations are completely idempotent since generated ids are consistent for a given component thanks touseId
useEffect
inEcosystemProvider
useAtomSelector
and then cache and destroy them in a very simpleuseEffect
callThese changes make use of the new
useId
hook, which I believe was released in React 18, so we'd need a shim (or manual handling) to support React 17 again, though I don't think that's a very high priority - most people should be off React 17 by now.@affects atoms, react
Issues
Resolves #83 -
useAtomSelector
is completely rewritten, cleaner, and should have no problems in strict mode in React 18Closes #73 - this PR incorporates those changes, using the forbidden React internals only for improving Dev X and falling back to generating names if React does change their internals.