diff --git a/internal/generate-tree.mjs b/internal/generate-tree.mjs index 543d1153c..3ed471f7f 100644 --- a/internal/generate-tree.mjs +++ b/internal/generate-tree.mjs @@ -161,6 +161,19 @@ const DEFINE_RE = /customElements\.define\(\s*['"]([^'"]+)['"]/g // registered // manifest lists exactly what the dev manifest lists (a blank template-map-a/b in the built studio was // the only difference, found 2026-09-25). Not gatedProfiles: that list is governance (private data). const SCAFFOLD_BUNDLES = ['template-bundle'] +// ★ THE MAPBOX ENGINE URL, read from the ONE place that loads it (useMapInstance.js ENGINES.mapbox.js), +// so the embed snippet's preload can never point at a different version than the one the bundle +// requests — a mismatched preload is not used, and the engine would download twice. +const MAPBOX_GL_JS = (() => { + try { + const src = readFileSync(resolve(__dirname, '..', 'library', 'composables', 'useMapInstance.js'), 'utf8') + const m = src.match(/mapbox:\s*\{[^}]*?js:\s*'([^']+mapbox-gl\.js)'/) + if (m) return m[1] + } catch { /* fall through */ } + console.warn('[generate-tree] could not read the Mapbox engine URL from useMapInstance.js; embed snippets get no preload') + return '' +})() + const isBundleDir = (name) => !name.startsWith('_') && !name.startsWith('.') && !DEST_CONFIG.gatedProfiles.includes(name) && !SCAFFOLD_BUNDLES.includes(name) // ★ CUSTOM-ELEMENT NAME RULE (HTML spec): lowercase, must contain a hyphen, no spaces. @@ -1204,7 +1217,20 @@ function scanBundles() { isMap, iframeUrl, scriptUrl, - embed: { iframe: iframeEmbed, script: scriptEmbed }, + // ★ ENGINE PRELOAD, map snippets only (measured 2026-09-25, cold, 10 Mbps). A partner page that + // pastes this snippet has no leaf page to fetch mapbox-gl.js, so the bundle requested it only + // after it had downloaded, run and mounted: doxa-simple-map's engine started at 1.06 s, right + // after its bundle (0.99 s); regions-mfe's at 2.67 s. A preload lets the ~480 KB engine download + // alongside the bundle. NO crossorigin attribute, on purpose: ensureEngineScript injects a plain + //