Skip to content

[toast] Render content passed through the render prop in Title, Description, and Action - #5210

Merged
atomiks merged 8 commits into
mui:masterfrom
m2na7:fix/toast-render-prop-content
Jul 14, 2026
Merged

atomiks merged 8 commits into
mui:masterfrom
m2na7:fix/toast-render-prop-content

Conversation

@m2na7

@m2na7 m2na7 commented Jul 13, 2026 •

Copy link
Copy Markdown
Contributor

Description

Toast.Title, Toast.Description, and Toast.Action gate rendering on the presence of resolved children. When the part is provided through the render prop with content but no children — e.g. <Toast.Description render={<div>…</div>} />, the form in the #2809 repro — that content was dropped: shouldRender was false and the element (along with its aria-* wiring) never mounted.

The fix gates on the evaluated element's resolved children, which are the source of truth for content — a render element's / render function's own children win over the toast-supplied content in the merge. Whether resolved children count as content is decided by a shared isRenderableNode predicate matching React renderability: numeric/bigint children (including 0, 0n, and NaN) are content; nullish values, booleans, empty strings, and arrays containing only those are not. A React.isValidElement check guards render functions that return null, so the children lookup can't crash. So:

  • render={<div>…</div>} (carries content) mounts;
  • a childless, styling-only render={<MyHeading />} — where content comes from toast.title / add({ title }), or is intentionally empty — stays conditional and does not force-mount an empty element;
  • <Toast.Title render={<MyHeading />}>…</Toast.Title> (explicit children) mounts;
  • a plain {0} child now mounts, and an empty-array child no longer mounts an empty element.

On top of #5219's structure: useToastLabelPart keeps resolving the content, and a new useToastLabelElement gates mounting on the evaluated element and registers the part's id with the root only while it actually renders, keeping aria-labelledby / aria-describedby pointing at real nodes. Toast.Action drops the enabled option because render-prop content only exists once the element is evaluated.

Linked Issues

Closes #2809

Additional context

  • New shared util packages/react/src/toast/utils/isRenderableNode.ts, with the value-kind edge cases (0, empty/nested arrays, null-returning render functions) pinned in its unit tests; each part's suite covers its own call-site paths, including the childless styling-only case and the aria-* wiring/cleanup for a render-only part.
  • Supersedes [toast] Render content passed via the render prop in Action #5211 — with the gate shared across the three parts, the Toast.Action fix lives here.

@pkg-pr-new

pkg-pr-new Bot commented Jul 13, 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@5210
    
    pnpm add https://pkg.pr.new/mui/base-ui/@base-ui/utils@5210
    

commit: cd7c312

@code-infra-dashboard

code-infra-dashboard Bot commented Jul 13, 2026 •

Copy link
Copy Markdown

Bundle size

Bundle Parsed size Gzip size
@base-ui/react 🔺+165B(+0.04%) 🔺+70B(+0.05%)

Details of bundle changes

Performance

Total duration: 1,304.94 ms +125.93 ms(+10.7%) | Renders: 78 (+0) | Paint: 2,030.79 ms +188.20 ms(+10.2%)

Test Duration Renders
Slider mount (300 instances) 183.08 ms 🔺+31.96 ms(+21.2%) 3 (+0)
Select mount (200 instances) 174.29 ms 🔺+31.94 ms(+22.4%) 3 (+0)
Tooltip mount (300 contained roots) 58.32 ms 🔺+12.86 ms(+28.3%) 1 (+0)

11 tests within noise — details

Metric alarms

Test Metric Change
Select mount (200 instances) bench:paint 🔺 +40.88 ms
Tooltip mount (300 contained roots) bench:paint 🔺 +19.85 ms

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

@netlify

netlify Bot commented Jul 13, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit cd7c312
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/6a5626a6cf615f0008832bd4
😎 Deploy Preview https://deploy-preview-5210--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.

@m2na7
m2na7 force-pushed the fix/toast-render-prop-content branch from c73db6a to 6656ec8 Compare July 13, 2026 06:56
@atomiks atomiks added type: bug It doesn't behave as expected. component: toast Changes related to the toast component. labels Jul 13, 2026
…ption

Toast.Title and Toast.Description gated mounting on the presence of the
resolved children, so content supplied through the `render` prop with no
children was dropped: `shouldRender` was false and the component returned null
before the render prop element or function could mount.

Gate on the evaluated element's resolved children instead, so a `render` prop
that carries content (`render={<div>…</div>}`) mounts while a childless,
styling-only `render` (`render={<MyHeading />}`) stays conditional. A
render-only title/description also registers its id so the root's
aria-labelledby / aria-describedby stays wired.

