Skip to content

Make mobile toast swipes reliable - #2984

Merged
ymichael merged 7 commits into
mainfrom
bb/improve-mobile-toast-dismissal-thr_9akfcu22uy
Sep 3, 2026
Merged

ymichael merged 7 commits into
mainfrom
bb/improve-mobile-toast-dismissal-thr_9akfcu22uy

Conversation

@ymichael

@ymichael ymichael commented Sep 3, 2026 •

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

Compact toasts render at top-center, while Sonner derives an upward-only swipe direction from that position and processes the first pointer movement before its React-managed axis has updated. The archived-thread toast exposed a second, more important gap: its linked thread title, Undo action, and close control are buttons, and Sonner deliberately does not begin a swipe when the pointer target is a button. That made most of the real "Thread Archived" toast a swipe dead zone even though plain diagnostic toasts felt reliable.

What changed

  • Allow compact toasts to use Sonner's native top, left, and right swipe directions.
  • Keep the CSS swipe distance continuous while Sonner's axis state catches up, preserving short Android touch movements without replacing Sonner's threshold, animation, callbacks, or toast identity.
  • Bridge touch starts on toast buttons into Sonner's normal swipe handling, then suppress the button click only after movement exceeds tap slop. Normal taps still invoke the thread-title, Undo, and close actions.
  • Add regression coverage using the actual archived-thread toast layout, including tap-versus-drag behavior, continuous batched movement, directional dismissal, rejected downward drags, and rapid stacked-toast identity.

There is no server/host-daemon wire change, so HOST_DAEMON_PROTOCOL_VERSION is unchanged. No CLI, SDK, guide, or user-facing configuration surface changed.

How you verified

  • Physical Android Chrome 152: archived a thread and swiped from the interactive title row; the user confirmed the interaction felt great. Captured movement stayed continuous through 130.8px, and Sonner reported direction: right, removed: true, and swipeOut: true at pointer-up.
  • Physical Android Chrome 152 diagnostic runs: both user-tested runs felt great and completed native swipe-out dismissal.
  • Doobie with a 390×844 touch viewport: 10/10 single-move left, right, up, and upward-diagonal flicks dismissed.
  • iPhone 16 Pro, iOS 18.4 Simulator, Mobile Safari: left, right, up, and both upward diagonals dismissed.
  • pnpm exec turbo run test --filter=@bb/app --force -- --run src/components/AppToaster.test.tsx — 8 tests passed.
  • pnpm exec turbo run typecheck --filter=@bb/app — passed.
  • pnpm exec turbo run lint --filter=@bb/app — passed with 178 existing warnings in unrelated files and 0 errors.
  • pnpm exec oxfmt apps/app/src/components/AppToaster.tsx apps/app/src/components/AppToaster.test.tsx and git diff --check — passed.

AGENT GENERATED

@ymichael

ymichael commented Sep 3, 2026

Copy link
Copy Markdown
Collaborator Author

@slopcop

@bb-slop-cop

bb-slop-cop Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

🚨 SLOP COP 🚨 · review

I am the SlopCop. I am now reviewing this pull request for security, code quality, performance, duplication, and user behavior.

Comment thread apps/app/src/components/AppToaster.tsx Outdated
return null;
}
const elementPosition = `${toastElement.dataset.yPosition}-${toastElement.dataset.xPosition}`;
const activeToasts = toast.getToasts();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚨 slopcop/review — This index can select and dismiss the wrong toast during another toast's exit.

Sonner keeps the exit element and its data-index for 200 ms. toast.getToasts() removes it immediately.

I reproduced this with three stacked toasts. A flick on the middle toast called the oldest toast's onDismiss.

Please use a stable toast identity. Add a test that flicks again before the first exit completes.

@bb-slop-cop bb-slop-cop Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚨 SLOP COP 🚨 · review

Plain English summary

This change helps mobile notifications respond to short left, right, and upward flicks. It adds a fallback when Sonner misses a fast gesture.

Finding

  • Medium: A rapid second flick can dismiss the wrong stacked notification. I reproduced this in the app with three notifications.

The exit element keeps its DOM index for 200 ms. Sonner removes the same notification from toast.getToasts() immediately.

The two lists then have different indexes. The fallback can call onDismiss for a notification that the user did not touch.

See the inline finding. Please use a stable notification identity and add a rapid stacked-notification test.

Other checks

  • The security review found no security or trust-boundary issue.
  • The full app test suite passed 3,805 tests. Four tests remained skipped.
  • The app type check passed.
  • A real Chrome mobile test dismissed one notification after one move.
  • The rapid stacked test reproduced the wrong-notification dismissal.
  • The event listeners attach once and detach correctly.
  • Each touch start scans Sonner's retained notification history. This cost grows with long sessions, but it is a secondary concern.

I found no exact duplicate. useHorizontalDismissDrag has related drag code, but it supports one horizontal direction and panel progress.

Direct reuse would need a larger change. An upstream Sonner fix offers the cleaner long-term design.

I posted this as a comment-only review. I did not approve or request changes.

@ymichael
ymichael merged commit 00e2fc7 into main Sep 3, 2026
15 checks passed
@ymichael
ymichael deleted the bb/improve-mobile-toast-dismissal-thr_9akfcu22uy branch September 3, 2026 16:22
ymichael added a commit that referenced this pull request Sep 5, 2026
## Human comments

## What was wrong

The compact-web toast gesture added in #2984 could leave Sonner's swipe
state active when Safari canceled a pointer or dropped pointer capture.
The toast stayed displaced, and Sonner treated the stack as interacting,
which could pause later automatic dismissals indefinitely. The app also
carried a second gesture implementation alongside Sonner's own tracker.

## What changed

- Patch Sonner 1.7.4 to reset interrupted pointer gestures and resume
toast timers on pointer cancellation or capture loss.
- Keep immediate axis selection, toast-button tap/drag arbitration, and
click suppression inside the toast library.
- Remove the app's duplicate 184-line pointer tracker while preserving
compact left, right, and upward dismissal.
- Add focused regressions for both pointer cancellation and
pointer-capture loss.

## How you verified

- `CI=1 pnpm install --frozen-lockfile --ignore-scripts`
- `pnpm exec turbo run test --filter=@bb/app --force --
'src/components/AppToaster.test.tsx'` (10/10 passed)
- `pnpm exec turbo run typecheck build --filter=@bb/app --force`
- Targeted `oxfmt --check`
- `git diff --check origin/main...HEAD`
- The fixer also ran the full app suite (3,852 passed, 3 skipped), lint
with 0 errors, and compact/desktop browser QA before handoff.

> AGENT GENERATED
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.

1 participant