Skip to content

fix(token-item): avoid button nesting when menuItems present - #211

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

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

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.

错误堆栈显示:

Item (render=<button>) > ... > DropdownMenuTrigger > button

Root Cause

当 TokenItem 同时有 onClick(使 Item 渲染为 button)和 menuItems(内部有 DropdownMenuTrigger button)时,会导致 button 嵌套。

这与 PR #210 修复的问题不同:

Solution

当有 menuItems 时,Item 渲染为 <div> 而不是 <button>,点击区域通过内部的 role="button" div 实现:

const hasMenuItems = items.length > 0;
const shouldRenderAsButton = isClickable && !hasMenuItems;

<Item render={shouldRenderAsButton ? <button /> : undefined}>
  {hasMenuItems && isClickable ? (
    <div role="button" tabIndex={0} onClick={onClick}>
      {itemContent}
    </div>
  ) : (
    itemContent
  )}
  {/* DropdownMenuTrigger 在这里,不会嵌套在 button 内 */}
</Item>

Additional Changes

更新 biwmeta API endpoint:

  • walletapi.biw-meta.com → walletapi.bfmeta.info

Testing

  • E2E 测试通过 (38 passed)
  • 无 button 嵌套 hydration 错误

When TokenItem has menuItems (DropdownMenuTrigger renders as button),
the outer Item cannot also be a button. Now Item renders as div when
menuItems exist, with a clickable div wrapper for the content area.

Also update biwmeta API endpoint from walletapi.biw-meta.com to
walletapi.bfmeta.info
@Gaubee
Gaubee merged commit 09a198f into main Jan 10, 2026
5 checks passed
@Gaubee
Gaubee deleted the fix/button-nesting-item branch January 10, 2026 16:51
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