Closes mui#2809
@m2na7
m2na7 force-pushed the fix/toast-render-prop-content branch from 6656ec8 to a9e92cf Compare July 13, 2026 07:07
@atomiks

atomiks commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

PR review

No merge-blocking .props, Suspense, RSC, or React-version issue. Both current heads—#5210 a9e92cf and #5211 c1edef0—now short-circuit with React.isValidElement(element).

Genuine React elements always contain a props object in React 18 and current React. A callback can return null at runtime, but the guard handles it. Only a manually forged internal $$typeof object could pass isValidElement without props; that is outside React’s supported contract.

Suspension occurs before the property read, and React retries suspended trees from scratch, so there is no partially initialized element. Client/Server Component JSX can cross a client boundary, while ordinary render callbacks cannot; they must originate in client code.

Local verification passed 44 Title/Description tests, TypeScript, SSR, and lazy/Suspense smoke testing. The React 18 CI job currently stops during dependency installation before running tests.

Bugs (1)

1. 🟡 Treat renderable children separately from truthiness

Location: packages/react/src/toast/title/ToastTitle.tsx:48, mirrored in ToastDescription.tsx:49 and PR #5211’s ToastAction.tsx:53

const shouldRender =
  React.isValidElement(element) &&
  Boolean((element.props as { children?: React.ReactNode }).children);

ReactNode renderability does not match JavaScript truthiness. Numeric 0, 0n, and NaN render visible text but are rejected here. Conversely, [] and [null] are truthy and mount an empty element.

Failure scenario: <Toast.Title render={<div>{count}</div>} /> disappears when count is 0, leaving the toast without its intended visible and accessible title.

Fix: Use a shared renderable-children predicate across Title, Description, and Action that preserves numeric/bigint children while filtering empty arrays, nullish values, booleans, and empty strings. Add 0 and empty-array coverage. This behavior predates these PRs for ordinary children, but the rewritten guard is the right place to correct it.

Tests (0)

No findings.

Simplifications (0)

No findings.

Docs (0)

No findings.

Verdict

Approve after nits - the only remaining issue is the narrow falsy-numeric children case.


🤖 Review generated with Codex

m2na7 added 3 commits July 13, 2026 16:46
…ntent

Boolean(children) rejected renderable-but-falsy content (0, 0n, NaN) and
accepted empty-but-truthy content ([], [null]). Use a shared isRenderableNode
predicate so a numeric render prop child such as render={<div>{0}</div>} mounts
while an empty array stays conditional.
Cover the ordinary-children behavior the renderability gate also changes
(a plain {0} child now mounts, an empty-array child no longer mounts an
empty element) and guard against a render function returning null crashing
the children lookup. Lock nested-array recursion in the shared predicate.
@m2na7

m2na7 commented Jul 13, 2026

Copy link
Copy Markdown
Contributor Author

Addressed with a shared isRenderableNode predicate (also used by Action in #5211): numeric/bigint children like 0 count as content; nullish values, booleans, empty strings, and empty arrays don't. Added 0 and empty-array coverage (render prop + plain children) and a regression test for a render function returning null.

@github-actions github-actions Bot added the PR: out-of-date The pull request has merge conflicts and can't be merged. label Jul 13, 2026
m2na7 added 2 commits July 14, 2026 11:00
…op-content

# Conflicts:
#	packages/react/src/toast/description/ToastDescription.tsx
#	packages/react/src/toast/title/ToastTitle.tsx
…iption, and Action

Title, Description, and Action decided whether to render from the raw
children prop, so content supplied through the render prop was dropped,
and renderable falsy children such as 0 never rendered.

Gate on the evaluated element instead: isRenderableNode() follows
React's rendering rules (nullish, booleans, empty strings, and empty
arrays produce no output; 0, 0n, and NaN do), and hasRenderableChildren()
applies it behind React.isValidElement so a render function returning
null renders nothing instead of throwing. Title and Description register
their ids with the root only while they actually render, keeping
aria-labelledby and aria-describedby pointing at real nodes. Action
drops the enabled option because render-prop content only exists once
the element is evaluated.

Closes mui#2809
@github-actions github-actions Bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged. label Jul 14, 2026
The renderability gate lives once in useToastLabelElement and
hasRenderableChildren, so value-kind variants (0, arrays, null-returning
render functions) are pinned in the shared unit tests while each part's
suite keeps only its own call-site paths. Add a regression test that
removing the title content clears aria-labelledby from the root.
@m2na7 m2na7 changed the title [toast] Render content passed via the render prop in Title and Description [toast] Render content passed through the render prop in Title, Description, and Action Jul 14, 2026
@m2na7

