[GH-ISSUE #3363] [Issue]: In-chat Gallery closes when interacting with an opened image (Copy prompt / selecting text) #1820

Closed
opened 2026-10-21 05:43:00 +07:00 by bsakaguchi · 0 comments
Owner

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

Originally assigned to: @kolacheee on GitHub.

Summary

In the in-chat Gallery, opening an image (its fullscreen preview) and then interacting with it — clicking Copy prompt, selecting the prompt text, or even clicking the image — closes the entire Gallery drawer. On Copy prompt there is also no "Prompt copied." toast (and the prompt may not actually be copied), because the Gallery closes before the copy runs.

Expected behavior

  • Clicking Copy prompt copies the prompt and shows the "Prompt copied." toast; the Gallery and the image preview stay open.
  • Selecting/highlighting the prompt text, or clicking the image, does nothing to the Gallery — it stays open.
  • The Gallery drawer only closes via its ✕ button, Escape, or a click in the chat area outside the gallery UI.

Actual behavior

Any pointer-down inside the opened image preview closes the whole Gallery drawer:

  • Copy prompt → the Gallery closes, no toast appears, and the prompt is (likely) not copied.
  • Select the prompt text (click-drag to highlight) → the Gallery closes the moment you press down to start the selection.
  • Clicking the image itself does the same.

Steps to reproduce

  1. In a chat, open the Gallery (the image gallery drawer).
  2. Click an image to open its fullscreen preview.
  3. Click Copy prompt → the Gallery closes with no toast. Or: click-and-drag to select the prompt text → the Gallery closes.

Environment

  • Marinara Engine version: 2.1.1 (staging)
  • Install type: source
  • OS + version: Windows 11 (not OS-specific — it's a DOM event-handling issue)
  • Browser or app shell: web app

Logs, screenshots, or video

User-reported with a screen recording: open Gallery → open image → Copy prompt exits the Gallery with no toast; retry → selecting the prompt text exits the Gallery again.

Additional context

Root cause — a single bug behind both symptoms.

ChatGalleryDrawer registers a document-level, capture-phase pointerdown listener that closes the drawer whenever the pointer-down target is outside the drawer (packages/client/src/components/chat/ChatGalleryDrawer.tsx:60-70):

const handlePointerDown = (event: PointerEvent) => {
  const target = event.target;
  if (!(target instanceof Node)) return;
  if (panelRef.current?.contains(target)) return;                                   // inside the drawer → keep open
  if (target instanceof Element && target.closest("[data-chat-floating-panel]")) return; // inside a floating panel → keep open
  onClose();                                                                        // otherwise → close the drawer
};
document.addEventListener("pointerdown", handlePointerDown, true); // capture phase

The image preview ChatImageLightbox is rendered with createPortal(..., document.body) (packages/client/src/components/chat/ChatImageLightbox.tsx:71), so its DOM lives directly on document.body — outside both panelRef and any [data-chat-floating-panel]. So any pointer-down inside the lightbox (the Copy prompt button, the prompt text, the image) matches neither exclusion and triggers onClose(), closing the whole Gallery drawer.

Because the listener is registered in the capture phase (addEventListener(..., true)), the stopPropagation() calls on the lightbox/panel's bubble-phase onPointerDown (ChatImageLightbox.tsx:107, ImagePromptPanel.tsx:34 & :43) fire too late to stop it — capture runs first.

This one cause explains the missing toast too: the pointer-down closes the drawer (unmounting ChatGallery and the lightbox) before the Copy button's onClick handler can run — and that handler is where the copy + toast live (handleCopyPrompt → toast.success("Prompt copied."), ImagePromptPanel.tsx:19-29). So the copy/toast never fire. It is not intended that Copy prompt closes the Gallery; the copy handler closes nothing.

The video preview ChatVideoLightbox is also a document.body portal (ChatImageLightbox.tsx:177), so it has the same problem.

Suggested fix: exclude the lightbox portal from the drawer's outside-close check. Options, cheapest first:

  • Also return when target.closest('[role="dialog"]') — the lightbox is role="dialog" aria-modal="true", so this covers both image and video previews (and any future modal on top of the drawer).
  • Or tag the lightbox root element with data-chat-floating-panel (reuse the existing exclusion pattern).
  • Or suppress the drawer's outside-close listener while a lightbox/modal is open (a modal aria-modal dialog on top should block the drawer's outside-click entirely).

Any of these keeps the Gallery open during image interactions and lets the "Prompt copied." toast fire on Copy prompt.

Template check

  • I DID NOT read this template and provide the requested details.
Originally created by @kolacheee on GitHub (Jul 8, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/3363 Originally assigned to: @kolacheee on GitHub. ## Summary In the in-chat **Gallery**, opening an image (its fullscreen preview) and then interacting with it — clicking **Copy prompt**, selecting the prompt text, or even clicking the image — closes the **entire Gallery drawer**. On **Copy prompt** there is also no *"Prompt copied."* toast (and the prompt may not actually be copied), because the Gallery closes before the copy runs. ## Expected behavior - Clicking **Copy prompt** copies the prompt and shows the *"Prompt copied."* toast; the Gallery and the image preview stay open. - Selecting/highlighting the prompt text, or clicking the image, does nothing to the Gallery — it stays open. - The Gallery drawer only closes via its **✕** button, **Escape**, or a click in the chat area outside the gallery UI. ## Actual behavior Any pointer-down inside the opened image preview closes the whole Gallery drawer: - **Copy prompt** → the Gallery closes, no toast appears, and the prompt is (likely) not copied. - **Select the prompt text** (click-drag to highlight) → the Gallery closes the moment you press down to start the selection. - Clicking the image itself does the same. ## Steps to reproduce 1. In a chat, open the **Gallery** (the image gallery drawer). 2. Click an image to open its fullscreen preview. 3. Click **Copy prompt** → the Gallery closes with no toast. **Or:** click-and-drag to select the prompt text → the Gallery closes. ## Environment - Marinara Engine version: 2.1.1 (staging) - Install type: source - OS + version: Windows 11 (not OS-specific — it's a DOM event-handling issue) - Browser or app shell: web app ## Logs, screenshots, or video User-reported with a screen recording: open Gallery → open image → **Copy prompt** exits the Gallery with no toast; retry → selecting the prompt text exits the Gallery again. ## Additional context **Root cause — a single bug behind both symptoms.** `ChatGalleryDrawer` registers a document-level, **capture-phase** `pointerdown` listener that closes the drawer whenever the pointer-down target is outside the drawer (`packages/client/src/components/chat/ChatGalleryDrawer.tsx:60-70`): ```ts const handlePointerDown = (event: PointerEvent) => { const target = event.target; if (!(target instanceof Node)) return; if (panelRef.current?.contains(target)) return; // inside the drawer → keep open if (target instanceof Element && target.closest("[data-chat-floating-panel]")) return; // inside a floating panel → keep open onClose(); // otherwise → close the drawer }; document.addEventListener("pointerdown", handlePointerDown, true); // capture phase ``` The image preview `ChatImageLightbox` is rendered with `createPortal(..., document.body)` (`packages/client/src/components/chat/ChatImageLightbox.tsx:71`), so its DOM lives directly on `document.body` — **outside** both `panelRef` and any `[data-chat-floating-panel]`. So any pointer-down inside the lightbox (the **Copy prompt** button, the prompt text, the image) matches neither exclusion and triggers `onClose()`, closing the whole Gallery drawer. Because the listener is registered in the **capture phase** (`addEventListener(..., true)`), the `stopPropagation()` calls on the lightbox/panel's *bubble-phase* `onPointerDown` (`ChatImageLightbox.tsx:107`, `ImagePromptPanel.tsx:34` & `:43`) fire too late to stop it — capture runs first. This one cause explains the missing toast too: the pointer-down closes the drawer (unmounting `ChatGallery` and the lightbox) **before** the Copy button's `onClick` handler can run — and that handler is where the copy + toast live (`handleCopyPrompt` → `toast.success("Prompt copied.")`, `ImagePromptPanel.tsx:19-29`). So the copy/toast never fire. It is **not** intended that Copy prompt closes the Gallery; the copy handler closes nothing. The video preview `ChatVideoLightbox` is also a `document.body` portal (`ChatImageLightbox.tsx:177`), so it has the same problem. **Suggested fix:** exclude the lightbox portal from the drawer's outside-close check. Options, cheapest first: - Also `return` when `target.closest('[role="dialog"]')` — the lightbox is `role="dialog" aria-modal="true"`, so this covers both image and video previews (and any future modal on top of the drawer). - Or tag the lightbox root element with `data-chat-floating-panel` (reuse the existing exclusion pattern). - Or suppress the drawer's outside-close listener while a lightbox/modal is open (a modal `aria-modal` dialog on top should block the drawer's outside-click entirely). Any of these keeps the Gallery open during image interactions and lets the *"Prompt copied."* toast fire on Copy prompt. ## Template check - [ ] I DID NOT read this template and provide the requested details.
bsakaguchi 2026-10-21 05:43:00 +07:00
  • closed this issue
  • added the
    bug
    label
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#1820
No description provided.