super-productivity/packages/plugin-dev/document-mode
Johannes Millan fb306e34b8 fix(document-mode): P1 sweep — context-switch races, flood, re-reg
Addresses the P1 findings from the multi-agent branch review:

- setActiveContext is now guarded by a monotonic activeContextSeq:
  concurrent context switches that resolve out-of-order bail after
  each await instead of writing the previous editor doc under the
  new context's id. Title write timers and pendingTitleWrites are
  cleared on every switch so they can't mutate the next context's
  cache.

- setContent catch path no longer silently overwrites a corrupt
  blob: when parsing fails we set isDocCorrupt and gate scheduleSave
  on it, so the empty seed shown in the editor is never persisted on
  top of the original (possibly recoverable) JSON.

- findParentTaskIdBefore and validInsertRange now iterate
  doc.childCount manually instead of doc.resolve(...).index(0).
  Provably correct at every top-level gap; the resolve+index path
  was flagged by review as mis-resolving for some positions.

- onAnyTaskUpdate only auto-appends a chip on a transition
  absent → present in taskCache (tracked via lastSeenTaskIds).
  Updates for existing tasks — including time-tracking ticks — no
  longer re-insert chips the user has intentionally removed.

- Work-context header button re-registration is now replace, not
  skip. Iframes that re-mount (work-view embed cycling with
  skipCleanupOnDestroy: true) produce a new onClick closure pointing
  at the new Window; the bridge would previously reject the new
  entry as a duplicate and keep posting to the detached Window.
  Spec updated to assert replacement instead of dedup-skip.

- Track lastWrittenTitles per task to seed a future, more robust
  echo-vs-remote-change discrimination in refreshTaskRef (the
  current 500 ms pendingTitleWrites window can still race with a
  concurrent remote edit, but the deeper fix needs a follow-up).
2026-05-21 19:21:12 +02:00
..
scripts feat(document-mode): add TipTap-based document-mode plugin (POC) 2026-05-21 17:22:31 +02:00
src fix(document-mode): P1 sweep — context-switch races, flood, re-reg 2026-05-21 19:21:12 +02:00
.gitignore feat(document-mode): add TipTap-based document-mode plugin (POC) 2026-05-21 17:22:31 +02:00
package-lock.json feat(document-mode): Notion-style UX (gutter, bubble menu, block menu) 2026-05-21 17:34:13 +02:00
package.json feat(document-mode): Notion-style UX (gutter, bubble menu, block menu) 2026-05-21 17:34:13 +02:00
tsconfig.json feat(document-mode): add TipTap-based document-mode plugin (POC) 2026-05-21 17:22:31 +02:00