[GH-ISSUE #2799] [Issue]: Mobile: chat notification bubbles never auto-dismiss — they stack and each must be closed manually #1423

Closed
opened 2026-10-21 05:33:36 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @kolacheee on GitHub (Jun 22, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2799

Summary

On mobile, the floating chat notification bubbles (the avatar circles that appear on the right edge of the chat view when a character messages you in another conversation) never go away on their own. They are only removed when the user manually taps the per-bubble X, opens that chat, or the chat is deleted. As more conversations generate messages, the bubbles stack up and each one has to be dismissed by hand.

The bubbles are rendered by packages/client/src/components/chat/ChatNotificationBubbles.tsx and backed by the chatNotifications map in packages/client/src/stores/chat.store.ts. The store's addNotification action has no auto-dismiss timer anywhere — removal is exclusively manual or on-chat-open. That is the literal match for the report wording ("notification bubbles never auto-dismiss; they stack and each must be closed manually").

Note on prior investigation: an earlier pass attributed this to sonner toasts (<Toaster> in App.tsx) not auto-fading on mobile. That mechanism is incorrect — see "Root cause" for why sonner toasts do auto-dismiss on touch devices. The sonner-side change is captured only as an optional secondary polish, not the fix.

Symptom & UX impact (mobile)

  • Background conversations (autonomous/group activity, or replies arriving while you're in a different chat) push avatar bubbles onto the right edge.
  • The bubbles persist indefinitely. There is no fade-out, no timeout.
  • On a phone they accumulate; once there are 2+, mobile collapses them into a tappable stacked-avatar group that the user must expand and then dismiss one-by-one via each bubble's X (ChatNotificationBubbles.tsx:163-177).
  • Net effect: visual clutter that the user has to actively clean up, with no way to "let them disappear." This is a polish/UX annoyance — nothing is broken and manual dismissal still works — hence low severity.

Steps to reproduce

On a mobile/touch device (or a narrow viewport, ≤ md):

  1. Have at least two chats. Open chat A.
  2. Trigger a message in chat B (and chat C) while A is active — e.g. background/autonomous activity, or a group/other-character reply that routes through addNotification.
  3. Observe one avatar bubble appear on the right edge per other-chat. With 2+, they collapse into a stacked-avatar group on mobile.
  4. Do nothing and wait. Expected: the bubbles fade after some seconds. Actual: they never disappear; each must be tapped (X) to clear, or the corresponding chat opened.

Root cause (exact file:line trace)

True source — avatar notification bubbles, no auto-dismiss timer:

  1. Notifications are created by useChatStore.addNotification(...), called from:
    • packages/client/src/hooks/use-background-autonomous.ts:238
    • packages/client/src/hooks/use-generate.ts:1621
    • packages/client/src/hooks/use-generate.ts:2251
  2. The store action packages/client/src/stores/chat.store.ts:605-620 inserts/increments the entry in the chatNotifications Map. There is no setTimeout/auto-expiry anywhere in this action or the store.
  3. Removal happens only via:
    • dismissNotification(chatId) — the manual X (chat.store.ts:621-628),
    • opening that chat / setActiveChatId guard (addNotification early-returns when the chat is active, chat.store.ts:608),
    • server reconciliation deleting unknown/missing chats (chat.store.ts:589-593).
  4. The component packages/client/src/components/chat/ChatNotificationBubbles.tsx renders one NotificationBubble per entry (desktop: lines 49-60; mobile collapsed/expanded: lines 62-132) and only ever calls dismissNotification from the per-bubble X (onDismiss, lines 56 / 75-78 / 163-177). It is mounted in packages/client/src/components/layout/AppShell.tsx:863. No timer here either.

Because nothing schedules removal, the bubbles live until the user acts — exactly the reported behavior.

Important nuance for the fix: dismissNotification not only removes the bubble, it adds the chat id to a persistent dismissedNotifications set (chat.store.ts:625-626), which permanently suppresses future notifications for that chat (addNotification early-returns on it, chat.store.ts:609). An auto-dismiss must therefore not call dismissNotification — it must remove only from chatNotifications so later messages can re-notify.

Why the earlier sonner-toast theory is wrong (so the PR author doesn't chase it):

  • The bundled sonner@2.0.7 auto-close timer (node_modules/.pnpm/sonner@2.0.7…/dist/index.mjs:589-612) runs startTimer() for every toast and only pauses when expanded || interacting || isDocumentHidden (line 605).
  • expanded is set true only by onMouseEnter/onMouseMove (lines 1128-1129) — neither fires on touch. interacting is set on pointer-down and cleared on pointer-up (lines 1140-1142), so a tap doesn't pin anything.
  • Therefore on mobile expanded stays false → the timer runs → toasts auto-dismiss after their duration. Toasts beyond visibleToasts are still mounted and still run their own timers (visibleToasts controls rendering count, not lifetime).
  • Consequently, adding expand/expandByDefault to <Toaster> would force data-expanded=true (dist/index.mjs:666, 1052) and hit the pause branch — counterproductive, it would stop toasts from auto-closing. Do not do this.

Suggested fix (concrete)

Primary — add an auto-dismiss timer for the avatar bubbles, centrally in the store. Schedule a timeout in addNotification that removes the entry from chatNotifications only (never touching dismissedNotifications), reset on re-notify, and skip while that chat is active.

In packages/client/src/stores/chat.store.ts:

// Module-scope timer registry (outside create()):
const NOTIFICATION_AUTODISMISS_MS = 8000;
const notificationTimers = new Map<string, ReturnType<typeof setTimeout>>();

function clearNotificationTimer(chatId: string) {
  const t = notificationTimers.get(chatId);
  if (t) {
    clearTimeout(t);
    notificationTimers.delete(chatId);
  }
}

// Remove a bubble WITHOUT marking it dismissed (so future messages can re-notify).
// Add this as a store action `autoDismissNotification`:
autoDismissNotification: (chatId) =>
  set((state) => {
    if (!state.chatNotifications.has(chatId)) return state;
    const m = new Map(state.chatNotifications);
    m.delete(chatId);
    return { chatNotifications: m };
  }),

Then in addNotification (chat.store.ts:605-620), after computing the new map, (re)arm the timer:

addNotification: (chatId, characterName, avatarUrl, avatarCrop) =>
  set((state) => {
    if (state.activeChatId === chatId) return state;
    if (state.dismissedNotifications.has(chatId)) return state;
    const m = new Map(state.chatNotifications);
    const existing = m.get(chatId);
    m.set(chatId, {
      chatId,
      characterName,
      avatarUrl,
      avatarCrop: avatarCrop ?? existing?.avatarCrop ?? null,
      count: (existing?.count ?? 0) + 1,
    });

    // (Re)arm auto-dismiss so each new message extends the bubble's life,
    // then it fades on its own. Use get() to call the action, not dismissNotification.
    clearNotificationTimer(chatId);
    notificationTimers.set(
      chatId,
      setTimeout(() => {
        clearNotificationTimer(chatId);
        get().autoDismissNotification(chatId);
      }, NOTIFICATION_AUTODISMISS_MS),
    );

    return { chatNotifications: m };
  }),

Also clear the timer in dismissNotification and wherever entries are removed (the reconciliation block at chat.store.ts:589-593 and on setActiveChatId) to avoid stray timers firing against deleted chats. Add autoDismissNotification to the store interface near chat.store.ts:188-194.

Alternative (component-local). Instead of the store, add a useEffect per bubble inside ChatNotificationBubbles.tsx that calls an auto-remove after N ms and clears on unmount. This is simpler to read but spreads timer logic across mounts and is harder to coordinate with the mobile collapsed/expanded state; the store approach is preferred because it is central and keeps the suppression-set distinction correct.

Consideration: when bubbles are mobile-expanded by the user (mobileExpanded, ChatNotificationBubbles.tsx:27/65), consider pausing auto-dismiss so a bubble doesn't vanish mid-interaction. Simplest acceptable behavior: let the timer run regardless; if it proves jarring in testing, gate the timer on !activeInteraction.

Secondary (optional, toast polish — not required for this report): transient generation-error toasts in packages/client/src/hooks/use-generate.ts:39-42 have no stable id, so repeated identical errors (e.g. "No API connection configured for this chat", returned at packages/server/src/routes/generate.routes.ts:1351) stack as separate toasts. Giving them a stable id de-dupes them (matching the existing CSRF-cooldown pattern in packages/client/src/lib/csrf-fetch.ts:9-42):

toast.error(msg, { id: `generation-error:${msg}`, duration: 15000, ...options });

Optionally lower the 15000ms duration (e.g. 6000ms) since these are transient send errors. Do NOT add expand/expandByDefault to <Toaster> (App.tsx:537) — per the trace above it would pause auto-close on mobile. visibleToasts is harmless but does not fix anything.

Affected files

  • packages/client/src/stores/chat.store.ts — primary fix (auto-dismiss timer + autoDismissNotification action + timer cleanup).
  • packages/client/src/components/chat/ChatNotificationBubbles.tsx — the bubbles UI; alternative fix location; verify expanded-state interaction.
  • packages/client/src/components/layout/AppShell.tsx — mount point (:863), context only.
  • packages/client/src/hooks/use-background-autonomous.ts, packages/client/src/hooks/use-generate.ts — callers of addNotification (:238, :1621, :2251); context for the timer behavior.
  • (Optional secondary) packages/client/src/hooks/use-generate.ts (showError, :39-42), packages/client/src/App.tsx (<Toaster>, :537) — toast dedupe polish; packages/client/src/lib/csrf-fetch.ts (:9-42) precedent.

Validation

  • pnpm install then pnpm check (TypeScript + ESLint) passes.
  • Triggering a cross-chat message while in a different chat shows one avatar bubble, which auto-dismisses after the configured timeout without any tap.
  • A new message for an already-bubbled chat resets/extends the timer (no premature disappear) and increments the count badge.
  • After auto-dismiss, a subsequent message for the same chat re-creates the bubble (auto-dismiss did NOT add the chat to dismissedNotifications).
  • Manual X still works and still permanently suppresses that chat's notifications for the session (existing behavior preserved).
  • Opening the chat still clears its bubble; no stray timer later removes/affects an unrelated chat.
  • Deleting a chat (server reconciliation, chat.store.ts:589-593) clears any pending timer for it (no timer fires against a removed chat).
  • No timer leaks: rapidly generating many notifications and dismissing them leaves no orphaned setTimeout callbacks mutating state.
  • (If secondary toast change applied) Repeatedly tapping Send with no API connection shows a single de-duped error toast that auto-fades; distinct errors still appear separately.
  • Mobile-viewport manual check at Display Size Small (≈320–360px wide): bubbles appear, collapse into the stacked-avatar group at 2+, and auto-dismiss; expanded group behaves sanely.
  • Mobile-viewport manual check at Display Size Medium (≈375–414px wide): same as above.
  • Mobile-viewport manual check at Display Size Large (≈428–480px wide): same as above.
  • Tablet/md breakpoint check: desktop layout (all bubbles shown, lines 49-60) also auto-dismisses correctly.

AI-investigated against released 2.0.0; verify before fixing.

Originally created by @kolacheee on GitHub (Jun 22, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2799 ## Summary On mobile, the floating **chat notification bubbles** (the avatar circles that appear on the right edge of the chat view when a character messages you in *another* conversation) never go away on their own. They are only removed when the user manually taps the per-bubble **X**, opens that chat, or the chat is deleted. As more conversations generate messages, the bubbles stack up and each one has to be dismissed by hand. The bubbles are rendered by `packages/client/src/components/chat/ChatNotificationBubbles.tsx` and backed by the `chatNotifications` map in `packages/client/src/stores/chat.store.ts`. The store's `addNotification` action has **no auto-dismiss timer** anywhere — removal is exclusively manual or on-chat-open. That is the literal match for the report wording ("notification bubbles never auto-dismiss; they stack and each must be closed manually"). > Note on prior investigation: an earlier pass attributed this to sonner toasts (`<Toaster>` in `App.tsx`) not auto-fading on mobile. That mechanism is **incorrect** — see "Root cause" for why sonner toasts *do* auto-dismiss on touch devices. The sonner-side change is captured only as an optional secondary polish, not the fix. ## Symptom & UX impact (mobile) - Background conversations (autonomous/group activity, or replies arriving while you're in a different chat) push avatar bubbles onto the right edge. - The bubbles persist indefinitely. There is no fade-out, no timeout. - On a phone they accumulate; once there are 2+, mobile collapses them into a tappable stacked-avatar group that the user must expand and then dismiss one-by-one via each bubble's X (`ChatNotificationBubbles.tsx:163-177`). - Net effect: visual clutter that the user has to actively clean up, with no way to "let them disappear." This is a polish/UX annoyance — nothing is broken and manual dismissal still works — hence **low** severity. ## Steps to reproduce On a mobile/touch device (or a narrow viewport, ≤ `md`): 1. Have at least two chats. Open chat A. 2. Trigger a message in chat B (and chat C) while A is active — e.g. background/autonomous activity, or a group/other-character reply that routes through `addNotification`. 3. Observe one avatar bubble appear on the right edge per other-chat. With 2+, they collapse into a stacked-avatar group on mobile. 4. Do nothing and wait. **Expected:** the bubbles fade after some seconds. **Actual:** they never disappear; each must be tapped (X) to clear, or the corresponding chat opened. ## Root cause (exact file:line trace) **True source — avatar notification bubbles, no auto-dismiss timer:** 1. Notifications are created by `useChatStore.addNotification(...)`, called from: - `packages/client/src/hooks/use-background-autonomous.ts:238` - `packages/client/src/hooks/use-generate.ts:1621` - `packages/client/src/hooks/use-generate.ts:2251` 2. The store action `packages/client/src/stores/chat.store.ts:605-620` inserts/increments the entry in the `chatNotifications` Map. **There is no `setTimeout`/auto-expiry anywhere in this action or the store.** 3. Removal happens only via: - `dismissNotification(chatId)` — the manual X (`chat.store.ts:621-628`), - opening that chat / `setActiveChatId` guard (`addNotification` early-returns when the chat is active, `chat.store.ts:608`), - server reconciliation deleting unknown/missing chats (`chat.store.ts:589-593`). 4. The component `packages/client/src/components/chat/ChatNotificationBubbles.tsx` renders one `NotificationBubble` per entry (desktop: lines 49-60; mobile collapsed/expanded: lines 62-132) and only ever calls `dismissNotification` from the per-bubble X (`onDismiss`, lines 56 / 75-78 / 163-177). It is mounted in `packages/client/src/components/layout/AppShell.tsx:863`. **No timer here either.** Because nothing schedules removal, the bubbles live until the user acts — exactly the reported behavior. **Important nuance for the fix:** `dismissNotification` not only removes the bubble, it adds the chat id to a persistent `dismissedNotifications` set (`chat.store.ts:625-626`), which **permanently suppresses future notifications for that chat** (`addNotification` early-returns on it, `chat.store.ts:609`). An auto-dismiss must therefore **not** call `dismissNotification` — it must remove only from `chatNotifications` so later messages can re-notify. **Why the earlier sonner-toast theory is wrong (so the PR author doesn't chase it):** - The bundled `sonner@2.0.7` auto-close timer (`node_modules/.pnpm/sonner@2.0.7…/dist/index.mjs:589-612`) runs `startTimer()` for every toast and only *pauses* when `expanded || interacting || isDocumentHidden` (line 605). - `expanded` is set true only by `onMouseEnter`/`onMouseMove` (lines 1128-1129) — neither fires on touch. `interacting` is set on pointer-down and cleared on pointer-up (lines 1140-1142), so a tap doesn't pin anything. - Therefore on mobile `expanded` stays false → the timer runs → toasts **auto-dismiss after their duration**. Toasts beyond `visibleToasts` are still mounted and still run their own timers (`visibleToasts` controls rendering count, not lifetime). - Consequently, adding `expand`/`expandByDefault` to `<Toaster>` would force `data-expanded=true` (`dist/index.mjs:666`, `1052`) and hit the *pause* branch — **counterproductive**, it would stop toasts from auto-closing. Do not do this. ## Suggested fix (concrete) **Primary — add an auto-dismiss timer for the avatar bubbles, centrally in the store.** Schedule a timeout in `addNotification` that removes the entry from `chatNotifications` only (never touching `dismissedNotifications`), reset on re-notify, and skip while that chat is active. In `packages/client/src/stores/chat.store.ts`: ```ts // Module-scope timer registry (outside create()): const NOTIFICATION_AUTODISMISS_MS = 8000; const notificationTimers = new Map<string, ReturnType<typeof setTimeout>>(); function clearNotificationTimer(chatId: string) { const t = notificationTimers.get(chatId); if (t) { clearTimeout(t); notificationTimers.delete(chatId); } } // Remove a bubble WITHOUT marking it dismissed (so future messages can re-notify). // Add this as a store action `autoDismissNotification`: autoDismissNotification: (chatId) => set((state) => { if (!state.chatNotifications.has(chatId)) return state; const m = new Map(state.chatNotifications); m.delete(chatId); return { chatNotifications: m }; }), ``` Then in `addNotification` (chat.store.ts:605-620), after computing the new map, (re)arm the timer: ```ts addNotification: (chatId, characterName, avatarUrl, avatarCrop) => set((state) => { if (state.activeChatId === chatId) return state; if (state.dismissedNotifications.has(chatId)) return state; const m = new Map(state.chatNotifications); const existing = m.get(chatId); m.set(chatId, { chatId, characterName, avatarUrl, avatarCrop: avatarCrop ?? existing?.avatarCrop ?? null, count: (existing?.count ?? 0) + 1, }); // (Re)arm auto-dismiss so each new message extends the bubble's life, // then it fades on its own. Use get() to call the action, not dismissNotification. clearNotificationTimer(chatId); notificationTimers.set( chatId, setTimeout(() => { clearNotificationTimer(chatId); get().autoDismissNotification(chatId); }, NOTIFICATION_AUTODISMISS_MS), ); return { chatNotifications: m }; }), ``` Also clear the timer in `dismissNotification` and wherever entries are removed (the reconciliation block at `chat.store.ts:589-593` and on `setActiveChatId`) to avoid stray timers firing against deleted chats. Add `autoDismissNotification` to the store interface near `chat.store.ts:188-194`. **Alternative (component-local).** Instead of the store, add a `useEffect` per bubble inside `ChatNotificationBubbles.tsx` that calls an auto-remove after N ms and clears on unmount. This is simpler to read but spreads timer logic across mounts and is harder to coordinate with the mobile collapsed/expanded state; the store approach is preferred because it is central and keeps the suppression-set distinction correct. **Consideration:** when bubbles are mobile-expanded by the user (`mobileExpanded`, `ChatNotificationBubbles.tsx:27/65`), consider pausing auto-dismiss so a bubble doesn't vanish mid-interaction. Simplest acceptable behavior: let the timer run regardless; if it proves jarring in testing, gate the timer on `!activeInteraction`. **Secondary (optional, toast polish — not required for this report):** transient generation-error toasts in `packages/client/src/hooks/use-generate.ts:39-42` have no stable `id`, so repeated identical errors (e.g. "No API connection configured for this chat", returned at `packages/server/src/routes/generate.routes.ts:1351`) stack as separate toasts. Giving them a stable id de-dupes them (matching the existing CSRF-cooldown pattern in `packages/client/src/lib/csrf-fetch.ts:9-42`): ```ts toast.error(msg, { id: `generation-error:${msg}`, duration: 15000, ...options }); ``` Optionally lower the 15000ms duration (e.g. 6000ms) since these are transient send errors. **Do NOT add `expand`/`expandByDefault` to `<Toaster>` (`App.tsx:537`)** — per the trace above it would pause auto-close on mobile. `visibleToasts` is harmless but does not fix anything. ## Affected files - `packages/client/src/stores/chat.store.ts` — primary fix (auto-dismiss timer + `autoDismissNotification` action + timer cleanup). - `packages/client/src/components/chat/ChatNotificationBubbles.tsx` — the bubbles UI; alternative fix location; verify expanded-state interaction. - `packages/client/src/components/layout/AppShell.tsx` — mount point (`:863`), context only. - `packages/client/src/hooks/use-background-autonomous.ts`, `packages/client/src/hooks/use-generate.ts` — callers of `addNotification` (`:238`, `:1621`, `:2251`); context for the timer behavior. - (Optional secondary) `packages/client/src/hooks/use-generate.ts` (`showError`, `:39-42`), `packages/client/src/App.tsx` (`<Toaster>`, `:537`) — toast dedupe polish; `packages/client/src/lib/csrf-fetch.ts` (`:9-42`) precedent. ## Validation - [ ] `pnpm install` then `pnpm check` (TypeScript + ESLint) passes. - [ ] Triggering a cross-chat message while in a different chat shows one avatar bubble, which auto-dismisses after the configured timeout without any tap. - [ ] A new message for an already-bubbled chat resets/extends the timer (no premature disappear) and increments the count badge. - [ ] After auto-dismiss, a subsequent message for the same chat **re-creates** the bubble (auto-dismiss did NOT add the chat to `dismissedNotifications`). - [ ] Manual X still works and still permanently suppresses that chat's notifications for the session (existing behavior preserved). - [ ] Opening the chat still clears its bubble; no stray timer later removes/affects an unrelated chat. - [ ] Deleting a chat (server reconciliation, `chat.store.ts:589-593`) clears any pending timer for it (no timer fires against a removed chat). - [ ] No timer leaks: rapidly generating many notifications and dismissing them leaves no orphaned `setTimeout` callbacks mutating state. - [ ] (If secondary toast change applied) Repeatedly tapping Send with no API connection shows a single de-duped error toast that auto-fades; distinct errors still appear separately. - [ ] Mobile-viewport manual check at Display Size **Small** (≈320–360px wide): bubbles appear, collapse into the stacked-avatar group at 2+, and auto-dismiss; expanded group behaves sanely. - [ ] Mobile-viewport manual check at Display Size **Medium** (≈375–414px wide): same as above. - [ ] Mobile-viewport manual check at Display Size **Large** (≈428–480px wide): same as above. - [ ] Tablet/`md` breakpoint check: desktop layout (all bubbles shown, lines 49-60) also auto-dismisses correctly. --- _AI-investigated against released 2.0.0; verify before fixing._
Author
Owner

@SpicyMarinara commented on GitHub (Jun 22, 2026):

Addressed in PR #2790 / commit acab1fba: chat notification bubbles now auto-dismiss after a short timeout, timers are cleaned up when chats open/reset, and mobile expanded stacks can be dismissed together.

<!-- gh-comment-id:4772440945 --> @SpicyMarinara commented on GitHub (Jun 22, 2026): Addressed in PR #2790 / commit acab1fba: chat notification bubbles now auto-dismiss after a short timeout, timers are cleaned up when chats open/reset, and mobile expanded stacks can be dismissed together.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#1423
No description provided.