Skip to content

Commit 66e600e

Browse files
authored
Merge branch 'release/v1.22' into backport-32435-v1.22
2 parents 1b0d193 + 62d8433 commit 66e600e

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

web_src/js/markup/mermaid.js

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

59+
const updateIframeHeight = () => {
60+
iframe.style.height = `${iframe.contentWindow.document.body.clientHeight}px`;
61+
};
62+
63+
// update height when element's visibility state changes, for example when the diagram is inside
64+
// a <details> + <summary> block and the <details> block becomes visible upon user interaction, it
65+
// would initially set a incorrect height and the correct height is set during this callback.
66+
(new IntersectionObserver(() => {
67+
updateIframeHeight();
68+
}, {root: document.documentElement})).observe(iframe);
69+
5970
iframe.addEventListener('load', () => {
6071
pre.replaceWith(mermaidBlock);
6172
mermaidBlock.classList.remove('tw-hidden');
62-
iframe.style.height = `${iframe.contentWindow.document.body.clientHeight}px`;
73+
updateIframeHeight();
6374
setTimeout(() => { // avoid flash of iframe background
6475
mermaidBlock.classList.remove('is-loading');
6576
iframe.classList.remove('tw-invisible');

0 commit comments

Comments
 (0)