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)
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 45/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- react, typescript, vite
- Ambito
- developer-experience, frontend
Direzione di ricerca
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.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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.
- Lingua principale
- TypeScript
- Stelle
- 640
- Fork
- 32
- Merge medio
- 1h 15m
- PR unite (30g)
- 7
Preparare l'ambiente
Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di TanStack/redact
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
TanStack/redact#195 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
TanStack/redact#142 · 4 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di TanStack/redact
Issue simili
-
bug data-types
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
ClickHouse/clickhouse-js#1293 ·
I maintainer di solito rispondono entro 1 giorno
-
area: middleware enhancement good first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
-
agent/quality testing
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 95/100
I maintainer di solito rispondono entro 1 giorno
-
GitHub registry install via `gh` credentials rewrites `\u0000`–`\u001f` escapes in source files to `^@`–`^_`Forse già presa Una pull request collegata a questa issue è aperta o già unita. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 92/100
I maintainer di solito rispondono entro 2 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
juspay/agent-distro#203 ·
I maintainer di solito rispondono entro 1 giorno