Skip to content

fix: Mermaid tab UI never rendered (wrong sibling lookup) - #20

Merged
jwsung91 merged 1 commit into
mainfrom
fix/mermaid-tabs-not-rendering
Jul 3, 2026
Merged

fix: Mermaid tab UI never rendered (wrong sibling lookup)#20
jwsung91 merged 1 commit into
mainfrom
fix/mermaid-tabs-not-rendering

Conversation

@jwsung91

@jwsung91 jwsung91 commented Jul 3, 2026

Copy link
Copy Markdown
Owner

Summary

  • Fixes the pre-existing bug flagged during P3: About CMS 등록, STL 시리즈 정리, Mermaid 테마 재렌더 #18's review: the Mermaid/Code tab toggle for diagrams never actually rendered because enhanceMermaidTabs looked for the code block via diagram.previousElementSibling, which is always null given the actual markup structure (.mermaid div is the only child of <figure class="mermaid-figure">; the code lives in a separate <details class="mermaid-source"> that follows the figure).
  • Now correctly locates the diagram/code pair via the figure and its next-sibling details block, and removes the now-empty shells after moving their contents into the tab panels.

Test plan

  • npm run check passes
  • Verified with Playwright against a production preview build (astro build + astro preview):
    • All 4 diagrams on a test post get Mermaid/Code tab pairs (8 buttons total)
    • Clicking "Code" shows the correct Mermaid source text; clicking back shows the rendered SVG
    • No leftover empty <figure>/<details> shells
    • Tab state survives a theme toggle (the dark/light re-render from the earlier Mermaid fix keeps working underneath)
    • Zero console errors

Closes #19

🤖 Generated with Claude Code

enhanceMermaidTabs looked for the code block via
diagram.previousElementSibling, expecting a pre[data-language="mermaid"]
right before the .mermaid div. But the actual markup (from the
remarkMermaid plugin in astro.config.mjs) wraps the diagram in its own
<figure class="mermaid-figure">, with the source code living in a
separate <details class="mermaid-source"> that follows the figure —
so previousElementSibling was always null and the tabs never built.
This was already broken on main before any of the recent work; unrelated
to it.

Look up the diagram/code pair from the figure and its next sibling
details block instead, and remove the now-empty figure/details shells
once their contents are moved into the tab panels.

Verified with Playwright against a production preview build: all 4
diagrams on a test post get Mermaid/Code tab pairs, switching tabs
shows the correct content, tab state survives a theme toggle
(re-render from the earlier Mermaid dark/light fix keeps working
underneath), and no leftover empty figure/details elements remain.
@jwsung91
jwsung91 merged commit cbba9c4 into main Jul 3, 2026
2 checks passed
@jwsung91
jwsung91 deleted the fix/mermaid-tabs-not-rendering branch July 3, 2026 23:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: Mermaid Mermaid/Code 탭이 전혀 렌더링되지 않음

1 participant