Skip to content

Document that map:ready fires before the base map style loads - #610

Merged
dannyleech merged 2 commits into
mainfrom
72-document-map-ready-timing
Oct 20, 2026
Merged

dannyleech merged 2 commits into
mainfrom
72-document-map-ready-timing

Conversation

@dannyleech

Copy link
Copy Markdown
Contributor

Resolves #72

The race in #72 no longer crashes. MapLibre v6 (#562) made getSource safe to call before the style exists. The single draw plugin (#422) also polls for its sources instead of reading them on map:ready.

We're keeping map:ready where it is, straight after the map is created, rather than moving it into the load callback. Padding sync, re-measuring the layout once plugins render, plugin UI and markers all wait on isMapReady, and none of them need the style. Moving it would hold the interface back until the style had loaded, and if the style failed to load, that UI would never appear.

This PR documents the timing instead:

  • map:ready / MAP_READY: fires once the map instance exists. The base map style may still be loading.
  • New map:loaded entry: fires once the initial style has loaded. Already emitted by all providers but not documented until now.
  • mapState.isMapReady: plugins should check mapProvider.isBaseMapReady() before adding sources or layers.

@dannyleech
dannyleech requested review from markfee and a balanced review from Copilot October 20, 2026 10:27

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Provider-specific timing, viewport readiness, and payload behavior need accurate documentation.

3 open issues
What changed in this PR

Clarifies map readiness timing for #72 without changing runtime behavior.

Changes:

  • Distinguishes map creation from base-style readiness.
  • Documents the existing map:loaded event.
  • Adds style-readiness guidance for plugins.
File Description
src/​config/​events.js Updates readiness event comments.
docs/​api/​context.md Explains isMapReady and the provider readiness check.
docs/​api.md Expands readiness documentation and adds map:loaded.

Review effort: Balanced

Comment thread docs/api.md Outdated
Comment thread docs/api.md Outdated
Comment thread docs/api.md Outdated
@sonarqubecloud

Copy link
Copy Markdown

@dannyleech

Copy link
Copy Markdown
Contributor Author

I've addressed all three in the latest commit. map:ready now only says the map uses the safe zone as its initial padding, since OpenLayers fits bounds after map:ready fires. "Base map style" is now "base map", which fits OpenLayers and ESRI. The map:loaded payload now notes that ESRI passes the current map state. Making ESRI's payload match the other providers would change runtime behaviour, so that should be a separate ticket.

@dannyleech
dannyleech merged commit abacc73 into main Oct 20, 2026
2 checks passed
@dannyleech
dannyleech deleted the 72-document-map-ready-timing branch October 20, 2026 10:38
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.

MAP_READY event emitted before map load event

2 participants