Skip to content

Popover onChange 触发3次后失效 #56259

Closed
react-component/trigger
#601

Description

@crazyair

Reproduction link

Edit on CodeSandbox

Steps to reproduce

  1. 点击 open
  2. 点击 Popover 内部按钮
  3. 点击页面空白处

What is expected?

控制台打印 open,需要一直打印

What is actually happening?

只打印了3次

我看 5.x 是好的 https://codesandbox.io/p/sandbox/ji-ben-antd-5-29-2-forked-3xnnr2?file=%2Fdemo.tsx%3A14%2C31

Environment Info
antd 6.1.1
React latest
System chrome
Browser mac

Activity

  1. added theissue type on Dec 17, 2025
  2. dosubot commented on Dec 17, 2025

    @dosubot

    这是 antd 6.1.1 的已知 bug,Popover(以及 Dropdown 等弹出类组件)的 onChange/onOpenChange 事件因为内部闭包问题,交互 3 次后就会失效,事件不再触发。这个问题在 PR #54880 中已修复,修复内容已合入 2025-09-06 之后发布的 antd 6.x 版本(5.27.3 及 6.x 同步修复)——建议直接升级到最新的 antd 6.x 版本即可恢复正常行为。修复 PR 详情

    如果暂时无法升级,可以尝试用受控模式手动管理 open 状态作为 workaround,例如:

    const [open, setOpen] = useState(false);
    
    <Popover
      open={open}
      onOpenChange={setOpen}
      // ...其他 props
    >
      <Button>open</Button>
    </Popover>

    但这种方式实现会比非受控复杂,且并不适用于所有场景。根本解决方案还是升级 antd 版本。这个问题属于 antd 框架底层回归,和业务代码无关。

    To reply, just mention @dosu.


    Share context across your team and agents. Try Dosu.

    Leave Feedback Learn about ant-design with Dosu Add Dosu to your team

  3. added
    🐛 BugAnt Design Team had proved that this is a bug.
    and removed on Dec 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    🐛 BugAnt Design Team had proved that this is a bug.

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions