Skip to content

[toast] Accept an updater function in the update method instead of on data - #5629

Merged
michaldudak merged 4 commits into
mui:masterfrom
michaldudak:claude/pr-5611-non-breaking-e554e0
Sep 4, 2026
Merged

michaldudak merged 4 commits into
mui:masterfrom
michaldudak:claude/pr-5611-non-breaking-e554e0

Conversation

@michaldudak

Copy link
Copy Markdown
Member

Follow-up to #5611.

Problem

#5611 made a function passed as data to update(), or to the loading/success/error options of promise(), act as an updater. Since Data extends object admits function types, that is a breaking change against 1.7.0 for any Data that is itself a function: a value that used to be stored is now called, and the added conditional type turns existing update(id, { data: fn }) calls into compile errors.

Change

The functional form moves from the data option to the update method itself. The second argument of update was always an object before, so accepting a function there is purely additive:

toastManager.update(id, (prevToast) => ({
  title: 'Upload complete',
  data: { ...prevToast.data, progress: 100 },
}));
  • ToastManagerUpdateOptions.data is back to the 1.7.0 declaration, Data | undefined, and is always stored as a value. The conditional type rejecting callable Data and the resolveData step on the promise loading path are removed.
  • The updater receives the whole current toast, so any field can be derived from the previous state, not only data. Fields left out of the returned object are untouched, as with the object form.
  • updateToast looks the toast up first and returns early if it is missing or ending, so an ignored update never runs the updater. The internal update re-reads state afterwards, keeping the "updater calls back into the store" cases from [toast] Replace custom data wholesale and accept a function to derive it #5611 working.
  • The update event emitted by createToastManager now carries { id, updates } since a function cannot be spread. Both sides live in the same package.
  • The updater type is inlined in the three signatures rather than exported under a name, because the API docs generator listed a named function type as if it were a hook.

Compatibility

Every call that compiled in 1.7.0 compiles and behaves the same, including update(id, { data: fn }) for a callable Data. The only addition is the function form of update's second argument.

Tests

store.test.ts covers deriving title and data from the previous toast, receiving a toast without data, a function passed as data being stored rather than called, no updater call for a missing or ending toast, add and close from inside the updater, and function values surviving the promise loading and success paths. Type specs assert the type of prevToast.data in the updater, that an incomplete returned data is an error, and that a callable Data is accepted directly on update and promise.

Typecheck, eslint, the full toast suite in jsdom, and the store tests in Chromium pass.

🤖 Generated with Claude Code

… data

Passing a function as custom data to update() or promise() was treated as an
updater in mui#5611, which changed the behavior for any Data that is itself a
function type compared to 1.7.0. Move the functional form to the update method
itself: update(id, (prevToast) => options). The options argument was never a
function before, so this is additive, and data is a plain value again.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@pkg-pr-new

pkg-pr-new Bot commented Sep 3, 2026 •

Copy link
Copy Markdown
  • base-ui-tanstack-start

  • vite-css-base-ui-example

    pnpm add https://pkg.pr.new/mui/base-ui/@base-ui/react@5629
    
    pnpm add https://pkg.pr.new/mui/base-ui/@base-ui/utils@5629
    

commit: ed3ff5a

@code-infra-dashboard

code-infra-dashboard Bot commented Sep 3, 2026 •

Copy link
Copy Markdown

Bundle size

Bundle Parsed size Gzip size
@base-ui/react ▼-112B(-0.02%) ▼-30B(-0.02%)

Details of bundle changes

Performance

Total duration: 1,312.77 ms +200.00 ms(+18.0%) | Renders: 76 (+0) | Paint: 2,104.88 ms +298.11 ms(+16.5%)

Test Duration Renders
Slider mount (300 instances) 155.90 ms 🔺+28.22 ms(+22.1%) 2 (+0)
Select open (500 options) 70.93 ms 🔺+21.86 ms(+44.5%) 14 (+0)
Scroll Area mount (300 instances) 81.87 ms 🔺+21.63 ms(+35.9%) 3 (+0)
Menu open (500 items) 88.73 ms 🔺+20.47 ms(+30.0%) 11 (+0)
Combobox type — 500 items, narrows to ~11 (type "Row 25") 48.13 ms 🔺+14.91 ms(+44.9%) 15 (+0)

