Skip to content

Commit 3100e64

Browse files
authored
Merge pull request #163 from sugarlabs/painter-fix-load-race-condition
painter: [sprite] Fix sprite loading race condition
2 parents 4f5f915 + 59cd1f7 commit 3100e64

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

src/components/painter/view/sprite.ts

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,26 @@ let _spriteSVG: SVGElement;
1717
* @param interactor - DOM container for the interactor (wrapper for the sprite)
1818
*/
1919
export function setup(interactor: HTMLElement): void {
20-
(async () => {
21-
const spriteWrapper = document.createElement('div');
22-
spriteWrapper.classList.add('artboard-sprite-wrapper');
23-
spriteWrapper.style.left = '50%';
24-
spriteWrapper.style.bottom = '50%';
25-
spriteWrapper.style.transform = 'translate(-50%, 50%)';
26-
spriteWrapper.innerHTML =
27-
// fetches the SVG source string from the .svg source file's URL
28-
await fetch(_spriteSrc).then((res) => res.text());
20+
const spriteWrapper = document.createElement('div');
21+
spriteWrapper.classList.add('artboard-sprite-wrapper');
22+
spriteWrapper.style.left = '50%';
23+
spriteWrapper.style.bottom = '50%';
24+
spriteWrapper.style.transform = 'translate(-50%, 50%)';
25+
interactor.appendChild(spriteWrapper);
2926

30-
const spriteElem = spriteWrapper.children[0] as SVGElement;
31-
spriteElem.classList.add('artboard-sprite');
27+
_sprite = spriteWrapper;
3228

33-
interactor.appendChild(spriteWrapper);
29+
// fetches the SVG source string from the .svg source file's URL
30+
fetch(_spriteSrc)
31+
.then((res) => res.text())
32+
.then((svg) => {
33+
spriteWrapper.innerHTML = svg;
3434

35-
_sprite = spriteWrapper;
36-
_spriteSVG = spriteElem;
37-
})();
35+
const spriteElem = spriteWrapper.children[0] as SVGElement;
36+
spriteElem.classList.add('artboard-sprite');
37+
38+
_spriteSVG = spriteElem;
39+
});
3840
}
3941

4042
/**

0 commit comments

Comments
 (0)