Skip to content

Commit 5da4852

Browse files
linushamerryman
andcommitted
🎛️: prevent multiple instances of lite-youtube-embed from executing
Co-authored-by: Robin Schreiber <[email protected]>
1 parent fbd8cf2 commit 5da4852

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

lively.components/youtube-morph.cp.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { component, ViewModel, HTMLMorph } from 'lively.morphic';
22
import { pt } from 'lively.graphics/geometry-2d.js';
3+
import { fun } from 'lively.lang';
34

45
class YouTubeEmbedViewModel extends ViewModel {
56
static get properties () {
@@ -10,8 +11,12 @@ class YouTubeEmbedViewModel extends ViewModel {
1011
}
1112

1213
async viewDidLoad () {
13-
// Browsers do not like us importing this in more than once place...
14-
window.liteYouTubeEmbed ? null : (window.liteYouTubeEmbed = await System.import('lite-youtube-embed'));
14+
// Browsers do not like us importing this in more than once...
15+
if (!window.liteYouTubeEmbed) {
16+
await fun.guardNamed('import-lite-youtube-embed', async () => {
17+
window.liteYoutubeEmbed = await System.import('lite-youtube-embed');
18+
})();
19+
}
1520
this.view.html = `<lite-youtube videoid="${this.videoID}" width="100%" height="100%" style="max-width: ${this.maxWidth};"></lite-youtube>`;
1621
}
1722
}

0 commit comments

Comments
 (0)