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)

Abierto
#92 1 comentario 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
45/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
react, typescript, vite

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
TypeScript
Estrellas
640
Forks
32
Merge medio
1 h 15 min
PR fusionados (30 d)
7

Preparar el entorno

Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de TanStack/redact

Todos los issues de TanStack/redact

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.