From 5da48522c481de61a482cc3e2f21683d9fdcd7e7 Mon Sep 17 00:00:00 2001 From: Linus Hagemann Date: Mon, 22 Jul 2024 18:24:39 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=9B=EF=B8=8F:=20prevent=20multiple=20i?= =?UTF-8?q?nstances=20of=20`lite-youtube-embed`=20from=20executing?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Robin Schreiber --- lively.components/youtube-morph.cp.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lively.components/youtube-morph.cp.js b/lively.components/youtube-morph.cp.js index fb7a1cbc55..6c99dbe9b9 100644 --- a/lively.components/youtube-morph.cp.js +++ b/lively.components/youtube-morph.cp.js @@ -1,5 +1,6 @@ import { component, ViewModel, HTMLMorph } from 'lively.morphic'; import { pt } from 'lively.graphics/geometry-2d.js'; +import { fun } from 'lively.lang'; class YouTubeEmbedViewModel extends ViewModel { static get properties () { @@ -10,8 +11,12 @@ class YouTubeEmbedViewModel extends ViewModel { } async viewDidLoad () { - // Browsers do not like us importing this in more than once place... - window.liteYouTubeEmbed ? null : (window.liteYouTubeEmbed = await System.import('lite-youtube-embed')); + // Browsers do not like us importing this in more than once... + if (!window.liteYouTubeEmbed) { + await fun.guardNamed('import-lite-youtube-embed', async () => { + window.liteYoutubeEmbed = await System.import('lite-youtube-embed'); + })(); + } this.view.html = ``; } }