…and 2 more (+8 within noise) — details

Metric alarms

Test Metric Change
Slider mount (300 instances) bench:paint 🔺 +45.46 ms
Select open (500 options) bench:paint 🔺 +39.74 ms
Select open (500 options) bench:paint#select-open 🔺 +39.74 ms
Scroll Area mount (300 instances) bench:paint 🔺 +24.59 ms
Menu open (500 items) bench:paint 🔺 +35.39 ms

…and 5 more metric alarms — details


Check out the code infra dashboard for more information about this PR.

@netlify

netlify Bot commented Sep 3, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for base-ui ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit ed3ff5a
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/6a9a68a684779e00089a7da4
😎 Deploy Preview https://deploy-preview-5629--base-ui.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@michaldudak michaldudak added the component: toast Changes related to the toast component. label Sep 3, 2026
@michaldudak
michaldudak marked this pull request as ready for review September 3, 2026 15:53
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 3, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-04T06:28:38.837061Z bcd6659 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@aarongarciah aarongarciah left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR review

No merge-blocking issues. The runtime change is small and correct: updateToast guards missing/ending toasts before running the updater, the object form behaves exactly as in 1.7.0, and the restored ToastManagerUpdateOptions declaration matches the v1.7.0 tag byte for byte. Remaining findings are a test gap on the manager bridge and a docs example that regresses for typed Data.

Bugs (1)

1. ℹ️ An updater that returns nothing throws an opaque TypeError

Location: packages/react/src/toast/store.ts:221

typeof updates === 'function' ? updates(prevToast) : updates,

TypeScript rejects a void-returning updater, but the docs examples are jsx and JS consumers get no such guard. When the updater forgets to return, updateToastInternal receives undefined and Object.hasOwn(updates, 'timeout') at store.ts:259 throws TypeError: Cannot convert undefined or null to object from inside the store, with no Base UI: message pointing at the cause. Same failure the object form already has for update(id), so this only adds a second path to it.

Failure scenario: toastManager.update(id, (prev) => { prev.data.progress = 100; }) in a JS app throws a TypeError from store.ts instead of doing nothing or explaining what went wrong.

Fix: Optional. Either leave to the types (reasonable), or coalesce the result (updates(prevToast) ?? {}) so a forgotten return is a no-op update like React's setState semantics.

Tests (1)

1. 🟡 The function form is never driven through createToastManager and the provider bridge

Location: packages/react/src/toast/createToastManager.test.tsx:335

toastManager.update(toastId, {
  title: 'updated',
});

This PR changes the update event payload to { id, updates } and has ToastProvider forward options.updates verbatim. Every existing manager-level update test uses the object form, and store.test.ts covers the function form only on the store directly. Nothing asserts that a function passed to createToastManager().update survives the emit/subscribe hop and is called with the current toast. A later refactor that normalizes options in createToastManager.update (for example spreading it as the previous code did) would silently break the new public form while every test stays green.

Failure scenario: createToastManager().update(id, (prev) => ({ title: ${prev.title} updated })) regresses to a no-op or a thrown error at the bridge, undetected.

Fix: Add one case to the update describe block in createToastManager.test.tsx mirroring the existing test but passing (prev) => ({ title: ${prev.title} updated }), asserting the rendered title.

Docs (1)

1. 🟡 The updater example drops the no-data guard and fails to type-check with a typed Data

Location: docs/src/app/(docs)/react/components/toast/page.mdx:386

toastManager.update(toastId, (prevToast) => ({
  data: { ...prevToast.data, progress: 100 },
}));

prevToast.data is Data | undefined, so the spread makes every field of Data optional. With useToastManager<{ name: string; progress: number }>() the example fails with Type 'undefined' is not assignable to type 'string' on data.name (confirmed with tsc --strict); it only compiles for the default any or when progress is the sole field. The example this replaces (prevData && { ...prevData, progress: 100 }) handled exactly this. Runtime semantics also shifted: for a toast with no data, the new example creates { progress: 100 } instead of leaving data untouched.

Failure scenario: A TypeScript user with a typed Data copies the documented snippet and gets a compile error on data, with no hint that the guard is needed.

