Skip to content

Fix Mermaid and line numbers on full load, number the editor lines - #42

Merged
ericof merged 1 commit into
mainfrom
issues-40-41
Nov 2, 2026
Merged

ericof merged 1 commit into
mainfrom
issues-40-41

Conversation

@ericof

@ericof ericof commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

Fixes two bugs seen on a full page load in 4.0.0, and adds line numbers to the Code block's edit view.

Mermaid (#40)

startOnLoad: true made Mermaid treat the block wrapper, which has the mermaid class, as a diagram. The block already calls mermaid.render, so it is now false.

Line numbers (#41)

The numbers were not always missing, as the issue says: on plone.org.br they usually rendered, but went missing on some loads. prismjs and prism-core were two instances, and each scheduled its own highlightAll at load, through requestAnimationFrame:

  • Before hydration, it changed the markup, which caused the React hydration errors (46 on that page).
  • After the blocks were highlighted, the prism-core run, which has no plugins, removed the numbers. A tab loading in the background makes this order likely, since it delays requestAnimationFrame, though that specific case is an inference.

helpers/prism.ts is now the only instance, in manual mode. Importing prismjs directly would bring the second instance back. Prism no longer highlights the page on its own at load, which a project could only have relied on by accident.

Edit view

Prism's plugin needs a <code> element and the complete hook, and the editor has neither. Instead, a marker on each line is numbered by the same CSS counter, so multi-line tokens and wrapped lines need no measuring. The Mermaid block has no line number settings, so it is unchanged.

Tests

The acceptance tests force the failing order: a pending image holds back load, and a delayed requestAnimationFrame puts Prism's run after hydration. They failed on main's source and pass here. Locally, the code block test fails on the hydration errors only; the removed numbers are covered by a unit test.

Closes #40
Closes #41

Mermaid block: with startOnLoad, Mermaid also treated the block wrapper,
which has the mermaid class, as a diagram on a full load. It replaced the
wrapper with a syntax error, and the caption went with it. The block
already calls mermaid.render itself, so startOnLoad is now false.

Code block: prismjs and prism-core were two instances, and each scheduled
its own highlightAll when the page loaded. Before hydration, that run
changed the markup and caused React hydration errors. After the blocks
were highlighted, the prism-core run, which has no plugins, replaced the
content of the code element and removed the line numbers, so they went
missing intermittently. helpers/prism.ts is now the only instance, and
helpers/prismManual.ts sets Prism to manual mode before it loads.

Edit view: the line numbers are now shown there too. A marker added to
each line of the highlighted code is numbered with the same CSS counter
as the view, so multi-line tokens and wrapped lines need no measuring.
The markers follow the Show Line Numbers and Starting Line Number
settings. Tokens are static in the editor, because the dark theme
positions them, which took markers inside a token out of the gutter.

Closes #40
Closes #41
@ericof
ericof merged commit c8d5841 into main Nov 2, 2026
9 checks passed
@ericof
ericof deleted the issues-40-41 branch November 2, 2026 02:21
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.

Code block does not show line numbers Mermaid block shows a syntax error on a full page load

1 participant