Skip to content

fix(map-explorer): pre-fetch style+TileJSON to bypass stale Cloudflare CDN - #168

Merged
slaveofcode merged 2 commits into
developfrom
fix/map-explorer-blank-tiles-cdn
Aug 8, 2026
Merged

fix(map-explorer): pre-fetch style+TileJSON to bypass stale Cloudflare CDN#168
slaveofcode merged 2 commits into
developfrom
fix/map-explorer-blank-tiles-cdn

Conversation

@slaveofcode

Copy link
Copy Markdown
Owner

Root cause

The OpenFreeMap /styles/liberty endpoint returns different content from different Cloudflare edge nodes. The Singapore CDN edge (serving users in Jakarta/Indonesia) had a stale cached response returning a TypeScript schema representation instead of the actual MapLibre style JSON — invalid JSON that MapLibre silently fails to parse, leaving the map blank.

Reproducing the schema response:

{ glyphs: string[59], layers: [{ id: string, ...

(unquoted keys, type annotations as values — not parseable as JSON)

Meanwhile, other edge nodes return the correct minified style JSON starting with {"version":8,...}.

Fix

  1. Pre-fetch style with cache: 'no-cache' before passing it to MapLibre — forces Cloudflare to revalidate with the origin server (which serves valid JSON), bypassing the stale edge cache.

  2. Validate the response (version + sources must exist) and fall back to the URL if it looks wrong.

  3. Inline TileJSON tile URLs — the openmaptiles vector source uses url: "https://tiles.openfreemap.org/planet" (TileJSON reference). We now fetch and resolve this to tiles: [...] before giving the style to MapLibre, so MapLibre never needs its own separate TileJSON fetch.

  4. Cap zoom at 14 for both GeolocateControl (fitBoundsOptions: { maxZoom: 14 }) and myLocation() flyTo — the vector tile source's maxzoom is 14; overzooming beyond it had previously caused additional rendering edge cases in MapLibre v6.

  5. Remove the moveend → rAF → resize() pattern — the canvas size doesn't change during pan/zoom. The ResizeObserver already handles real container-size changes. This eliminates the potential for resize() to cause internal state conflicts. Replaced with a simple triggerRepaint() on moveend to nudge the render loop.

Test plan

  • Hard refresh Map Explorer → map loads with correct tiles at zoom 3
  • Click locate button / GeolocateControl → flies to zoom 14, tiles render correctly
  • Pan and zoom around → no blank tile regions
  • Switch map styles → style changes without blank tiles

🤖 Generated with Claude Code

slaveofcode and others added 2 commits August 7, 2026 17:13
Promote to production: fix blank tiles after GeolocateControl flyTo
The OpenFreeMap /styles/liberty endpoint serves different content from
different Cloudflare edge nodes — some return the actual MapLibre style
JSON, others return a TypeScript schema representation that MapLibre
cannot parse, causing blank tiles.

Instead of letting MapLibre fetch the style URL internally (where it hits
the same stale edge), we pre-fetch the style with cache:'no-cache' to
force revalidation with the origin server. We also resolve TileJSON-backed
vector sources (openmaptiles) to direct tile URL arrays inline, so MapLibre
never needs a separate TileJSON fetch at all.

Also caps GeolocateControl and myLocation() zoom at 14 (the vector tile
source's maxzoom), avoiding overzoom tile-loading edge cases in MapLibre v6.

Removes the moveend→rAF→resize() pattern (the canvas size doesn't change
during pan/zoom — the ResizeObserver handles real container size changes).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Aug 8, 2026

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
goodwebtools fc9c50b Aug 08 2026, 03:25 AM

@slaveofcode
slaveofcode merged commit 9307d8c into develop Aug 8, 2026
2 checks passed
@slaveofcode
slaveofcode deleted the fix/map-explorer-blank-tiles-cdn branch August 8, 2026 03:26
slaveofcode added a commit that referenced this pull request Aug 8, 2026
Promote to production: fix blank tiles in Map Explorer (PR #168)
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