Skip to content

Commit

Permalink
fix: @radix-ui/react-slot with React 19
Browse files Browse the repository at this point in the history
  • Loading branch information
ggallon committed Dec 9, 2024
1 parent 9c07a58 commit a704d52
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 10 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@
"use-sync-external-store": "1.4.0"
},
"patchedDependencies": {
"@radix-ui/[email protected]": "patches/@[email protected]"
"@radix-ui/[email protected]": "patches/@[email protected]",
"@radix-ui/react-slot": "patches/@radix-ui__react-slot.patch"
}
}
}
50 changes: 50 additions & 0 deletions patches/@radix-ui__react-slot.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
diff --git a/dist/index.js b/dist/index.js
index 724cd6fcdf2dce8622bcef6a4880e92fe05cf44c..c335e011edad42951d0c67439debe27a6a7688aa 100644
--- a/dist/index.js
+++ b/dist/index.js
@@ -63,11 +63,15 @@ var SlotClone = React.forwardRef((props, forwardedRef) => {
const { children, ...slotProps } = props;
if (React.isValidElement(children)) {
const childrenRef = getElementRef(children);
- return React.cloneElement(children, {
- ...mergeProps(slotProps, children.props),
- // @ts-ignore
- ref: forwardedRef ? (0, import_react_compose_refs.composeRefs)(forwardedRef, childrenRef) : childrenRef
- });
+ const props = {
+ ...mergeProps(slotProps, children.props)
+ }
+ // do not pass ref to React.Fragment for React 19 compatibility
+ if (children.type !== React.Fragment) {
+ props.ref = forwardedRef ? (0, import_react_compose_refs.composeRefs)(forwardedRef, childrenRef) : childrenRef;
+ }
+
+ return React.cloneElement(children, props);
}
return React.Children.count(children) > 1 ? React.Children.only(null) : null;
});
diff --git a/dist/index.mjs b/dist/index.mjs
index 73e28afb741e05e1d1bb4206fa917918bb9457ec..61b961dae21928d73c2a543d4e463e144846a29f 100644
--- a/dist/index.mjs
+++ b/dist/index.mjs
@@ -25,11 +25,15 @@ var SlotClone = React.forwardRef((props, forwardedRef) => {
const { children, ...slotProps } = props;
if (React.isValidElement(children)) {
const childrenRef = getElementRef(children);
- return React.cloneElement(children, {
- ...mergeProps(slotProps, children.props),
- // @ts-ignore
- ref: forwardedRef ? composeRefs(forwardedRef, childrenRef) : childrenRef
- });
+ const props = {
+ ...mergeProps(slotProps, children.props)
+ }
+ // do not pass ref to React.Fragment for React 19 compatibility
+ if (children.type !== React.Fragment) {
+ props.ref = forwardedRef ? composeRefs(forwardedRef, childrenRef) : childrenRef;
+ }
+
+ return React.cloneElement(children, props);
}
return React.Children.count(children) > 1 ? React.Children.only(null) : null;
});
21 changes: 12 additions & 9 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a704d52

Please sign in to comment.