Defect #44767
openMermaid diagrams in a hidden code block are rendered squashed
Description
If a Mermaid code block (#44425) is hidden with display: none when Mermaid.js finishes loading, the diagram is squashed and nothing is visible once the block is shown.
Example (CommonMark Markdown): open an issue with the following description, wait until Mermaid.js has loaded, and click "Show".
Notes in the issue history have the same problem when the issue is opened with the “Property changes” tab.
Files
Updated by Mizuki ISHIKAWA about 22 hours ago
The attached patch fixes this by using a ResizeObserver to render a hidden block when it is shown.
Updated by Mizuki ISHIKAWA about 22 hours ago
The ResizeObserver adds no measurable overhead. Measured with headless Chrome (median of 5 runs):
| Visible diagrams | Before | After |
| --- | --- | --- |
| 10 | 0.5 s | 0.5 s |
| 100 | 3.0 s | 3.0 s |
| 200 | 6.1 s | 6.2 s |
Most of the time is spent rendering with Mermaid.js. Starting to observe 10,000 hidden blocks takes about 6 ms. Diagrams in a collapse macro are now rendered when it is expanded instead of at page load. The first one appears within 100 ms.