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:
Sidharth Vinod
2023-07-18 07:57:38 +00:00
committed by GitHub
2 changed files with 23 additions and 4 deletions

View File

@@ -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', () => {

View File

@@ -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);
})
) )
); );
} }