Skip to content

fix(token-item): resolve button nesting hydration error - #210

Merged
Gaubee merged 1 commit into
mainfrom
fix/button-nesting-hydration
Jan 10, 2026
Merged

Gaubee merged 1 commit into
mainfrom
fix/button-nesting-hydration

Conversation

@Gaubee

@Gaubee Gaubee commented Jan 10, 2026

Copy link
Copy Markdown
Contributor

Problem

首页启动时出现 React hydration 错误:

In HTML, <button> cannot be a descendant of <button>.
This will cause a hydration error.

错误堆栈显示 TokenItem > Item > DropdownMenuTrigger > Button > button 嵌套。

Root Cause

DropdownMenuTrigger 基于 @base-ui/react/menu 的 Menu.Trigger,默认渲染为 <button>。而内部又放了一个 <Button> 组件,导致嵌套的 <button> 元素。

Solution

遵循 shadcn/ui + base-ui 最佳实践,使用 render 属性将渲染委托给 Button 组件:

// Before (错误)
<DropdownMenuTrigger className="...">
  <Button variant="ghost" size="icon-sm">
    <IconDotsVertical />
  </Button>
</DropdownMenuTrigger>

// After (正确)
<DropdownMenuTrigger
  render={<Button variant="ghost" size="icon" className="size-11 rounded-lg" />}
>
  <IconDotsVertical className="text-muted-foreground size-5" />
</DropdownMenuTrigger>

Testing

  • E2E 测试通过
  • 截图基准已更新

Use render prop on DropdownMenuTrigger to delegate rendering to Button
component, following shadcn/ui + base-ui best practices. This avoids
nesting <button> elements which causes React hydration errors.
@Gaubee
Gaubee merged commit af4f024 into main Jan 10, 2026
5 checks passed
@Gaubee
Gaubee deleted the fix/button-nesting-hydration branch January 10, 2026 16:42
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