Fix: Restore the guard in the example: data: prevToast.data && { ...prevToast.data, progress: 100 }, or note in the prose that prevToast.data is undefined when the toast has no data yet.

Verdict

Approve after nits - no correctness regression; the manager-bridge test gap and the docs example's dropped undefined guard are worth fixing before merge.


🤖 Review generated with Claude Code

@jjenzz

jjenzz commented Sep 3, 2026

Copy link
Copy Markdown
Member

i even prefer this API tbh, nice 👍

@atomiks atomiks left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks correct; only found the @aarongarciah docs issue

@michaldudak
michaldudak merged commit dd13809 into mui:master Sep 4, 2026
24 checks passed
@michaldudak
michaldudak deleted the claude/pr-5611-non-breaking-e554e0 branch September 4, 2026 07:05
arturbien added a commit to whopio/frosted-ui that referenced this pull request Sep 8, 2026
## Summary

Upgrades `@base-ui/react` from `^1.7.0` → `^1.8.0` (latest, published
Sep 4, 2026).

No Frosted UI source changes were required. Validated locally:
- `tsc` (CJS + ESM) ✅
- `eslint` + `stylelint` ✅
- `vitest` — 312/312 tests passing ✅

Sources: [Base UI v1.8.0 release
notes](https://base-ui.com/react/overview/releases/v1-8-0), [GitHub
CHANGELOG](https://github.com/mui/base-ui/blob/master/CHANGELOG.md).

---

## Breaking changes

**Official changelog marks no breaking changes in v1.8.0.**

A few behavioral / API additions consumers (and Frosted UI wrappers)
should be aware of:

| Area | Change |
|---|---|
| Avatar | New `keepMounted` prop on `<Avatar.Image>`
([#5536](mui/base-ui#5536)) — Frosted already
forwards image props, so this is available automatically |
| Combobox | New `createItems` collection API
([#5326](mui/base-ui#5326)) |
| Toast | `update()` can take a function derived from the current toast
([#5464](mui/base-ui#5464),
[#5611](mui/base-ui#5611),
[#5629](mui/base-ui#5629)) |
| Autocomplete / Combobox / Select | Popup can open and be browsed while
`readOnly` ([#5541](mui/base-ui#5541),
[#5531](mui/base-ui#5531)) |
| Navigation Menu | Focus stays on the trigger when opening
([#5479](mui/base-ui#5479)) |
| Field | Neutral validity is published while async validation is in
flight ([#5600](mui/base-ui#5600)) |
| Dialog / Alert Dialog / Popover | Outside clicks from presses that
began before open are ignored
([#5378](mui/base-ui#5378)) |
| Scroll Area | Scrollbars no longer steal focus
([#5430](mui/base-ui#5430)) |

### Frosted UI impact assessment

| Concern | Status |
|---|---|
| Compile / typecheck against 1.8.0 | Passes with no source edits |
| Existing `DialogRootActions` / `AlertDialogRootActions` imports |
Still exported |
| `useRender` / `mergeProps` | Unchanged public surface |
| Toast manager `update()` | Still compatible; functional updates are
additive |
| Combobox `useFilter` re-export | Still present |

---

## Full v1.8.0 changelog (from
[upstream](https://base-ui.com/react/overview/releases/v1-8-0))

_Sep 4, 2026_

### General changes

- Fix label association when a control unregisters (#5456)
- Reduce animation completion work (#5535)
- Fix prop and ref merging for lazy render elements (#5562)
- Fix roving focus when items are added or removed (#5447)
- Fix hover and focus interaction issues (#5037)
- Improve trigger mount performance (#5426)
- Fix disabled anchor tracking on scroll (#5478)
- Fix transform origin for start/end alignment (#5015)
- Remove duplicate options key from arrow middleware (#5606)
- Register passive touch listeners (#5572)

### Alert Dialog

- Ignore outside clicks from presses that began before open (#5378)

### Autocomplete

- Render groups with the rowgroup role in grid mode (#5564)
- Allow opening and browsing the popup while `readOnly` (#5541)
- Move `aria-orientation` to the role owners (#5551)
- Hide group labels and scrollbars from the accessibility tree (#5598)

### Avatar

- Add `keepMounted` prop to `<Avatar.Image>` (#5536)

### Checkbox

- Fix stale and duplicated control IDs (#5457)
- Fix controlled blur validation and stale filled state (#5563)

### Checkbox Group

- Fix stale and duplicated control IDs (#5457)

### Combobox

- Fix applying `data-readonly` to `<Combobox.Trigger>` (#5418)
- Add `createItems` collection API (#5326)
- Fix cancellation when preserving the filter after selection (#5362)
- Render groups with the rowgroup role in grid mode (#5564)
- Allow opening and browsing the popup while `readOnly` (#5541)
- Move `aria-orientation` to the role owners (#5551)
- Fix record item label lookup reading from `Object.prototype` (#5518)
- Anchor multiple selection to the first selected item with a linear
lookup (#5573, #5613)
- Hide group labels and scrollbars from the accessibility tree (#5598)

### Dialog

- Ignore outside clicks from presses that began before open (#5378)

### Drawer

- Ignore swipes without an attributed direction when using snap points
(#5477)
- Respect canceled snap point dismissal (#5571)
- Ignore the page scroller when starting a swipe (#5567)

### Field

- Fix custom validity ownership and validation lifecycle (#5449)
- Sync controlled value changes with field state (#5460)
- Fix stale and duplicated control IDs (#5457)
- Validate once on Enter inside a Form (#5459)
- Publish neutral validity while async validation is in flight (#5600)
- Fix controlled blur validation and stale filled state (#5563)

### Form

- Fix `clearErrors` dropping updates when multiple fields change at once
(#5446)

### Menu

- Play the enter transition for an initially open submenu (#4383)
- Move `aria-orientation` to the role owners (#5551)
- Hide group labels and scrollbars from the accessibility tree (#5598)

### Menubar

- Fix menubar accessibility tree to satisfy `aria-required-children`
(#5058)

### Navigation Menu

- Fix pointer-events lock when sweeping quickly across a trigger (#5454)
- Keep focus on trigger when opening (#5479)
- Add disabled data attribute to `<NavigationMenu.Trigger>` (#5521)

### Number Field

- Stop incrementing when disabled during press-and-hold (#5435)
- Prevent scrubbing on horizontal wheel events (#5463)
- Preserve native and consumer-controlled selection when focusing the
input (#5578, #5619)

### Popover

- Ignore outside clicks from presses that began before open (#5378)
- Fix detached trigger store migration (#5442)

### Scroll Area

- Hide group labels and scrollbars from the accessibility tree (#5598)
- Prevent scrollbars from stealing focus (#5430)

### Select

- Move `aria-orientation` to the role owners (#5551)
- Anchor multiple selection to the first selected item with a linear
lookup (#5573, #5613)
- Hide group labels and scrollbars from the accessibility tree (#5598)
- Fix the root ID being ignored inside a Field (#5461)
- Remove redundant size check in `<Select.Positioner>` (#5469)
- Allow opening and browsing the popup while `readOnly` (#5531)
- Fix record item label lookup reading from `Object.prototype` (#5518)

### Slider

- Prevent update loops from unstable refs (#5441)

### Switch

- Fix controlled blur validation and stale filled state (#5563)

### Tabs

- Prevent update loops from unstable refs (#5441)
- Consider 3D transforms when positioning the indicator (#4852)

### Toast

- Allow functional toast updates derived from the current toast (#5464,
#5611, #5629)

### Tooltip

- Respect trigger delay with zero provider delay (#5444)

---

## Test plan

- [x] Bump `@base-ui/react` to `^1.8.0` and refresh lockfile
- [x] `pnpm --filter=frosted-ui exec tsc --project tsconfig-esm.json
--noEmit`
- [x] `pnpm --filter=frosted-ui build:js` (CJS + ESM)
- [x] `pnpm --filter=frosted-ui lint`
- [x] `pnpm --filter=frosted-ui test` (312 tests)
- [x] CI green on this PR
- [ ] Spot-check Storybook surfaces that wrap Base UI heavily (Combobox,
Select, Dialog, Menu, Toast, Field) if desired before merge


Made with [Cursor](https://cursor.com)

Co-authored-by: Cursor <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component: toast Changes related to the toast component.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants