Skip to content

Gallery editor leaks ~31 global listeners per open/close, and a refused closeEditor() stops the agent bridge #7421

Done

Description

@o3LL

Prerequisites

  • I searched open issues and discussions and did not find an existing report of this bug.
  • This is not a security vulnerability.
  • I am running the latest code from the dev branch and the bug still reproduces there.

Odysseus Revision

dev @ 22f937c5

Install Method

Manual Python install (pip / venv)

Operating System

Linux

Steps to Reproduce

  1. Gallery, Edit tab, click a template (Square HD for example).
  2. Close the edit with the x on the Edit tab and confirm.
  3. Repeat 1 and 2 three more times, then open a template a fifth time.
  4. Press Ctrl+K.

Expected Behaviour

One command palette opens.

Actual Behaviour

Five .ge-command-palette overlays open on top of each other, one per editor session.

Every open/close of the editor leaves listeners on window and document behind. I counted them by wrapping addEventListener/removeEventListener in Chromium: 239, 269, 301, 333 live global listeners after closes 1 to 4, so about 31 per cycle (9 resize, 7 keydown, 7 click, 4 pointerdown, plus pointermove, pointerup, focusin, mousemove, mouseup). The palette overlay appended to body by editor/build/command-palette.js is never removed either.

The leaked handlers check state.editorOpen, which is true again on the next open, so the old closures keep running against detached DOM. That is why Ctrl+K fires once per stale session.

Sources: the listeners _buildEditor and _wireAiCommandBox register in static/js/galleryEditor.js (for example onCommandPaletteKey, the capture-phase Escape interceptor, the topbar resize handlers, the text/shape "More" pointerdown closers), plus the document/window listeners in 13 static/js/editor/* modules. closeEditor only removes the click-away handlers and the popup Escape handlers. canvas-events.js, keyboard-shortcuts.js and clipboard-and-drop.js keep their own AbortController, but only abort it on the next open, not on close.

Second, smaller defect in the same teardown: closeEditor() without force removes the ge-editor-open body class, cancels the pen path and stops the agent bridge (window.__geEditorBridge = null) before it checks whether it may close. When it then refuses ("Close the edit tab first") and returns false, the editor stays open with no bridge, so gePhotoEditorApply waits for a bridge that never comes back. The Gallery buttons check before calling, so they don't hit it; a direct call to window.geGalleryEditor.closeEditor() does:

window.__galleryAllowCloseEditor = false;
window.geGalleryEditor.closeEditor();     // false
window.__geEditorBridge;                  // null
window.geGalleryEditor.isEditorOpen();    // true

Logs / Screenshots

Screenshot after four reopens: five stacked palettes.

Ctrl+K on dev after four reopens: five stacked command palettes

Are you willing to submit a fix?

Yes, I can open a PR

Additional Information

This blocks moving editor event wiring out of galleryEditor.js (#4071): the wiring should not move while it leaks.

Activity

  1. added
    ready for review
    on Nov 27, 2026
  2. removed
    ready for review
    on Nov 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions