Repository navigation
Description
Overview
When a code block node is set to mermaid language, clicking away after editing causes the rendered diagram to disappear rather than re-render.
Problem Statement
User Experience:
- User views a mermaid code block — diagram renders correctly
- User clicks the diagram — enters edit mode, mermaid syntax is shown
- User clicks away (blur) — diagram disappears instead of re-rendering
Expected: After blur, the mermaid diagram should re-render and display correctly.
Root Cause
Location: packages/desktop-app/src/lib/design/components/code-block-node.svelte — $effect render block (~lines 113–140)
The $effect that drives mermaid rendering skips execution when isEditing is true. When blur occurs and isEditing becomes false, the effect re-runs. However, the effect can fire multiple times in rapid succession (once for the isEditing change, once for derived content changes), causing the renderSeq stale-result guard to discard the in-flight render result. Since mermaidSvgUri is not preserved across the re-render attempt, if the result is discarded the diagram disappears with no fallback and no error shown.
Proposed Solution
Fix the stale-result guard interaction so that:
mermaidSvgUriis not cleared until a new successful render is available (preserve existing diagram during re-render)- The error state is cleared at the start of a new render attempt, not on discard
- Only set
mermaidSvgUri = nullwhen the render definitively fails (not when discarded as stale)
Acceptance Criteria
- Mermaid diagram re-renders correctly after clicking away from edit mode
- Diagram remains visible (not blank) during the async re-render on blur
- Error state still displays correctly when mermaid syntax is invalid
- No regression in stale-result protection (rapid language/content changes still handled correctly)
- Tests pass (
bun run test:all) - Code passes
bun run quality:fix
Technical Specifications
Files to Modify
- CodeBlockNode:
packages/desktop-app/src/lib/design/components/code-block-node.svelte—$effectrender block (~lines 113–140)
Key Logic
The fix should ensure mermaidSvgUri is only replaced (not cleared) when a valid new render arrives, and only set to null when the render definitively returns null (failure), not when discarded by the sequence guard.
Activity
malibio commentedon Mar 14, 2026
Frontend baseline: 117 test files, 3704 tests passed
Fix mermaid diagram disappearing after blur from edit mode (closes #938)
Fix mermaid diagram disappearing after blur from edit mode (closes #938)
Mermaid diagram disappears after blurring from edit mode (#953)
Mermaid diagram disappears after blurring from edit mode (#942)
Mermaid diagram disappears after blurring from edit mode (#953)