Skip to content

Commit e59256f

Browse files
authored
Revert Slot changes causing RSC errors (radix-ui#3554)
1 parent 7e2adc6 commit e59256f

File tree

4 files changed

+13
-8
lines changed

4 files changed

+13
-8
lines changed

.changeset/twenty-apples-stay.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@radix-ui/react-slot': patch
3+
---
4+
5+
Revert slot changes causing errors in server components

packages/react/slot/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
'use client';
21
export {
32
Slot,
43
Slottable,

packages/react/slot/src/slot.test.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState } from 'react';
1+
import * as React from 'react';
22
import { cleanup, render, screen, fireEvent } from '@testing-library/react';
33
import userEvent from '@testing-library/user-event';
44
import { Slot, Slottable } from './slot';
@@ -140,7 +140,9 @@ describe('given a Button with Slottable', () => {
140140
});
141141
});
142142

143-
describe('given an Input', () => {
143+
// TODO: Unskip when underlying issue is resolved
144+
// Reverted in https://github.com/radix-ui/primitives/pull/3554
145+
describe.skip('given an Input', () => {
144146
const handleRef = vi.fn();
145147

146148
beforeEach(() => {
@@ -199,7 +201,7 @@ const Input = React.forwardRef<
199201
}
200202
>(({ asChild, children, ...props }, forwardedRef) => {
201203
const Comp = asChild ? Slot : 'input';
202-
const [value, setValue] = useState('');
204+
const [value, setValue] = React.useState('');
203205

204206
return (
205207
<Comp

packages/react/slot/src/slot.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as React from 'react';
2-
import { useComposedRefs } from '@radix-ui/react-compose-refs';
2+
import { composeRefs } from '@radix-ui/react-compose-refs';
33

44
/* -------------------------------------------------------------------------------------------------
55
* Slot
@@ -66,14 +66,13 @@ interface SlotCloneProps {
6666
/* @__NO_SIDE_EFFECTS__ */ function createSlotClone(ownerName: string) {
6767
const SlotClone = React.forwardRef<any, SlotCloneProps>((props, forwardedRef) => {
6868
const { children, ...slotProps } = props;
69-
const childrenRef = React.isValidElement(children) ? getElementRef(children) : undefined;
70-
const ref = useComposedRefs(childrenRef, forwardedRef);
7169

7270
if (React.isValidElement(children)) {
71+
const childrenRef = getElementRef(children);
7372
const props = mergeProps(slotProps, children.props as AnyProps);
7473
// do not pass ref to React.Fragment for React 19 compatibility
7574
if (children.type !== React.Fragment) {
76-
props.ref = ref;
75+
props.ref = forwardedRef ? composeRefs(forwardedRef, childrenRef) : childrenRef;
7776
}
7877
return React.cloneElement(children, props);
7978
}

0 commit comments

Comments
 (0)