From dc1f5bb7b135022ba53f9c8e77eef0498e575ed2 Mon Sep 17 00:00:00 2001 From: Steffen Becker Date: Sun, 16 Aug 2026 01:47:05 +0200 Subject: [PATCH] fix: leaving a header/footer no longer throws state_unsafe_mutation Clearing hfActive removes the live zone's DOM during Svelte's flush; ProseMirror dispatches a blur transaction as it goes, and the hfTick mutation in onTransaction then landed mid-render and threw, aborting the rest of the batch. The tick is queued to the next microtask instead. --- src/lib/components/HeaderFooterLayer.svelte | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/lib/components/HeaderFooterLayer.svelte b/src/lib/components/HeaderFooterLayer.svelte index 8cc7872..9ca168e 100644 --- a/src/lib/components/HeaderFooterLayer.svelte +++ b/src/lib/components/HeaderFooterLayer.svelte @@ -337,8 +337,10 @@ content: (zoneDoc(editingIndex, zone, editingVariant) ?? emptyDoc()) as Content, // No autofocus: its scrollIntoView nudges the page so the just-clicked zone // appears to jump. Focus the zone explicitly without scrolling instead. + // Deferred: leaving a zone removes this DOM mid-render, and the blur ProseMirror + // dispatches then would tick state while Svelte is still flushing. onTransaction: () => { - hfTick++; + queueMicrotask(() => hfTick++); }, onUpdate: ({ editor }) => { writeZone(editingIndex, zone, editingVariant, editor.getJSON() as HfDoc);