Files
pad/web/src
xarmian 1ef7a21de2 fix(editor): add NodeView update() hook to MermaidCodeBlock (TASK-1249) (#447)
* fix(editor): add NodeView update() hook to MermaidCodeBlock (TASK-1249)

Mermaid diagrams previously froze on the SVG generated when the NodeView
was first created. ProseMirror only recreates a NodeView on node identity
change; in-place text edits don't trigger that, and the existing factory
had no `update()` hook to re-queue a render — so editing the source via
the hover-revealed `< >` toggle silently mutated the code while the
diagram showed stale output. Resolves BUG-1246.

Implementation matches the pattern verified in the TASK-1245 spike
(iteration 3, dev sandbox at /dev/yjs-sandbox) but with precise
ProseMirror Node typing instead of `any`:

- update(updatedNode) returns false on type mismatch or when the
  language attr flips into/out of `mermaid` — different DOM shape, so
  ProseMirror must tear down + recreate the NodeView.
- Returns true (in-place update accepted) when same-node + same-lang;
  re-queues queueMermaidRender only when textContent actually changed.
- Empty source clears the diagram element and the mermaid-error class.
- Toggle state survives because we don't recreate the wrapper.

Becomes a hard blocker once Yjs collab lands (PLAN-1248) since remote
ops will constantly mutate mermaid source text mid-view.

Parent: PLAN-1248.

* fix(editor): serialize mermaid clear + drop error class on success per Codex review (round 1)

Two issues raised in PR #447 review:

P2 — Pending queueMermaidRender() could overwrite a synchronous diagram
clear with a stale SVG, racing against a freshly-emptied source. Route
the clear through the same renderQueue (queueMermaidClear) so it executes
strictly after any in-flight render for the same target.

P3 — A valid re-render after an invalid mermaid edit kept the
.mermaid-error class on the diagram element. Drop the class in
queueMermaidRender's success path now that successful render means the
source compiled.

Both fixes preserve TASK-1249's NodeView update() contract; no other
behavior changed.
2026-05-08 12:51:02 -04:00
..
2026-03-26 01:52:36 +00:00