Skip to content

Commit f28142f

Browse files
committed
Fix mermaid diagram height when it's initially hidden
Fixes: go-gitea#32392
1 parent 0f397ae commit f28142f

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

web_src/js/markup/mermaid.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,19 @@ export async function renderMermaid() {
5757
btn.setAttribute('data-clipboard-text', source);
5858
mermaidBlock.append(btn);
5959

60+
const updateIframeHeight = () => {
61+
iframe.style.height = `${iframe.contentWindow.document.body.clientHeight}px`;
62+
};
63+
64+
// update height when element becomes visible, for example when the diagram is inside a details+summary block
65+
(new IntersectionObserver(() => {
66+
updateIframeHeight();
67+
}, {root: document.documentElement})).observe(iframe);
68+
6069
iframe.addEventListener('load', () => {
6170
pre.replaceWith(mermaidBlock);
6271
mermaidBlock.classList.remove('tw-hidden');
63-
iframe.style.height = `${iframe.contentWindow.document.body.clientHeight}px`;
72+
updateIframeHeight();
6473
setTimeout(() => { // avoid flash of iframe background
6574
mermaidBlock.classList.remove('is-loading');
6675
iframe.classList.remove('tw-invisible');

0 commit comments

Comments
 (0)