Skip to content

Fix basemap-aeroway layers racing style swaps - #168

Merged
amorfinv merged 2 commits into
mainfrom
fix/navdata-basemap-style-swap-race
Aug 8, 2026
Merged

Fix basemap-aeroway layers racing style swaps#168
amorfinv merged 2 commits into
mainfrom
fix/navdata-basemap-style-swap-race

Conversation

@amorfinv

@amorfinv amorfinv commented Aug 8, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Adds a synchronous onBeforeStyleChange hook to MapDisplay/MapStyleManager, fired right before every map.setStyle() call (user selection, first-load probe, and offline-fallback triggers), so listeners can tear down layers attached to the outgoing style's sources in time.
  • Wires NavdataRenderer.prepareForStyleChange() to that hook: it removes the basemap-attached aeroway layers upfront and pauses re-attachment (tryAddBasemapAeroway) until the incoming style loads, closing a race where a slow/flaky connection's vector-tile metadata could re-trigger the attach mid-swap and surface MapLibre's "Source ... cannot be removed while layer ... is using it" error (observed on the demo deployment).
  • Includes a failure-path reset (map error listener) so a style URL that never loads can't leave the pause latched forever.

🤖 Generated with Claude Code

amorfinv and others added 2 commits August 8, 2026 17:21
MapLibre's style diff can race a renderer trying to tear down layers
it attached to the outgoing style's sources. Give MapStyleManager a
synchronous hook fired right before every map.setStyle() call, from
every trigger (user selection, first-load probe, network-error
fallback), so listeners can clean up in time. App.ts wires it to
NavdataRenderer in the next commit.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
On a slow or flaky connection, the basemap's vector-tile metadata can
arrive mid-swap and re-trigger tryAddBasemapAeroway right as an
offline-fallback style change is in flight, surfacing as MapLibre's
"Source ... cannot be removed while layer ... is using it" error
(observed on the demo deployment).

prepareForStyleChange (wired to the new onBeforeStyleChange hook) now
tears down the basemap-attached layers upfront and pauses
tryAddBasemapAeroway until the incoming style loads, with a map
'error' listener as a failure-path reset so a style that never loads
can't latch the pause forever.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@amorfinv
amorfinv merged commit 61cc1c8 into main Aug 8, 2026
2 checks passed
@amorfinv
amorfinv deleted the fix/navdata-basemap-style-swap-race branch August 8, 2026 15:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant