Fix basemap-aeroway layers racing style swaps - #168
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
onBeforeStyleChangehook toMapDisplay/MapStyleManager, fired right before everymap.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.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).errorlistener) so a style URL that never loads can't leave the pause latched forever.🤖 Generated with Claude Code