Skip to content

fix(site): ensure Error Boundary catches render errors correctly #15963

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Jan 3, 2025
Prev Previous commit
Next Next commit
Merge branch 'main' into mes/error-boundary-fix
  • Loading branch information
Parkreiner committed Jan 3, 2025
commit 01b19479e04ab7870aae71f34f0093baf1aefe75
38 changes: 22 additions & 16 deletions site/src/components/Button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,25 @@ export interface ButtonProps
asChild?: boolean;
}

export const Button: FC<ButtonProps> = forwardRef<
HTMLButtonElement,
ButtonProps
>(({ className, variant, size, asChild = false, ...props }, ref) => {
const Comp = asChild ? Slot : "button";
return (
<Comp
ref={ref}
{...props}
className={cn(buttonVariants({ variant, size }), className)}
type={
props.type === undefined && Comp === "button" ? "button" : props.type
}
/>
);
});
export const Button = forwardRef<HTMLButtonElement, ButtonProps>(
({ className, variant, size, asChild = false, ...props }, ref) => {
const Comp = asChild ? Slot : "button";
return (
<Comp
{...props}
ref={ref}
className={cn(buttonVariants({ variant, size }), className)}
// Adding default button type to make sure that buttons don't
// accidentally trigger form actions when clicked. But because
// this Button component is so polymorphic (it's also used to
// make <a> elements look like buttons), we can only safely
// default to adding the prop when we know that we're rendering
// a real HTML button instead of an arbitrary Slot. Adding the
// type attribute to any non-buttons will produce invalid HTML
type={
props.type === undefined && Comp === "button" ? "button" : props.type
}
/>
);
},
);
You are viewing a condensed version of this merge commit. You can view the full changes here.