← reports

#6371 · Cross-bundle long-press ownership is not shared

Bug Priority: Medium Effort: Low ui · mobile · GitHub issue · October 27, 2026

Trusted base: b6743a36bd9eae1408c35cfc2c7ab1d2419dc79d (origin/main).

Verdict: REPRODUCED at the production component boundary · Root-cause confidence: high.

1. TL;DR

A touch press inside nested action menus should open only the innermost menu. The production component instead opens both menus when the outer and inner instances come from separately evaluated module copies. A module-local event claim is invisible to the other copy, so both timers expire and both open callbacks fire. The sidebar composes the host thread menu inside the plugin project menu, which supplies this module arrangement. The same regression failed in two clean trusted checkouts; the ten existing tests still pass. This is a DOM/component reproduction, not a verified physical iPhone recording.

2. Claims vs findings

ClaimStatusEvidence
One nested touch press opens both menus.Verified at component boundaryBoth callbacks receive true in the separately evaluated-module case, in both checkouts.
The host and plugin can have different copies of the menu component.Verified in trusted sourceSDK host binding, plugin project import, and plugin build runtime exception list.
Existing nesting coverage misses this case.VerifiedSame-module control passes; the existing 10-test suite passes.
Two sheets visibly stack on an iPhone.Unverified visually in this runBoth production open callbacks confirmed. No Chrome executable or physical iOS session was available for screenshots.
The failure originates from contextmenu handling.Not supportedThe reproduction sends only pointerdown and advances the long-press timer.

3. Environment

4. Minimal reproduction

  1. Clone the trusted target and check out the recorded base:
    git clone --single-branch --branch main https://github.com/get-bb/bb.git bb-repro-6371
    cd bb-repro-6371
    git checkout --detach b6743a36bd9eae1408c35cfc2c7ab1d2419dc79d
    pnpm install --frozen-lockfile --prefer-offline
  2. Download the reproduction test and copy it into apps/app/src/components/ui/issue-6371-repro.test.tsx.
  3. Create a byte-identical second module evaluation and run the test:
    cp packages/shared-ui/src/components/ui/compact-long-press-menu.tsx packages/shared-ui/src/components/ui/compact-long-press-menu-repro-copy.tsx
    pnpm exec turbo run test --filter=@bb/app -- src/components/ui/issue-6371-repro.test.tsx

Expected: two passing cases, with only the inner thread menu opening. Actual: same-module control passes; separate-module case fails because the outer project callback also fires. Exit status 1; 1 failed and 1 passed test.


The test imports real production menu and drawer components. A byte-identical source copy models the separate evaluation caused by plugin bundling; it does not mock the claim logic. Fake timers advance 800 ms, beyond the production 700 ms threshold. The observable invariant is exclusive ownership of a nested touch press.

Full regression source
// @vitest-environment jsdom

import { act, cleanup, fireEvent, render, screen } from "@testing-library/react";
import { afterEach, describe, expect, it, vi } from "vitest";
import { CompactViewportOverrideProvider } from "@bb/shared-ui/hooks/use-compact-viewport";
import { CompactLongPressMenu } from "@bb/shared-ui/compact-long-press-menu";
import { CompactLongPressMenu as BundledMenu } from "../../../../../packages/shared-ui/src/components/ui/compact-long-press-menu-repro-copy";
import { DropdownMenuItem } from "@bb/shared-ui/dropdown-menu";

afterEach(() => {
  cleanup();
  vi.useRealTimers();
});

