[toast] Remove memoized selector#4751
Conversation
commit: |
Bundle size
PerformanceTotal duration: 1,288.11 ms 🔺+67.25 ms(+5.5%) | Renders: 50 (+0) | Paint: 1,953.97 ms 🔺+95.19 ms(+5.1%)
…and 7 more — 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. |
5889cae to
0f0046a
Compare
There was a problem hiding this comment.
Pull request overview
This PR removes Toast’s dependency on a memoized selector (createSelectorMemoized / reselect) by precomputing and storing ID-indexed toast metadata in the ToastStore state whenever the toast list changes, keeping lookups fast without selector-level memoization.
Changes:
- Removed
createSelectorMemoized(and thereselectdependency) from@base-ui/utils/store. - Added
toastMetadata(aMap) toToastStorestate and recompute it whenevertoastschanges. - Added a Vitest test to ensure toast metadata stays synchronized across common toast mutations.
Reviewed changes
Copilot reviewed 6 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| pnpm-lock.yaml | Removes reselect from the utils importer section (but needs full lock regen). |
| packages/utils/src/store/index.ts | Stops exporting createSelectorMemoized. |
| packages/utils/src/store/createSelectorMemoized.ts | Deletes the memoized selector implementation that depended on reselect. |
| packages/utils/src/store/createSelector.ts | Drops reselect type import and replaces it with a local selector type. |
| packages/utils/package.json | Removes reselect from dependencies. |
| packages/react/src/toast/store.ts | Stores toastMetadata in state and updates it whenever toasts mutate; updates selectors to read from metadata. |
| packages/react/src/toast/store.test.ts | Adds coverage for metadata synchronization after toast mutations. |
Files not reviewed (1)
- pnpm-lock.yaml: Language not supported
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| '@floating-ui/utils': | ||
| specifier: ^0.2.11 | ||
| version: 0.2.11 | ||
| reselect: | ||
| specifier: ^5.1.1 | ||
| version: 5.1.1 | ||
| use-sync-external-store: | ||
| specifier: ^1.6.0 | ||
| version: 1.6.0(react@19.2.5) |
flaviendelangle
left a comment
There was a problem hiding this comment.
We are using createSelectorMemoized heavily in advanced components (MUI X and Base), what is the proposed alternative here?
If it's still needed externally, we can leave it in the package. But it wasn't necessary for Toast or any other component and adds needless bundle size, so it feels like a waste to have the |
|
I think we should leave it in the package, because it's the only centralized place we have to easily import it from everything without duplicating, even if it means keeping For Toast specifically, if we can have the same performances without the bundle size cost, great 👍 |
0f0046a to
60f4638
Compare
|
@atomiks Please keep in mind that |
|
@romgrk I've kept the deps and memoized module after @flaviendelangle's review. I wasn't sure if it was being used elsewhere previously, but now I know
Looks like you were marked as a code reviewer here automatically. Since there are no changes to the utils package anymore, there shouldn't be any issue there |
|
👍 And if there are BUI-specific utils, they should actually go in |
Code Review (GPT-5.5 + Opus 4.7)Approve ✅ because the full Toast store diff keeps metadata synchronized across every affected mutation path, preserves behavior, and the test/typecheck evidence plus local benchmarking support the eager metadata tradeoff. 1. Bugs / Issues (None)Behavior Preservation AssessmentChecked constructor initialization, The new Performance AssessmentI reran a local Node microbenchmark against freshly fetched
The code confirms the underlying tradeoff: toast-list writes now rebuild metadata eagerly, while render/positioning selectors read from a direct Simplification and DRY AssessmentThis is a clean simplification. Repo Conventions / Cleanliness AssessmentThe new Test Coverage AssessmentValidated with |
Removes Toast's memoized selector use while keeping the ID-based toast metadata lookup fast.
Changes
createSelectorMemoizedandreselectin utils for other consumers.Performance
Local Node microbenchmark comparing upstream/master to this PR with 50 toasts:
The rebuild timing moved: upstream rebuilds lazily on the first selector read after a toast list change, while this PR rebuilds when the toast list is written. Toast lists are normally small in practice, so this is not a meaningful cost.