m2na7 commented Jul 14, 2026

Copy link
Copy Markdown
Contributor Author

@atomiks Updated the branch on top of #5219. The gate now lives in the shared layer (useToastLabelPart + a new useToastLabelElement that mounts on the evaluated element), and Toast.Action is folded in here via the same check, supersedes #5211. Also pinned the effect's cleanup (removing the title content clears aria-labelledby) and moved the value-kind edge cases into the isRenderableNode unit tests.

@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.

Gating each part on the evaluated element's resolved children is the right fix for #2809, and matches React renderability semantics. Added two tests pinning the Toast.Description render-prop paths (aria-describedby wiring and the childless styling-only fallback to toast.description). CI green.

@atomiks
atomiks merged commit ec5609b into mui:master Jul 14, 2026
7 checks passed
arturbien added a commit to whopio/frosted-ui that referenced this pull request Aug 6, 2026
<!-- CURSOR_AGENT_PR_BODY_BEGIN -->
## Summary

Upgrades `@base-ui/react` from `^1.6.0` → `^1.7.0` (latest as of Aug 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.7.0 release
notes](https://base-ui.com/react/overview/releases/v1-7-0), [GitHub
release](https://github.com/mui/base-ui/releases/tag/v1.7.0),
[CHANGELOG](https://github.com/mui/base-ui/blob/master/CHANGELOG.md).

---

## Breaking changes

**Official changelog marks no 🚨 breaking changes in v1.7.0.**

However, there are behavioral, API, and type changes consumers (and
Frosted UI wrappers) should be aware of:

### Behavioral / DOM changes (potentially breaking in practice)

1. **`Accordion.Root` no longer sets an implicit `dir` attribute**
([#5117](mui/base-ui#5117))
- Previously `Accordion.Root` wrote `dir` onto the root. Direction now
comes from the document / ancestor only.
- Impact: CSS/JS that depended on `Accordion.Root[dir]` may stop
matching. Pass `dir` explicitly if needed.

2. **`Combobox.Input` / `Autocomplete.Input` no longer inject
`type="text"`** ([#5104](mui/base-ui#5104))
- Native `<input>` still defaults to text, but the attribute is no
longer present in the DOM.
- Impact: selectors like `input[type="text"]` will no longer match
unless `type="text"` is passed explicitly.

3. **Listbox separators use `role="presentation"`**
([#5399](mui/base-ui#5399))
- `Select.Separator`, `Combobox.Separator`, and `Autocomplete.Separator`
no longer expose `role="separator"` (axe/ARC compliance).
- `Select.Separator` switched from a re-export of the generic
`Separator` to a dedicated listbox separator component.
   - Public props (`orientation`, etc.) are preserved.

4. **Checkbox Group / Radio Group form values aligned with native
submission** ([#5218](mui/base-ui#5218),
[#5238](mui/base-ui#5238))
- Form payload shape may change vs prior Base UI behavior. Verify any
custom form serialization that assumed the old values.

5. **Popup / overlay remount + handle reuse**
- Dialog, Alert Dialog, Drawer, Menu, Popover, Preview Card, Tooltip no
longer reopen after remounting with a reused handle
([#5109](mui/base-ui#5109),
[#5149](mui/base-ui#5149)).

6. **Disabled state inheritance**
- `Combobox.Item` / `Select.Item` inherit disabled from Root
([#5365](mui/base-ui#5365)).
- `Menu` propagates disabled state to items
([#5363](mui/base-ui#5363)).

7. **`Field` keeps invalid state when disabled**
([#5116](mui/base-ui#5116)).

8. **`Select` no longer force-mounts the popup on programmatic value
changes** ([#5119](mui/base-ui#5119)).

### API additions / changes

| Area | Change |
|---|---|
| Autocomplete / Combobox | New `ChangeEventReason` values:
`"input-press"`, `"cancel-open"`
([#5356](mui/base-ui#5356),
[#5376](mui/base-ui#5376)) |
| Autocomplete | New `form?: string` prop on Root (associates the
internal input with an external form) |
| Combobox | Exposes `aria-expanded` / expanded behavior for inline
comboboxes ([#5332](mui/base-ui#5332)) |
| Combobox / Autocomplete | New `.Separator` part |
| Select | Dedicated `.Separator` part (listbox-safe semantics) |
| Toast | `render` prop content now works on `Toast.Title`,
`Toast.Description`, `Toast.Action`
([#5210](mui/base-ui#5210)) |
| Modal docs | Touch-device modal scroll behavior clarified for Combobox
/ Select |

### Type changes

1. **`render` callback props specialized to the rendered element**
([#5104](mui/base-ui#5104))
- Third generic of `BaseUIComponentProps` now types callback props as
the intrinsic element for:
     - `Avatar.Image` → `'img'`
     - `Form` → `'form'`
     - `NumberField.Input` / `OTPField.Input` → `'input'`
- `PreviewCard.Trigger` / `Menu.LinkItem` / `NavigationMenu.Link` /
`Toolbar.Link` → `'a'`
- Polymorphic parts (e.g. `Combobox.Input`, `Field.Control`, button
parts via `nativeButton`) remain loosely typed as `HTMLProps`.
- May surface new TS errors if a `render` callback assumed looser props
(or the reverse: more precise props like `src`/`href` are now
available).

2. **Implementation-only types stripped from published `.d.ts`**
([#5165](mui/base-ui#5165))
   - `@internal` declarations are no longer emitted.
- Deep imports of internals (e.g. previously published helpers like
`FloatingFocusManager`, `useAnchorPositioning`, numeral utils, store
helpers) will fail typechecking if used.
   - Frosted UI does not depend on these internals.

3. **`AutocompleteRootChangeEventReason` /
`ComboboxRootChangeEventReason` union widened**
- Adds `"input-press"` and `"cancel-open"`. Exhaustive `switch`/`if`
chains over reasons may need updates.

4. **Internal path moves** (only relevant for deep imports)
- e.g. `useAnchorPositioning` moved under `internals/`; several utils
relocated/removed from the public declaration graph.

### Frosted UI impact assessment

| Concern | Status |
|---|---|
| Compile / typecheck against 1.7.0 | Passes with no source edits |
| Existing `DialogRootActions` / `AlertDialogRootActions` imports |
Still exported |
| `useRender` / `mergeProps` | Unchanged public surface |
| Autocomplete `keepHighlight` stories | Still valid (Autocomplete
retains the prop; Combobox had removed it earlier in 1.6) |
| Select.Separator wrapper | Compatible; benefits from a11y role fix
automatically |

---

## What's new in `@base-ui/[email protected]`

### Features / enhancements
- Typed `render` callback props based on the rendered element
- Autocomplete locale-aware filtering
- Autocomplete `form` prop for associating an external form
- New Combobox / Autocomplete / Select listbox `Separator` parts
(presentation role)
- Combobox inline `aria-expanded` exposure
- New open-change reasons: `input-press`, `cancel-open`
- Scroll Area WebKit overscroll feedback on Thumb
- Avatar Fallback shows immediately when `delay={0}`
- Toast `render` prop support on Title / Description / Action

### Fixes (high level)
- Popup positioning: collision padding off-by-one, unwanted flip with
capped scrollable content, left-anchored auto-resize origin,
unpositioned popups at viewport origin, canceled-exit unmount completion
- Focus restoration after keyboard close in Safari/Firefox
- Dialog touch outside-press without backdrop; scroll-lock handoff with
external overlays
- Drawer swipe/open reliability, iOS cross-axis scroll, Shadow DOM
gestures, virtual keyboard scroll
- Menu/submenu: duplicate `onOpenChange`, VoiceOver, TalkBack,
pinch-zoom, Chrome mouseleave
- Combobox/Select highlight/filter/scroll fixes (Safari hover highlight,
grouped limit, query clear, disabled inheritance)
- Field `data-dirty` for null-valued controls; Form focuses first
invalid field in document order
- Number Field multi-character format symbol editing
- Progress custom `min`/`max` semantics
- Slider assorted fixes; Tabs Suspense pre-hydration indicator
- Toast timer / swipe / re-add / provider effect ordering
- Navigation Menu frozen state when open trigger unmounts
- Radio unnecessary ARIA attributes removed; internal input clicks no
longer bubble (Checkbox/Switch/Radio)

### Performance / bundle size
Across many components Base UI reduced parsed bundle size and avoided
redundant work:
- Shared popup / store / dialog / popover / field / form / meter /
progress / scroll-area / slider / switch / tabs / toast / toolbar /
toggle-group size reductions
- Avoid redundant re-renders during lazy flipping
- Remove redundant lifecycle synchronization
- Exclude prehydration scripts from client bundles (Slider, Tabs)
- Deduplicate Combobox/Select/Autocomplete handlers and swipe math

---

## Full v1.7.0 changelog (from upstream)

### General
- Restore visible focus after keyboard close in Safari and Firefox
(#5093)
- Type `render` callback props based on the rendered element (#5104)
- Reduce popup / store / shared popup bundle size (#5233, #5250, #5192)
- Keep unpositioned popups at the viewport origin (#5299)
- Correct layout and passive effect timing (#5337)
- Remove redundant lifecycle synchronization (#5341)
- Prevent stale cleanup from clearing registered part IDs (#5340)
- Complete popup unmounting after a canceled exit transition (#5401)
- Fix rendered trigger ID ownership (#5110)
- Prevent unwanted flip with capped scrollable content (#5120)
- Fix `collisionPadding` off-by-one on the biased side (#5143)
- Mount popup subtrees synchronously when opening in React 17 (#5309)
- Fix auto-resize origin for left-anchored popups (#5370)
- Avoid redundant re-renders during lazy flipping (#5372)
- Strip implementation-only types from published `.d.ts` files (#5165)
- Fix `usePreviousValue` equality comparison (#5264)

### Components
- **Accordion:** Remove implicit `dir` on Root (#5117)
- **Alert Dialog / Dialog / Drawer / Menu / Popover / Preview Card /
Tooltip:** Prevent reopen after remount with reused handle (#5109,
#5149)
- **Autocomplete:** Locale filtering; `input-press` / `cancel-open`
reasons; reset scroll on filter; separator semantics
- **Avatar:** Fallback immediate at `delay={0}`
- **Button:** Keyboard click for custom elements
- **Checkbox / Checkbox Group / Switch / Radio Group:** Click bubbling,
validation, native form values, bundle size
- **Combobox:** Filtering/highlight fixes; `expanded` for inline;
disabled inheritance; separator; portalled content; bundle cleanup
- **Composite:** Nested reorder, disabled nav skip, RTL scroll alignment
- **Drawer:** Swipe/open, iOS scroll, Shadow DOM, snap points, bundle
- **Field / Fieldset / Form:** Invalid-when-disabled, `data-dirty`,
focus first invalid, bundle
- **Menu:** Pinch-zoom, submenu hover/VO/TalkBack, disabled propagation,
exit animation
- **Meter / Progress / Toggle Group:** Formatting / min-max / bundle
- **Navigation Menu:** Frozen menu on trigger unmount; pinch-zoom
- **Number Field / OTP Field:** Format symbols; invalid autofocus when
autoSubmit blocked
- **Scroll Area:** Thumb drag, iOS visibility, overscroll feedback, snap
while dragging
- **Select:** Highlight/disabled/mount/separator fixes
- **Slider / Tabs:** Assorted fixes; Suspense indicator; exclude
prehydration from client bundles
- **Toast:** Timer, swipe locking, re-add closing toast, `render` prop
content, provider effect order

---

## Test plan

- [x] Bump `@base-ui/react` to `^1.7.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)
- [ ] CI green on this PR
- [ ] Spot-check Storybook surfaces that wrap Base UI heavily (Combobox,
Select, Dialog, Menu, Toast, Accordion) if desired before merge

<!-- CURSOR_AGENT_PR_BODY_END -->

<div><a
href="https://cursor.com/agents/bc-b799cb20-62b5-4aad-9033-e9e7a838d771?cursor_ref=pr_footer&cursor_cta=open_in_web"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://cursor.com/assets/images/open-in-web-dark.png"><source
media="(prefers-color-scheme: light)"
srcset="https://cursor.com/assets/images/open-in-web-light.png"><img
alt="Open in Web" width="114" height="28"
src="https://cursor.com/assets/images/open-in-web-dark.png"></picture></a>&nbsp;<a
href="https://cursor.com/background-agent?bcId=bc-b799cb20-62b5-4aad-9033-e9e7a838d771&cursor_ref=pr_footer&cursor_cta=open_in_cursor"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://cursor.com/assets/images/open-in-cursor-dark.png"><source
media="(prefers-color-scheme: light)"
srcset="https://cursor.com/assets/images/open-in-cursor-light.png"><img
alt="Open in Cursor" width="131" height="28"
src="https://cursor.com/assets/images/open-in-cursor-dark.png"></picture></a>&nbsp;</div>

Co-authored-by: Cursor Agent <[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. type: bug It doesn't behave as expected.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[toast] Toast.Description does not render when a custom component is passed to render

2 participants