Skip to content

fix(editor): mounted checks, load-failure close and Edit tab label in the Gallery editor - #7429

Merged
alteixeira20 merged 6 commits into
odysseus-dev:devfrom
o3LL:fix/gallery-editor-close-paths
Dec 2, 2026
Merged

alteixeira20 merged 6 commits into
odysseus-dev:devfrom
o3LL:fix/gallery-editor-close-paths

Conversation

@o3LL

@o3LL o3LL commented Nov 29, 2026 •

Copy link
Copy Markdown
Member

Summary

Three close-path fixes for the Gallery image editor, found while working on #7422 and left out of it because it merged first. One commit each, all in static/js plus tests. It doesn't depend on the editor decomposition PR opened next to it: both touch static/js/galleryEditor.js, but either can merge first and they merge cleanly together.

  1. Mounted checks (Gallery editor "mounted" checks look for a .gallery-editor descendant that never exists #7426). Five guards (gallery.js setup-cancel, Gallery Escape, _doCloseGallery; _galleryEditMounted(); the global Escape guard in ui.js) looked for a .gallery-editor descendant of #gallery-editor-container. _buildEditor() puts that class on the container itself, so all five were always false. They now check #gallery-editor-container > .ge-editor-body, which only exists while the editor is built. The container keeps its class after a close, so matching it instead would count the landing as an open editor. gallery.js:1334 is left to fix(gallery): retain the editor after creating a canvas #7156.
  2. Load failures (Gallery editor: a draft or image that fails to load leaves an empty editor open ("Close the edit tab first") #7427). When a draft is not found, can't be restored, or the image fails to load, openEditor called closeEditor() unforced, which is refused while the editor counts as open: "Close the edit tab first" replaced the real error and an empty editor stayed up. These paths now close with force and fire gallery-editor-setup-cancelled, like a cancelled New canvas, so the landing comes back. They first check that their session is still the open one, so a slow failure from a closed session can't close the next one.
  3. Edit tab label (Gallery editor: the Edit tab keeps "Edit: <name>" after the edit is closed #7428). closeEditor() reset the Edit tab label while state.editorOpen was still true, so the document tab renderer wrote "Edit: " back after every close. The reset now happens once the editor stops counting as open.

Target branch

  • This PR targets the correct integration branch: lab in the private maintainer-preview repository, or dev in the public repository. main remains release-curated.

Linked Issue

Fixes #7426
Fixes #7427
Fixes #7428

Type of Change

  • Bug fix (non-breaking — fixes a confirmed issue)
  • New feature (non-breaking — adds new behaviour)
  • Breaking change (changes or removes existing behaviour)
  • Refactor / cleanup (behaviour unchanged)
  • Documentation only
  • CI / tooling / configuration

Checklist

  • I searched open issues and open PRs — this is not a duplicate.
  • This PR targets the correct integration branch (lab in maintainer-preview; dev in the public repository)
  • My changes are limited to the scope described above — no unrelated refactors or whitespace changes mixed in.
  • I actually ran the app (docker compose up or uvicorn app:app) and verified the change works end-to-end. Type-checks and unit tests are not enough.
  • I did not run the app/runtime validation and stated that gap in How to Test. Leave this unchecked when the app-run box above is checked.

How to Test

  1. python -m pytest tests/test_gallery_editor_mounted_checks_browser.py -p no:randomly: 15 pass. Each of the five guards runs in Chromium against a mounted editor, the landing after a close, and a fresh landing; on dev the five "mounted" cases fail.
  2. npm run test:photo-editor -- load-failure-close edit-tab-label: 6 pass, all 6 fail on dev. A missing draft, a broken draft and a 404 image each end on the landing with one toast; a stale failure can't close the next session; the tab label resets after the tab x close, and the multi-document tab strip still follows its documents.
  3. By hand: save a project, break it (for example imgWidth: 0 through POST /api/editor-drafts), click its card under Saved projects. One "Failed to load draft" toast, the landing, tab reads Edit.
  4. Open a template, close it with the tab x: the tab reads Edit, not Edit: 1024×1024.

Not verified:

  • Firefox, WebKit and a real phone (Chromium only).
  • Docker.
  • Escape with focus inside a styled confirm over the editor hides the Gallery and leaves the confirm up. Same on dev, not touched here.

Visual / UI changes — REQUIRED if you touched anything that renders

  • Screenshot or short clip of the change in the running app, attached below. Mobile screenshot too if the change affects mobile.
  • Style match: the change uses Odysseus's existing visual language. Specifically:
    • Reuse existing CSS variables (--red, --fg, --bg, --card, --border, etc.) — do not introduce new color values, font sizes, or spacing units.
    • Reuse existing button/input/card/border classes. Don't invent parallel styling.
    • No Unicode emoji in UI or code. Use inline SVG (matching the monochrome icon style already in static/index.html) or plain text.
    • Monospaced font (Fira Code) for primary UI text. Don't override.
    • Dark theme is the default; any light-mode work must be wired through the existing theme system, not hard-coded.
  • No new component patterns. If a similar widget already exists in the app, extend it instead of writing a parallel one.
  • I am not an LLM agent submitting a bulk PR. If you are, please open an issue describing the problem first — bulk auto-generated PRs that don't match the project's visual style are closed on sight, even when the underlying fix is correct.

Screenshots / clips

No styling change.

Before (dev): broken saved project clicked, empty editor and "Close the edit tab first"

dev: broken saved project leaves an empty editor and "Close the edit tab first"

After: same project, one error toast, the landing, tab reads Edit

branch: one "Failed to load draft" toast, the landing, tab reads Edit

o3LL added 3 commits November 28, 2026 23:23
…ry-editor descendant

_buildEditor() replaces the container's class with `gallery-editor`, so the
`#gallery-editor-container .gallery-editor` descendant checks in gallery.js,
galleryEditor.js and ui.js never matched. They only behaved because
isEditorOpen() or __galleryEditLive sat next to them; the global Escape
guard in ui.js had no such fallback and was always false.

closeEditor() also leaves that class on the container, so the landing shown
after a close carries it too. Matching the container class instead would
treat that landing as a mounted editor. Check for the editor body element,
which only exists while the editor is built.
…age fails to load

openEditor() mounts the editor shell before it fetches the draft or image.
When that fails (draft not found, draft data that cannot be restored, image
onerror) it called closeEditor() without force. state.editorOpen is true at
that point, so the close was refused: the user got "Close the edit tab
first" on top of the real error and was left in an empty editor.

The three failure paths now close with force and dispatch
gallery-editor-setup-cancelled, the same way a cancelled New canvas does, so
the Gallery renders the Edit tab landing again.

Forcing the close makes a stale failure dangerous: a slow draft fetch from a
session the user already closed could tear down the session opened after
it. The failure paths therefore check that the session they belong to is
still the open one, like the save pipeline already does, and stay silent
otherwise.
closeEditor() reset the Gallery's Edit tab label before it set
state.editorOpen to false. _setEditTabLabel(null) writes "Edit" and then
re-renders the document tabs, and that renderer only checks
state.editorOpen, so it wrote "Edit: <name>" straight back. Every close
path left the old name on the tab: the tab x, a cancelled New canvas and
the load-failure closes.

Reset the label once the editor no longer counts as open. The document tab
strip is unchanged while the editor is open; the new spec also checks it
with two documents.
@github-actions github-actions Bot added needs visual evidence UI-sensitive change without an attested screenshot or clip from the running app ready for review Description complete — ready for maintainer review and removed needs visual evidence UI-sensitive change without an attested screenshot or clip from the running app labels Nov 29, 2026
o3LL added 2 commits November 30, 2026 11:31
With an edit open, closing the Gallery is refused ("Close the edit tab
first"), but two paths still hid the sheet and left it unreachable:

- the sidebar Gallery button: closeGallery() goes through Modals.close(),
  which hides and unregisters the node even when closeFn refuses;
- a swipe-down on the sheet header (ui.js), which hides the node and fires
  modal-dismissed without asking the gallery.

In both cases _open stayed true, so every later tap went back to the
refused close and the edit was stranded in memory.

closeGallery() now refuses before calling Modals.close(), so the button
leaves the sheet in place and only shows the toast. When the sheet is
hidden while an edit is live, isGalleryOpen() reports false and
openGallery() shows the existing sheet again (re-registering it with the
modal manager if needed) instead of building a new one. The swipe gesture
itself is unchanged.
…nd the dock

Phone viewport, real app. With an edit open, the Gallery button must leave
the sheet visible, and one tap must bring back the same edit (same layer
count) after a CDP touch swipe on the header or a refused dock close. All
three fail on dev.

@alteixeira20 alteixeira20 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Reviewed the fixes and verified the integration with the Gallery editor decomposition from #7425.

The original corrections are preserved, all required CI checks and CodeQL pass, and no merge-blocking findings remain.

LGTM! Thanks for identifying and addressing these issues during the decomposition.

@alteixeira20
alteixeira20 merged commit e3d13f4 into odysseus-dev:dev Dec 2, 2026
32 checks passed
touzenesmy pushed a commit to touzenesmy/odysseus that referenced this pull request Dec 3, 2026
…on, load-failure close, live-edit close guard

ADAPT of upstream e3d13f4 (editor fix odysseus-dev#7429) onto the fork's monolithic
galleryEditor.js, preserving fork customizations:

- galleryEditor.js: _galleryEditMounted() now keys off the real body
  element (.ge-editor-body) instead of the stale gallery-editor class;
  openEditor() tracks the open session token and routes every load-failure
  path (missing draft, broken project data, image onerror) through
  _closeEditorAfterLoadFailure(), which force-closes and re-dispatches
  gallery-editor-setup-cancelled so the Gallery's Edit tab returns to its
  landing; closeEditor() resets the Edit-tab label after state.editorOpen
  is false so the document tab strip cannot write the old name back.
- gallery.js: _editorMounted() helper; setup-cancel handler, openGallery()
  re-show, _doCloseGallery()/closeGallery()/isGalleryOpen() all use the
  DOM-based mount check and a live-edit guard so a refused close cannot
  strand a hidden sheet.
- ui.js: swipe-dismiss path adjusted to the same mount check.
- New tests: edit-tab-label, gallery-live-edit-reopen, load-failure-close
  e2e specs + test_gallery_editor_mounted_checks_browser.py.

Gates: browser guard suite 15/15; focused e2e 11 passed, 1 skipped
(multi-document tab strip requires upstream 34d61a6, not yet adopted),
1 failed (core-workflow line 28, #ge-layer-tools .ge-true-mask-btn
timeout) — reproduced identically on the clean 8c60b1a baseline
worktree, i.e. pre-existing, not a regression from this ADAPT.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready for review Description complete — ready for maintainer review

Projects

None yet

2 participants