Repository navigation
Conversation
commit: |
Bundle size
PerformanceTotal duration: 1,444.53 ms +160.20 ms(+12.5%) | Renders: 78 (+0) | Paint: 2,253.41 ms +260.74 ms(+13.1%)
10 tests within noise — details Metric alarms
Check out the code infra dashboard for more information about this PR. |
✅ Deploy Preview for base-ui ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
<Toast.Root toast={toast}>
<Toast.Action render={<MyButton />} /> {/* content comes from toast.actionProps */}
</Toast.Root>With this change, an empty action button mounts for every toast, even those without an action. A better check is to also treat the render element's own children as content, so - const shouldRender = Boolean(computedChildren);
+ // The render prop's evaluated element is the source of truth for content:
+ // `render` element children override `computedChildren` in the merge, and a
+ // render function's returned element carries its own children.
+ const shouldRender = Boolean(
+ (element.props as { children?: React.ReactNode }).children,
+ );
+ |
|
Thanks, you're right |
99fe7e1 to
73f4bac
Compare
Toast.Action gated mounting on the presence of 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. This is the same oversight fixed for Toast.Title and Toast.Description in mui#2809; apply the same fix so `render` behaves consistently across all three optional Toast content parts.
73f4bac to
c1edef0
Compare
…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={<button>{0}</button>}
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.
Description
Toast.Actiongates rendering on the presence of resolved children (toast.actionProps?.children ?? children). When the action is provided through therenderprop with content but no children —<Toast.Action render={<button>Undo</button>} />— that content was dropped:shouldRenderwasfalseand the element never mounted.The fix gates on the evaluated element's resolved children, so a
renderthat carries content mounts, while a childless, styling-onlyrender={<MyButton />}— used purely to customize the element in a shared template, with the action content coming fromtoast.actionProps— stays conditional and does not force-mount an empty button for every toast. Whether resolved children count as content is decided by a sharedisRenderableNodepredicate matching React renderability (numeric/bigint children including0are content; nullish values, booleans, empty strings, and arrays containing only those are not), behind aReact.isValidElementcheck so a render function returning null can't crash the children lookup.Linked Issues
Related to #2809 (same root cause, for Title and Description).
Additional context
Follow-up to #5210, kept separate to scope that PR to the reported issue. The shared util
packages/react/src/toast/utils/isRenderableNode.ts(+ tests) is included byte-identically on both PRs, so whichever merges second resolves it cleanly and its squash then effectively touches only theToast.Actionfiles. Tests cover therenderprop as an element and as a function, the childless-render case, a render function returning null, numeric0as render-prop and plain child, and empty-array children.