Context
I’m embedding a Leaflet map inside an iOS app using WKWebView (BeeWare/Toga, but this seems WebView-level rather than framework-specific).
Problem
Leaflet’s default marker icon and shadow intermittently disappear and are rendered as ? placeholders.
This happens:
-
After the app has been backgrounded and resumed (warm start).
-
Occasionally even on first/cold start.
-
With no console errors.
-
With no network requests involved (icons are inlined, but the issue remains).
The map itself works. Tiles load correctly. Only the marker icon and shadow sometimes disappear.
Setup details
-
Leaflet (standard build).
-
The map runs in a local HTML file loaded into a
WKWebView. -
Icons are inlined as base64 PNG data-URIs, not fetched from disk or network.
-
No relative paths are used for marker assets.
Example (simplified):
// Executed before map creation
L.Icon.Default.mergeOptions({
iconUrl: 'data:image/png;base64,...',
iconRetinaUrl: 'data:image/png;base64,...',
shadowUrl: 'data:image/png;base64,...',
});
// Later
L.marker([lat, lng]).addTo(map);
Despite this, the marker sometimes renders as a ? glyph instead of the image.
Observations
-
When it fails, both icon and shadow disappear.
-
There is no
tileerror, image error, or JavaScript exception. -
A new cold start seems to fix the issue.
-
This feels like a WebKit /
WKWebViewlifecycle or memory issue, not a Leaflet path issue.
What I think I have ruled out
Even with fully inlined assets and correct ordering, the issue persists sporadically.
Question
Has anyone encountered Leaflet marker icons disappearing in WKWebView, especially on iOS, even when using data-URI icons?
Specifically:
-
Is this a known
WKWebViewimage lifecycle or memory purge issue? -
Is there a canonical way to make Leaflet marker icons robust across background/foreground transitions?
-
Is explicitly hosting marker PNGs over HTTPS actually more reliable than inlined assets in this environment?
-
Are there WebKit bugs or recommended patterns for keeping image-backed DOM elements alive across app suspension?
I would greatly appreciate insight into why this happens and what the most stable, review-safe solution is on iOS.