Skip to content

Conversation

jjenzz
Copy link
Contributor

@jjenzz jjenzz commented Oct 6, 2025

Description

This is inspired by #2197 and should resolve #3626, but I've made it backwards compatible and also improved the implementation of Slot slightly:

  • Avoids rendering redundant extra Slot.SlotClone comps
  • Replaces React.Children.only() error with a more intuitive warning
  • Re-introduces a working version of the useComposedRefs change that was reverted
  • Adds tests including thorough use-case examples in ssr-testing

Copy link

changeset-bot bot commented Oct 6, 2025

🦋 Changeset detected

Latest commit: 60c567c

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 44 packages
Name Type
@radix-ui/react-slot Patch
@radix-ui/react-alert-dialog Patch
@radix-ui/react-collection Patch
@radix-ui/react-dialog Patch
@radix-ui/react-menu Patch
@radix-ui/react-popover Patch
@radix-ui/react-primitive Patch
radix-ui Patch
@radix-ui/react-select Patch
@radix-ui/react-tooltip Patch
@radix-ui/react-accordion Patch
@radix-ui/react-menubar Patch
@radix-ui/react-navigation-menu Patch
@radix-ui/react-one-time-password-field Patch
@radix-ui/react-roving-focus Patch
@radix-ui/react-slider Patch
@radix-ui/react-toast Patch
@radix-ui/react-context-menu Patch
@radix-ui/react-dropdown-menu Patch
@radix-ui/react-announce Patch
@radix-ui/react-arrow Patch
@radix-ui/react-aspect-ratio Patch
@radix-ui/react-avatar Patch
@radix-ui/react-checkbox Patch
@radix-ui/react-collapsible Patch
@radix-ui/react-dismissable-layer Patch
@radix-ui/react-focus-scope Patch
@radix-ui/react-form Patch
@radix-ui/react-hover-card Patch
@radix-ui/react-label Patch
@radix-ui/react-password-toggle-field Patch
@radix-ui/react-popper Patch
@radix-ui/react-portal Patch
@radix-ui/react-progress Patch
@radix-ui/react-radio-group Patch
@radix-ui/react-scroll-area Patch
@radix-ui/react-separator Patch
@radix-ui/react-switch Patch
@radix-ui/react-tabs Patch
@radix-ui/react-toggle-group Patch
@radix-ui/react-toggle Patch
@radix-ui/react-toolbar Patch
@radix-ui/react-visually-hidden Patch
@radix-ui/react-accessible-icon Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@jjenzz jjenzz force-pushed the slot-improvements branch from 56797c0 to 60c567c Compare October 6, 2025 15:57
Comment on lines +85 to +87
<Client.Button {...props} ref={forwardedRef} style={{ display: 'flex', gap: '3rem' }}>
<Slot.Root>
<Slot.Slottable child={children}>
Copy link
Contributor Author

@jjenzz jjenzz Oct 6, 2025

Choose a reason for hiding this comment

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

I added this example because it's important that Slot.Root and its desired Slot.Slottable are on the same client or server boundary. This is perhaps something worth documenting. It isn't specific to nested slottables—it's important if we want to change the element that an existing component slots onto.

Comment on lines +17 to +18
// fine in RSC as it's a React.useCallback under the hood
const composedRefs = useComposedRefs(forwardedRef, slottableElementRef);
Copy link
Contributor Author

@jjenzz jjenzz Oct 6, 2025

Choose a reason for hiding this comment

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

This broke in the previous attempts because Slot was changed to a 'use client' boundary. We can compose them without that, and all is well :)

Comment on lines +21 to +22
if (process.env.NODE_ENV === 'development') console.warn(createSlotWarning(ownerName));
return children;
Copy link
Contributor Author

@jjenzz jjenzz Oct 6, 2025

Choose a reason for hiding this comment

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

If it cannot slot, we don't throw anymore... it renders the children as normal with a warning. I wasn't sure what was best here tbh.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant