Skip to content

[Bug]: DismissableLayer dismisses on the next tap inside after a cancelled touch outside (stale deferred click listener) #2891

Closed

Description

@kevinpickett

Environment

Developement/Production OS: macOS 26.5.2
Node version: 22.23.1
Package manager: npm 10
Reka UI version: 2.10.4
Vue version: 3.5.38
Nuxt version: n/a (Vite + Inertia)
Nuxt mode: n/a
Nuxt target: n/a
CSS framework: tailwindcss@4.3.1
Client OS: iOS 26 / Android 16
Browser: Mobile Safari, Chrome for Android

Link to minimal reproduction

Runnable repro as a failing unit test against v2 (fails on 35dde22, passes with the one-line fix on the same branch):
https://github.com/kevinpickett/reka-ui/blob/fix/dismissable-layer-stale-touch-click/packages/core/src/DismissableLayer/DismissableLayer.test.ts (describe given a DismissableLayer after a cancelled touch tap outside)

Minimal component for a device repro:

<script setup lang="ts">
import { PopoverContent, PopoverPortal, PopoverRoot, PopoverTrigger } from 'reka-ui'
</script>

<template>
  <div style="height: 200vh; padding: 2rem">
    <PopoverRoot>
      <PopoverTrigger>Open</PopoverTrigger>
      <PopoverPortal>
        <PopoverContent :side-offset="8">
          <button type="button">Inside button</button>
          <input placeholder="Inside input">
        </PopoverContent>
      </PopoverPortal>
    </PopoverRoot>
  </div>
</template>

Steps to reproduce

On a touch device (or DevTools device emulation with touch):

  1. Tap Open so the popover shows.
  2. Touch the page outside the popover and drag/scroll the page. Because the touch became a scroll, the browser does not fire click, and the popover correctly stays open.
  3. Tap Inside button (or the input) inside the popover.

Describe the bug

Step 3 closes the popover. The tap inside emits pointerDownOutside and then dismiss, even though the pointer never went outside.

Cause: in usePointerDownOutside (packages/core/src/DismissableLayer/utils.ts), a touch pointerdown outside the layer defers the pointerDownOutside dispatch to a one-shot document click listener (handleClickRef). If no click follows (scroll, drag, long-press, cancelled touch), that listener stays armed. The next pointerdown inside the layer takes the isLayerExist(...) early return:

if (isLayerExist(element.value, target)) {
  isPointerInsideDOMTree.value = false
  return
}

That return skips the cleanup further down (ownerDocument.removeEventListener('click', handleClickRef.value)), so the click from the inside tap fires the stale listener and dismisses the layer.

Radix UI, which this hook is ported from, removes the deferred listener whenever the pointerdown is inside the tree. That else branch was added in radix-ui/primitives#2171 ("Popover component closing after content dragging event on mobile when clicked after"). The reka-ui port added the isLayerExist early return for nested layers above that logic, so the same scenario regressed for both the layer itself and nested layers.

Fix is one line, at the top of the isLayerExist branch:

ownerDocument.removeEventListener('click', handleClickRef.value)

I have a PR ready with this change and a regression test.

Expected behavior

A tap inside a dismissable layer (or a layer nested above it) never emits pointerDownOutside / dismiss for that layer, regardless of whether an earlier outside touch was cancelled. A completed tap outside still dismisses it.

Context & Screenshots (if applicable)

Affects every Reka component built on DismissableLayer on touch devices: Popover, DropdownMenu, Select, Combobox, DatePicker calendars (the month arrows are a common first tap after scrolling), Tooltip, and Dialog when not modal. In our app the practical symptom was popovers and pickers closing on the first tap after any page scroll.

The main (1.x / radix-vue) branch has the same early return in packages/radix-vue/src/DismissableLayer/utils.ts.

Activity

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions