mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-03 07:36:41 +02:00
Merge pull request #4496 from moka-care/bug/4439_graph_doesnt_load_when_img_fail_to_load
Fix graph not loading when the img loads too fast or fail to load
This commit is contained in:
@@ -695,6 +695,15 @@ A ~~~ B
|
|||||||
{}
|
{}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('4439: Should render the graph even if some images are missing', () => {
|
||||||
|
imgSnapshotTest(
|
||||||
|
`flowchart TD
|
||||||
|
B[<img>]
|
||||||
|
B-->C[<img>]`,
|
||||||
|
{}
|
||||||
|
);
|
||||||
|
});
|
||||||
describe('Markdown strings flowchart (#4220)', () => {
|
describe('Markdown strings flowchart (#4220)', () => {
|
||||||
describe('html labels', () => {
|
describe('html labels', () => {
|
||||||
it('With styling and classes', () => {
|
it('With styling and classes', () => {
|
||||||
|
@@ -66,8 +66,11 @@ export const labelHelper = async (parent, node, _classes, isNode) => {
|
|||||||
await Promise.all(
|
await Promise.all(
|
||||||
[...images].map(
|
[...images].map(
|
||||||
(img) =>
|
(img) =>
|
||||||
new Promise((res) =>
|
new Promise((res) => {
|
||||||
img.addEventListener('load', function () {
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function setupImage() {
|
||||||
img.style.display = 'flex';
|
img.style.display = 'flex';
|
||||||
img.style.flexDirection = 'column';
|
img.style.flexDirection = 'column';
|
||||||
|
|
||||||
@@ -82,8 +85,15 @@ export const labelHelper = async (parent, node, _classes, isNode) => {
|
|||||||
img.style.width = '100%';
|
img.style.width = '100%';
|
||||||
}
|
}
|
||||||
res(img);
|
res(img);
|
||||||
})
|
}
|
||||||
)
|
setTimeout(() => {
|
||||||
|
if (img.complete) {
|
||||||
|
setupImage();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
img.addEventListener('error', setupImage);
|
||||||
|
img.addEventListener('load', setupImage);
|
||||||
|
})
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user