[utils] Import Store changes from x-internals#4765
Conversation
commit: |
Bundle size
PerformanceTotal duration: 1,148.38 ms +56.22 ms(+5.1%) | Renders: 50 (+0) | Paint: 1,753.27 ms +89.49 ms(+5.4%)
11 tests within noise — details Check out the code infra dashboard for more information about this PR. |
✅ Deploy Preview for base-ui ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
| }, | ||
| }; | ||
|
|
||
| instance.subscribe(); |
There was a problem hiding this comment.
This creates a store subscription before the component commits. In concurrent rendering, an abandoned render will not run the useOnMount cleanup, leaving a listener for an instance that never mounted.
There was a problem hiding this comment.
Good catch. The useStoreEffect early subscription has always felt too hacky for my taste but it fixed initialization issues in some parts of the MUI X codebase. I'm going to remove the hook altogether from this PR and see if we can rework things there to get rid of it.
| ): void { | ||
| const instance = useRefWithInit(initialize, { store, selector }).current; | ||
| instance.effect = effect; | ||
| useOnMount(instance.onMount); |
There was a problem hiding this comment.
The hook updates only effect; initialize closes over the initial store and selector, and useOnMount never reruns. If a component receives a replacement store, or passes a selector that closes over props, updates continue to be computed from stale inputs while invoking the latest effect callback.
There was a problem hiding this comment.
JSDoc is stale after the arity change
There was a problem hiding this comment.
New public store behavior is effectively untested.
The only changed test line widens an existing nested-store type. The PR adds/exports useStoreEffect, Store.create, createSelectorMemoizedWithOptions, single-combiner handling in createSelectorMemoized, and expanded createSelector arity, but none of those behaviors have focused regression tests.
This PR imports the
Storechanges fromx-internalsin preparation for deleting the duplicated code from the MUI X repository.