Repository navigation
[toast] Introduce a store - #3464
Conversation
commit: |
Bundle size report
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. |
e036c1b to
529e85e
Compare
97a71e8 to
728c2c3
Compare
| return ( | ||
| <ToastViewportContext.Provider value={contextValue}> | ||
| {numToasts > 0 && prevFocusElement && <FocusGuard onFocus={handleFocusGuard} />} | ||
| <React.Fragment> |
There was a problem hiding this comment.
This context was never used.
But if we need viewportRef, we can now use useToastContext since it's stable accross render 👌
| resumeTimers, | ||
| viewportRef, | ||
| windowFocusedRef, | ||
| setFocused, |
There was a problem hiding this comment.
For me the logic still works here but I would like a double check 👀
|
I'd rather not include this in v1. Introducing a Store to other components usually came with a couple of subtle bugs, so let's test it without rushing after the release. |
Clearly, I'm not in favor of rushing anything before the stable, unless the gains are huge 👍 |
|
@michaldudak this PR is ready for another round of review 🙏 |
|
Review by Codex: The new |
|
@michaldudak I think the did the review before this morning's fix. Analysis updateToast(id: string, updates: ToastManagerUpdateOptions) { The Fix (Already Applied) Cancels timers when timeout: 0 is set or type changes to loading Verdict timeout: 0 → positive value: starts auto-dismiss timer |
|
Yup, Codex agrees, it's fixed :) |
michaldudak
left a comment
There was a problem hiding this comment.
Just one nit. Besides that it looks good to me
atomiks
left a comment
There was a problem hiding this comment.
Codex review:
ToastManagerUpdateOptions now allows internal-only fields (ref, height, transitionStatus, limited) because it’s Partial<Omit<ToastObject, 'id'>>. That expands the public API and lets consumers put the toast into invalid states. Consider keeping the public type narrow (as before) and using an internal update type/method for ToastRoot height updates.
Some optimizations as well we could do:
- Update
createToastManagerto useSetinstead of an array - Limit handling still does multiple passes and closeToast does indexOf inside map (O(n²)). This is a hot path and was one of the perf fixes we made; it can be a single pass with an active index counter
- updateToast always calls
setToastsbefore checking whether the toast exists. If an update races with removal (or uses a stale id), this becomes a no‑op state update that still forces subscriptions to re-run. Move the prevToast null check ahead of setToasts or gate ontoastIndex !== -1.
Fixes #3922
This should not be part of the stable release it can be reviewed after 👍
ToastProvideruseStableCallback