Skip to content

fix(preview): render JSXGraph diagrams against the live DOM (#68) - #88

Merged
adibhanna merged 1 commit into
mainfrom
fix/jsxgraph-preview-container
Jun 10, 2026
Merged

fix(preview): render JSXGraph diagrams against the live DOM (#68)#88
adibhanna merged 1 commit into
mainfrom
fix/jsxgraph-preview-container

Conversation

@adibhanna

Copy link
Copy Markdown
Contributor

Fixes #68 — JSXGraph diagrams failed to render in the preview with "JSXGraph: HTML container element 'zen-jxg-…' not found."

Cause

The preview renders a note into a detached <article> buffer, runs every diagram renderer on it, then swaps it into the live DOM. JSXGraph's initBoard(id) resolves its container via document.getElementById (the live document) and sizes the board from the laid-out element — so against a detached buffer it can't find the container and would get a zero-size board. Mermaid (inline SVG) and function-plot (handed the element directly) were unaffected, which is why only JSXGraph broke.

Fix

Attach the rendered content to the live document before running the diagram renderers (Preview.tsx). Mermaid still renders in the buffer (inline SVG). Side benefit: note text now paints immediately instead of waiting for every diagram library to load. The PDF export window reuses <Preview>, so it's fixed there too.

Verification

  • Traced to the detached-buffer swap in Preview.tsx.
  • Reproduced via the demo tour note 05b — Math Diagrams (3 JSXGraph blocks); confirmed they now render and are draggable, no console errors.
  • npm run typecheck passes.

JSXGraph's initBoard() resolves its container via document.getElementById
and sizes the board from the laid-out element. The preview rendered all
diagrams into a detached <article> buffer before swapping it into the DOM,
so every JSXGraph block failed with "HTML container element 'zen-jxg-…'
not found" and zero-size boards. Mermaid (inline SVG) and function-plot
(handed the element directly) were unaffected.

Attach the rendered content to the live document before running the
diagram renderers; Mermaid still renders in the buffer. As a side effect,
note text now paints immediately instead of waiting for every diagram
library to load. The PDF export window reuses <Preview>, so it is fixed too.

Fixes #68
@adibhanna
adibhanna merged commit f53cb2c into main Jun 10, 2026
5 checks passed
@adibhanna
adibhanna deleted the fix/jsxgraph-preview-container branch June 10, 2026 13:58
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.

demo tour - jsxgraph is not rendered

1 participant