Skip to content

fix(transcript): exclude disclosure title toggle from reading hold - #1888

Merged
vastsa merged 2 commits into
vastsa:mainfrom
soulet:fix/transcript-disclosure-click-collapse
Oct 26, 2026
Merged

vastsa merged 2 commits into
vastsa:mainfrom
soulet:fix/transcript-disclosure-click-collapse

Conversation

@soulet

@soulet soulet commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

Problem

When clicking a collapsed transcript disclosure header (such as a shell command or thinking row) to view details, the row momentarily flashes open and immediately collapses back. Clicking it a second time successfully expands it without collapsing.

Cause

In commit 6e6f862 / PR #1808, useAutomaticDisclosure introduced transient reading protection via ownsReadingPosition(titleRef.current, bodyRef.current) and a global event hub listening to focusin and pointerup.

When a reader presses the pointer on a collapsed disclosure header <button ref={titleRef}>:

  1. The button gains keyboard focus (focusin), triggering syncReading().
  2. Because titleRef.current was passed into ownsReadingPosition, level.contains(document.activeElement) evaluated to true, setting reading = true.
  3. For an unchosen item (choice === undefined), requestedOpen derived from (derivedOpen || reading) flipped to true, causing the disclosure body to render and updating currentOpen.current = true.
  4. The subsequent click event fired toggle(), which evaluated setManualOpen(!currentOpen.current) -> setManualOpen(false). This collapsed the row back and explicitly recorded { open: false } into choices.

On the second click, choice was already { open: false }, which bypassed the (derivedOpen || reading) branch, allowing the toggle to work normally.

Fix

  • In useAutomaticDisclosure, restrict ownsReading and syncReading to inspect bodyRef.current only. The toggle button (titleRef) controls expansion and is not part of the active reading content. Keyboard focus or text selections inside an ancestor's bodyRef already protect the enclosing level.
  • Added a regression test in apps/desktop/test/transcript-disclosure-reading.test.mjs verifying reading protection inspects bodyRef.current and excludes the toggle title.

Verification

  • node --test apps/desktop/test/transcript-disclosure-reading.test.mjs apps/desktop/test/activity-group-folding.test.mjs apps/desktop/test/thinking-ui.test.mjs apps/desktop/test/transcript-display-modes-ui.test.mjs — 36/36 pass
  • pnpm --filter @pi-desktop/desktop typecheck — 0 errors
  • node scripts/check-pr-base-main.mjs — passed (HEAD is ahead of origin/main)
  • node scripts/check-agent-policy-sync.mjs — passed

When clicking a collapsed disclosure header (such as a command or thinking
row), focus was placed on the title button. Because reading position
protection checked both the title and body elements, focus on the title
caused the disclosure to immediately claim a transient reading hold and
preemptively expand before click completed.

The subsequent click event then read the already-expanded state and
toggled it closed, recording an explicit collapsed choice and causing a
visible flash-collapse on first click.

Exclude titleRef from the level's own reading hold checks so only
keyboard focus or text selections inside the expanded body keep the
disclosure open. Add a regression test to pin the reading hold scope.
@vastsa
vastsa merged commit 79eae84 into vastsa:main Oct 26, 2026
1 check passed

vastsa commented Oct 26, 2026

Copy link
Copy Markdown
Owner

Merged after verifying the root cause with the actual React hook in isolated Chromium: on old main, focusing the untouched collapsed header and then clicking leaves it collapsed (afterFocus=true, afterClick=false); with this change, focus leaves it closed and the first click opens it. The candidate also passes the 36 affected transcript tests, Desktop typecheck, and the real-React/Electron disclosure-anchor E2E (including nested/dock geometry). Current main was merged into the contributor branch without rewriting history; the updated PR head has exactly the tested integration tree. No design/style change is included. Thank you for the focused fix.

This branch was previously deployed

1 inactive deployment
Preview — eccab481 Deployed Oct 26, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants