A9 leaf hints: a token no longer selects Mapbox — engine = provider or MapLibre default
Correction (dx-shepherd 2026-09-29, from regions executing the shipping resolver, confirmed by rega's A9NET on the wire): useMapProvider's default is MapLibre unless provider is EXPLICITLY 'mapbox'; a baked token or a tokenUrl does NOT select Mapbox any more. rega measured all 8 auto leaves — which carry a pray.doxa.life data base — loading MapLibre from jsdelivr cold. engineFor now returns 'mapbox' only for provider:'mapbox', else 'maplibre', ignoring bakedToken/tokenUrl. And the engine preload is emitted unless the leaf already has a static engine <script> — which only a provider:'maplibre' leaf does; a provider:'mapbox' leaf emits no static tag (the Mapbox static tags were removed 2026-09-25), so it now correctly gets a preload too. No tree change: every production leaf is 'auto', and the old code also resolved those to MapLibre (tokenUrl is empty, so hasEndpoint was false), so the built hints were already jsdelivr+openfreemap. This makes the logic correct by reason rather than by the config happening to be empty. check:leaf-hints PASS 37/27.
This commit is contained in:
parent
71f36b5079
commit
778e990ca4
1 changed files with 16 additions and 13 deletions
|
|
@ -851,12 +851,13 @@ const MAPLIBRE_STYLE_ORIGIN = 'https://tiles.openfreemap.org' // useMapInstanc
|
|||
* MapLibre, keyless. The runtime can still be overridden by ?tk=/?provider=/window.MAP_PROVIDER/a stored
|
||||
* token; the hint follows the build default and the report names that miss case (one unused preconnect).
|
||||
*/
|
||||
function engineFor({ isMapLibre, config, tokenUrlExpr, bakedToken }) {
|
||||
const asked = String((config && config.provider) || '').toLowerCase().trim()
|
||||
if (isMapLibre || asked === 'maplibre') return 'maplibre'
|
||||
if (asked === 'mapbox') return 'mapbox'
|
||||
const hasEndpoint = !!(tokenUrlExpr && tokenUrlExpr !== 'window.MAP_TOKEN_URL')
|
||||
return (bakedToken || hasEndpoint) ? 'mapbox' : 'maplibre'
|
||||
function engineFor({ config }) {
|
||||
// CORRECTED 2026-09-29 (regions executed the shipping resolver; rega's A9NET confirmed on the wire):
|
||||
// a token no longer selects Mapbox. useMapProvider's default is MapLibre unless provider is EXPLICITLY
|
||||
// 'mapbox'. rega measured all 8 auto leaves — which DO carry a pray.doxa.life token endpoint — loading
|
||||
// MapLibre from jsdelivr cold. So the hint's engine is Mapbox ONLY when provider:'mapbox' is set; every
|
||||
// other case (auto, or provider:'maplibre') is MapLibre, regardless of any baked token / tokenUrl.
|
||||
return String((config && config.provider) || '').toLowerCase().trim() === 'mapbox' ? 'mapbox' : 'maplibre'
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -866,19 +867,21 @@ function engineFor({ isMapLibre, config, tokenUrlExpr, bakedToken }) {
|
|||
* and 'mapbox' branches already carry a static engine tag (mapPageHtml's peerBlock / the embed snippet),
|
||||
* so a preload there would double-fetch — those get preconnects only. Returns '' for a non-map leaf.
|
||||
*/
|
||||
function resourceHints({ isMapLibre, config, apiBaseUrl, tokenUrlExpr, bakedToken }) {
|
||||
const engine = engineFor({ isMapLibre, config, tokenUrlExpr, bakedToken })
|
||||
function resourceHints({ isMapLibre, config, apiBaseUrl }) {
|
||||
const engine = engineFor({ config })
|
||||
const styleOrigin = engine === 'maplibre' ? MAPLIBRE_STYLE_ORIGIN : ENGINE_ORIGIN.mapbox
|
||||
const dataOrigin = ORIGIN(apiBaseUrl) // '' when same-origin (no build apiBaseUrl): nothing to preconnect
|
||||
const origins = [...new Set([ENGINE_ORIGIN[engine], styleOrigin, dataOrigin].filter(Boolean))]
|
||||
const lines = origins.map((o) => ` <link rel="preconnect" href="${o}" crossorigin />`)
|
||||
// 'auto' leaf only: it emits no engine <script>, so preload the engine (URL+integrity+crossorigin from cdn.js).
|
||||
const staticEngine = isMapLibre || (config && (config.provider === 'mapbox'))
|
||||
if (!staticEngine) {
|
||||
// Preload the engine UNLESS the leaf already emits a static engine <script>. Only a provider:'maplibre'
|
||||
// leaf does (peerBlock); the 'auto' leaf and a provider:'mapbox' leaf emit no static tag (the Mapbox
|
||||
// static tags were removed 2026-09-25), so both benefit from a preload. URL+integrity+crossorigin from
|
||||
// cdn.js so it matches ensureEngineScript's tag exactly (a mismatched preload is not reused).
|
||||
if (!isMapLibre) {
|
||||
const gl = engine === 'maplibre' ? CDN.maplibreGlJs : CDN.mapboxGlJs
|
||||
lines.push(` <link rel="preload" as="script" href="${gl.url}" integrity="${gl.integrity}" crossorigin="anonymous" />`)
|
||||
}
|
||||
return lines.length ? ` <!-- A9 hints: the map's origins, so DNS/TLS + the engine start with the bundle, not after it (dx-base/a9-leaf-hints; engine derived from the token ladder). -->\n${lines.join('\n')}\n` : ''
|
||||
return lines.length ? ` <!-- A9 hints: the map's origins, so DNS/TLS + the engine start with the bundle, not after it (dx-base/a9-leaf-hints; engine = provider or the MapLibre default). -->\n${lines.join('\n')}\n` : ''
|
||||
}
|
||||
|
||||
// Does a bundle's BUILT .js reference a map engine? The directly verifiable signal for A9 leaf hints
|
||||
|
|
@ -950,7 +953,7 @@ function mapPageHtml(opts) {
|
|||
// over-hints it. The engine only mounts in-page for a real map leaf (drawsMap) or a cap-4 composite
|
||||
// (isComposite) that stacks a map child; a non-map, non-composite leaf never opens the engine itself.
|
||||
const drawsMapInPage = (drawsMap || (isComposite && bundleLoadsEngine)) && !shellTokenFree
|
||||
const hintBlock = drawsMapInPage ? resourceHints({ isMapLibre, config, apiBaseUrl, tokenUrlExpr, bakedToken }) : ''
|
||||
const hintBlock = drawsMapInPage ? resourceHints({ isMapLibre, config, apiBaseUrl }) : ''
|
||||
const peerBlock = shellOnly
|
||||
? `<!-- NON-MAP leaf (app-shell / composite / grid / card / chart-table): NO map peer.
|
||||
This element draws no map tiles, so it needs no Mapbox/MapLibre engine and MUST NOT
|
||||
|
|
|
|||
Loading…
Reference in a new issue