Skip to content

The slot stops working in Server Component React #3542

@Qbason

Description

@Qbason

Bug report

I am using shadcn component Button which looks like this:

const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
	({ className, variant, size, asChild = false, ...props }, ref) => {
		const Comp = asChild ? Slot : "button";
		return (
			<Comp
				className={cn(buttonVariants({ variant, size, className }))}
				ref={ref}
				{...props}
			/>
		);
	}
);
Button.displayName = "Button";

And use it in my code ( in my server component react page ) like this:

	<Button variant="outline" size="sm" asChild>
		<Link
			href={`somePath`}
		>
			{t("common.view")}
		</Link>
	</Button>

From version 1.2.2 of "@radix-ui/react-slot"
Server Page generate nothing no html element (lack of link element)
The slot made it to be disappeared
Back to 1.2.0 solve the issue

Workaround

I just made the Button the child of the Link and it works and is okey to avoid using slot.
I will stay with that. I just have wanted to mention it to help maintain the package :)

Your environment

packages:
"@radix-ui/react-slot": "1.2.2",
"react": "^19.0.0",
"next": "^15.2.5",

Important info

I see that this issue doesn't appear in client component ("use client")

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions