`@effect/ui-kit` (Effect-TS/ui): `Popover`: a generated trigger id changes on each render of its Dialog, so the popup loses its anchor

未关闭 适合新手
#11,088 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
78/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
typescript

调研方向

阅读 packages/ui-kit/src/Popover.ts,重点查看第 1071 行和第 1272 行附近的触发器 ID 生成,以及第 1060–1062 行附近的活动触发器选择器。切换已打开的 popover 内的控件,然后关闭并重新打开,即可重现问题。确保生成的触发器 ID 在各次 dialog 渲染间保持稳定;完成后,popup 会保持锚定状态,且触发器每次打开时都保留 aria-expanded="true"。

由索引模型根据 Issue 内容生成。

描述

Written with Claude Code for @magoz, from an app we're building on Effect UI.

What version of Effect is running?
Package Version
@effect/ui-kit, @effect/ui (Effect-TS/ui) 0.0.0 snapshot, reproduced on main at dec1ca9
effect 4.1.7
What steps can reproduce the bug?
  1. A Popover whose trigger has no id of the consumer's (so the kit generates one), and whose popup holds a control that re-renders the popover's inner Dialog on its own, e.g. a Switch that changes the popup's content.
  2. Open the popover and toggle the switch. Close it, and open it again.
What is the expected behavior?

The popup stays anchored to its trigger on every open, and the trigger keeps aria-expanded="true" while it's open.

What do you see instead?

After the first re-render the popup is placed at the viewport's top-left (--anchor-width: 0px), and the trigger has no aria-expanded. It happens again on every reopen.

Additional information

The trigger's generated id comes from a counter declared in the Popover's parts (Popover.ts#L1071) but incremented inside the child Dialog's parts (Popover.ts#L1272):

const key = idOf(options.element) ?? p.id("trigger", triggers++)

The dialog's parts run on every render of the dialog, also when the popover's own parts don't run (a transition frame, or a re-render the popup's content causes). So the count carries over between runs and the trigger becomes …-trigger-1, then -2. The popover still positions against the id from the open (triggerSelector = idSelector(active), Popover.ts#L1060-L1062), which no element has any more.

A fix that works for us (a local patch): count per run of the dialog's parts, by moving let triggers = 0 from the popover's parts to the start of parts: (dialog) => { … }. Ids stay stable across re-renders as long as triggers are drawn in the same order, which is how Dialog and Menu count theirs. A sturdier form for triggers drawn conditionally or reordered would key the id on the element's .key() when it has one.

Menu, PreviewCard, Dialog and Drawer count their triggers within their own parts and have no child whose parts rerun alone, so they aren't affected.

主要语言
TypeScript
星标
16.7k
派生
808
平均合并
21 小时 22 分钟
30 天内合并 PR
486

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

Effect-TS/effect 的其他 Issue

查看 Effect-TS/effect 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。