Skip to content

Mermaid diagram disappears after blurring from edit mode #938

Closed

Description

@malibio

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:

  1. User views a mermaid code block — diagram renders correctly
  2. User clicks the diagram — enters edit mode, mermaid syntax is shown
  3. 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:

  • mermaidSvgUri is 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 = null when 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 — $effect render 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

  1. added
    bug
    on Mar 14, 2026
  2. malibio commented on Mar 14, 2026

    @malibio
    CollaboratorAuthor

    Frontend baseline: 117 test files, 3704 tests passed

  3. self-assigned this
    on Mar 14, 2026
  4. added a commit that references this issue on Mar 14, 2026
    a63860a
  5. added 2 commits that reference this issue on Mar 14, 2026
    e826f1b
    167e4df
  6. added 2 commits that reference this issue on Jun 22, 2026
    3649035
    bfa7d1c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugui

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions