[internal] Update the hook value when store/arguments change - #4866
Conversation
commit: |
Bundle size
PerformanceTotal duration: 1,194.71 ms +54.22 ms(+4.8%) | Renders: 50 (+0) | Paint: 1,821.51 ms +75.65 ms(+4.3%) No significant changes — 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. |
21ba704 to
0f81b48
Compare
42ab8c8 to
3eb568a
Compare
|
@atomiks |
| hook.a2 = a2; | ||
| hook.a3 = a3; | ||
| hook.didChange = true; | ||
| hook.value = selector(store.getSnapshot(), a1, a2, a3); |
There was a problem hiding this comment.
This was an optimization because we have complex memoized selectors (in the MUI X repository), so avoiding running the selectors is desirable. It's indeed a bug to avoid it here, and the behavior was relying on react updating in response to our getSnapshot() (instance.syncTick) changing.
I will investigate avoiding the double selector call (here and in getSnapshot()) by keeping a copy of the snapshot on the hook, but in a different PR. The gains may not be worth the bookkeeping cost for some/all components.
|
Thanks for the PR! |
Co-authored-by: Rom Grk <romgrk@users.noreply.github.com>
This PR fixes an issue where
useStoreFastreturns a stale value when selector arguments changes during render.This was not an issue in all test cases and dev mode because of the
StrictMode, but was causing issues in production build.ex: MenuTrigger in the Menu hero demo does not update
aria-expanded.https://base-ui.com/react/components/menu