From c7eac98de4063046aad7f9decbda0b2849793b41 Mon Sep 17 00:00:00 2001 From: Andri <5224431+ndri@users.noreply.github.com> Date: Tue, 31 Mar 2026 15:23:13 +0200 Subject: [PATCH] Fix race condition in asset loader when script tag hasn't loaded When multiple components mount simultaneously, the script tag may already exist in the DOM but mapboxgl hasn't finished loading yet. The loader would call cb() immediately, causing TypeError when trying to set accessToken on undefined. Now checks if window.mapboxgl is available. If not, waits for the existing script's load event before calling the callback. --- src/lib/asset-loader.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/lib/asset-loader.js b/src/lib/asset-loader.js index 47bb1b0..a9295ad 100644 --- a/src/lib/asset-loader.js +++ b/src/lib/asset-loader.js @@ -4,7 +4,11 @@ function load (assets, cb) { if (existing) { if (type === 'script') { - cb() + if (window.mapboxgl) { + cb() + } else { + existing.addEventListener('load', () => cb(), { once: true }) + } } return }