Proposed fix

Guarded marker icon callback

This demo keeps the same event timing as the failing race demo, but adds the proposed module-side guard before the async preload callback calls setIcon().

Current simulated marker icon

Waiting to run

Event Log

    Proposed Fixed Callback

    const marker = new Marker();
    const iconBeforePreload = marker.getIcon();
    
    // Geofield Map starts this before geofieldMapInit.
    const img = new Image();
    img.onload = () => {
      if (marker.getIcon() === iconBeforePreload) {
        marker.setIcon('/default-open-pin.png');
      }
    };
    img.src = '/default-open-pin.png';
    
    // Site code can still react to geofieldMapInit.
    document.addEventListener('geofieldMapInit', () => {
      marker.setIcon('/closed-pin.png');
    });