ZDDC/browse/js
ZDDC cfb2fab401 fix(browse): editor lifecycle — dispose on switch, guard unsaved edits, kill leaks
The markdown/YAML preview editors were never disposed when switching to a
non-editor file: dispose() was only called from inside the same plugin's
render(), so md→PDF/image/YAML overwrote the pane via innerHTML and leaked
the Toast UI instance, its DOM, and document-level resizer drag listeners.
Unsaved edits were also discarded silently on any file switch (including
arrow-key auto-preview), and debounced change handlers could resolve after
an editor was disposed and write the wrong file's dirty/hash state.

preview.js now owns editor lifecycle centrally in renderInline:
- disposeEditors() up front before replacing the pane (fixes the leak for
  every md/yaml → anything switch).
- dirty guard: deliberate switches (click/Enter/menu) confirm before
  discarding; auto previews (keyboard cursor walking the tree, opts.auto)
  leave the dirty editor in place rather than nagging per keystroke;
  re-selecting the file already being edited is a no-op.
- a renderSeq token bails late-arriving loads so a slow file can't paint
  stale content into the pane after a newer selection.
- clearPreview() exposed and used by rescope (events.js) and popstate
  (app.js) so those resets dispose the editor instead of leaking it.
- beforeunload warns when an editor is dirty at page exit.

preview-markdown.js: per-mount AbortController wired into the resizer
document listeners so dispose() detaches them even mid-drag; debounced
change/save/convert handlers guard `currentInstance !== instance` so a
disposed editor's callbacks can't corrupt the active file; expose
isDirty()/currentNode().

preview-yaml.js: track dirty/node state, guard the change handler the same
way, expose dispose()/isDirty()/currentNode().

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-03 14:46:31 -05:00
..
accept-transmittal.js feat(browse,tables): flat-peer clients + dual-mode cross-party aggregate 2026-06-03 12:35:31 -05:00
app.js fix(browse): editor lifecycle — dispose on switch, guard unsaved edits, kill leaks 2026-06-03 14:46:31 -05:00
create-transmittal.js feat: reviewing/ lifecycle — Plan Review endpoint, virtual received window, browse context-menu workflows 2026-05-15 16:08:04 -05:00
download.js refactor: virtual file extensions for subtree zip + MD conversion 2026-05-14 12:23:37 -05:00
events.js fix(browse): editor lifecycle — dispose on switch, guard unsaved edits, kill leaks 2026-06-03 14:46:31 -05:00
grid.js feat(zddc): Phase 4b — grid mode driven by cascade default_tool 2026-05-11 16:15:25 -05:00
history.js feat(history): self-describing per-save snapshots + readable-when-disabled + mdl/rsk/working defaults 2026-06-02 09:51:23 -05:00
hovercard.js feat: show effective permissions + roles per location in the browse hovercard 2026-06-01 11:12:39 -05:00
init.js feat(browse): SPA overhaul — context menu, YAML editor, icons, hovercard, deep links, autofilter 2026-05-14 12:12:42 -05:00
loader.js feat(browse): markdown version-history viewer with diff + restore 2026-05-28 12:49:00 -05:00
plan-review.js refactor(browse): drop status-bar footer, route messages to toasts 2026-05-21 12:19:40 -05:00
preview-markdown.js fix(browse): editor lifecycle — dispose on switch, guard unsaved edits, kill leaks 2026-06-03 14:46:31 -05:00
preview-yaml.js fix(browse): editor lifecycle — dispose on switch, guard unsaved edits, kill leaks 2026-06-03 14:46:31 -05:00
preview.js fix(browse): editor lifecycle — dispose on switch, guard unsaved edits, kill leaks 2026-06-03 14:46:31 -05:00
stage.js feat(browse,tables): flat-peer clients + dual-mode cross-party aggregate 2026-06-03 12:35:31 -05:00
tree.js fix(browse): preserve undefined verbs to distinguish Caddy/FS-API from zddc 2026-05-21 09:00:12 -05:00
upload.js feat(browse): full create/edit/rename/delete in local-directory (offline) mode 2026-06-01 10:46:51 -05:00