Base UI Menu.Trigger's DOM node is re-created when the menu opens, so a mouse-up alone activates a menu item (React keeps the node)
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 45/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- react, typescript, vite
调研方向
Start by reproducing the issue with the provided Base UI menu example and compare the Redact and React builds. Trace how Redact handles the Menu.Trigger DOM node when opening the menu, then inspect the existing tests or add a focused regression case for node identity and mouse-up behavior. Done means the trigger node remains connected and unchanged across opening, and a mouse-up alone does not activate a menu item.
由索引模型根据 Issue 内容生成。
描述
Opening a Base UI Menu replaces the trigger's host DOM node under Redact: after the mousedown that opens the menu, the <button> the page had before is detached (isConnected === false) and a new one is in its place. Under React 19 the node is kept.
Base UI relies on the node staying put. Menu.Trigger's onMouseDown starts a 200 ms timer that arms allowMouseUpTriggerRef ("release the mouse over an item → activate it") and registers a one-shot document mouseup listener that disarms it. When the mouseup lands on the detached node it never bubbles to document, the flag stays armed, and the next mouseup on any item activates it. Anything that dispatches events on an element reference (test harnesses, userEvent-style tooling) then sees an item activate twice: once from Base UI's synthesized click on mouseup, once from the real click. A real mouse is hit-tested onto the new node, so humans mostly don't notice, but the stale mousedown target also means the browser never fires click on the trigger itself.
In our app (TasksBoard, Base UI DropdownMenu on every task row) the production e2e run duplicated a task twice from one "Duplicate" click and lost a freshly created subtask editor; we reverted to React.
Reproduction
package.json
{
"name": "redact-menu-repro", "private": true, "type": "module",
"scripts": { "build": "vite build", "build:react": "REDACT=0 vite build --outDir dist-react" },
"dependencies": { "@base-ui/react": "1.8.0", "react": "19.2.0", "react-dom": "19.2.0" },
"devDependencies": { "@tanstack/redact": "0.2.1", "@vitejs/plugin-react": "4.3.4", "vite": "6.3.5" }
}
vite.config.js
import { defineConfig } from "vite"
import react from "@vitejs/plugin-react"
import { redact } from "@tanstack/redact/vite"
export default defineConfig({ plugins: [react(), ...(process.env.REDACT === "0" ? [] : [redact()])] })
index.html
<!doctype html><html><body><div id="root"></div><script type="module" src="/src/main.jsx"></script></body></html>
src/main.jsx
import React from "react"
import { createRoot } from "react-dom/client"
import { Menu } from "@base-ui/react/menu"
let clicks = 0
function App() {
return (
<Menu.Root>
<Menu.Trigger data-testid="trigger">Open</Menu.Trigger>
<Menu.Portal>
<Menu.Positioner>
<Menu.Popup>
<Menu.Item data-testid="item" onClick={() => { clicks++; document.getElementById("out").textContent = "item clicks: " + clicks }}>Item</Menu.Item>
</Menu.Popup>
</Menu.Positioner>
</Menu.Portal>
</Menu.Root>
)
}
createRoot(document.getElementById("root")).render(<><App /><p id="out">item clicks: 0</p></>)
pnpm install && pnpm build && pnpm build:react, serve dist/ (Redact) and dist-react/ (React), then run this in the console of each:
const sleep = ms => new Promise(r => setTimeout(r, ms))
const q = s => document.querySelector(`[data-testid="${s}"]`)
const ev = (e, type, buttons) => {
const r = e.getBoundingClientRect()
const at = { bubbles: true, cancelable: true, composed: true, view: window, button: 0, clientX: r.x + r.width / 2, clientY: r.y + r.height / 2 }
e.dispatchEvent(type.startsWith("pointer") ? new PointerEvent(type, { ...at, buttons, pointerId: 1, pointerType: "mouse", isPrimary: true }) : new MouseEvent(type, { ...at, buttons }))
}
const t = q("trigger")
ev(t, "pointerdown", 1); ev(t, "mousedown", 1); await sleep(50)
console.log({ menuOpen: !!q("item"), triggerSameNode: q("trigger") === t, heldTriggerConnected: t.isConnected })
ev(t, "pointerup", 0); ev(t, "mouseup", 0); await sleep(400)
const item = q("item")
ev(item, "pointerup", 0); ev(item, "mouseup", 0); await sleep(300) // a mouse-up alone, no click
console.log(document.getElementById("out").textContent)
Results
| build | after mousedown on the trigger |
after one mouseup on the item |
|---|---|---|
| React 19.2 | { menuOpen: true, triggerSameNode: true, heldTriggerConnected: true } |
item clicks: 0 |
| Redact 0.2.1 | { menuOpen: true, triggerSameNode: false, heldTriggerConnected: false } |
item clicks: 1 |
Expected: the trigger keeps its DOM node across the re-render that opens the menu (as React does), so Base UI's document mouseup sees the release and a lone mouseup on an item does nothing.
Versions: @tanstack/redact 0.2.1 (redact() with default options), @base-ui/react 1.8.0, react / react-dom 19.2.0, vite 6.3.5, Chrome 143 on macOS. Same with Base UI 1.8.0's useRenderElement-based Menu.Trigger in our app (DropdownMenu wrapper). Possibly related to #70 (Base UI submenu links close without navigating), which also involves a Base UI menu and real pointer input.
- 主要语言
- TypeScript
- 星标
- 640
- 派生
- 32
- 平均合并
- 1 小时 15 分钟
- 30 天内合并 PR
- 7
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
TanStack/redact 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 70/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 82/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 84/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 85/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
相似的 Issue
-
bug data-types
难度 2/5 1-3 小时 新手友好度 88/100
ClickHouse/clickhouse-js#1293 ·
维护者通常 1 天内回复
-
area: middleware enhancement good first issue
难度 2/5 1-3 小时 新手友好度 68/100
-
agent/quality testing
难度 1/5 1 小时以内 新手友好度 95/100
维护者通常 1 天内回复
-
GitHub registry install via `gh` credentials rewrites `\u0000`–`\u001f` escapes in source files to `^@`–`^_`可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭
难度 2/5 1-3 小时 新手友好度 92/100
维护者通常 2 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
juspay/agent-distro#203 ·
维护者通常 1 天内回复