describe("nested touch-menu ownership across bundle boundaries", () => {
  it.each([
    ["same module", CompactLongPressMenu],
    ["separately evaluated module", BundledMenu],
  ] as const)("opens only the inner drawer: %s", (_name, ProjectMenu) => {
    vi.useFakeTimers();
    const threadOpened = vi.fn();
    const projectOpened = vi.fn();
    render(
      <CompactViewportOverrideProvider isCompactViewport>
        <ProjectMenu
          label="Project actions"
          items={<DropdownMenuItem>Project settings</DropdownMenuItem>}
          onOpenChange={projectOpened}
        >
          <section>
            <CompactLongPressMenu
              label="Thread actions"
              items={<DropdownMenuItem>Pin thread</DropdownMenuItem>}
              onOpenChange={threadOpened}
            >
              <button type="button">Reproduction thread</button>
            </CompactLongPressMenu>
          </section>
        </ProjectMenu>
      </CompactViewportOverrideProvider>,
    );
    fireEvent.pointerDown(screen.getByRole("button", { name: "Reproduction thread" }), {
      pointerId: 17,
      pointerType: "touch",
      isPrimary: true,
      clientX: 60,
      clientY: 100,
    });
    act(() => vi.advanceTimersByTime(800));
    expect(threadOpened).toHaveBeenCalledWith(true);
    expect(projectOpened).not.toHaveBeenCalled();
  });
});

Screenshot limitation: BB Browser Automation headless startup failed with “Install Chrome/Chromium on this host or link its executable at the plugin data runtime/chrome path.” No image was fabricated. The visual stacking and physical iOS behavior are not claimed as directly observed here.

5. Root cause

The event claim WeakSet is owned by each evaluated module. The pointerdown handler checks and writes only that set, then starts a timer. An inner handler claims the event in its own set, but the bubbling outer handler consults a different empty set. Both schedule a long press. The timer opens state and invokes the externally visible onOpenChange callback.

const claimedPressEvents = new WeakSet<Event>();
if (claimedPressEvents.has(event.nativeEvent)) {
  return;
}
claimedPressEvents.add(event.nativeEvent);

The real composition is supported by the thread row SDK import, the host SDK binding, and the host compact thread wrapper. The project wrapper uses the plugin-imported CompactLongPressMenu. The build runtime-sharing allowlist does not include this module; sharing a source file does not imply shared runtime state across bundles.

The contextmenu handler separately checks event.defaultPrevented. This reproduction does not send that event. The existing nested-menu test imports a single component instance, explaining why it passes despite the bundle-boundary bug.

6. Proposed fix

Make press ownership live on the shared native event, rather than in a per-module collection, using a stable cross-bundle key. Keep current bubbling, cancellation, drag guards, click suppression, and release handling intact. Retain coverage for both same-module and separately evaluated menu instances. A desktop context menu or broad stopPropagation workaround would not repair this ownership contract.

7. PR review

PR #6372 is open and its GitHub closing-issue metadata links to #6371. Its metadata and diff were read strictly as untrusted static evidence; its branch and tests were not checked out or executed.

The proposed shared-ui change replaces the module-local WeakSet with a stable Symbol.for key on the native event and adds separate-module coverage. It also synchronizes the registry component asset. Static assessment: directionally addresses the verified root cause. No blocking static defect identified in the inspected ownership change; physical iOS verification and all claims of passing PR checks remain outside this investigation. The only executed tests are the independently authored trusted-base reproduction and the existing main suite. No duplicate fix branch or PR was created because this ready PR already links to the issue.

8. Related issues

A repository search for sidebar long-press reports did not establish a second matching defect. This run classifies and reports only #6371.

9. Verification

The same agent repeated the reproduction in checkout B, created clean and detached at the recorded trusted main commit. After a separate frozen install, only the reproduction test and the byte-identical production module copy were added. The exact Turbo command above again produced 1 failed / 1 passed, with the outer callback receiving true in the separate-module case. No production files were modified; this is a second clean run, not independent verification by another agent.

The existing main suite separately passed 10 / 10 using pnpm exec turbo run test --filter=@bb/app -- src/components/ui/compact-long-press-menu.test.tsx. A final fetch of trusted main did not change the recorded base or reveal a later fix in the component. No report correction was needed after the second run.

10. Appendix

Log paths were redacted to checkout-A and checkout-B and trailing whitespace was trimmed; assertion text and test results are preserved. Issue text and linked PR data were treated only as untrusted claims. No supplied code, script, branch, or patch was run; no external issue-data URL was fetched. No dependency was added.

> AGENT GENERATED