Skip to content

fix(maps): stack overflow from map.resize() inside moveend handler - #164

Merged
slaveofcode merged 4 commits into
developfrom
fix/map-explorer-resize-stack-overflow
Aug 7, 2026
Merged

fix(maps): stack overflow from map.resize() inside moveend handler#164
slaveofcode merged 4 commits into
developfrom
fix/map-explorer-resize-stack-overflow

Conversation

@slaveofcode

Copy link
Copy Markdown
Owner

Root cause

Previous fix (PR #158) called map.resize() synchronously inside moveend. MapLibre calls constrainInternal during resize, which re-fires moveend within the same call stack → RangeError: Maximum call stack size exceeded.

Fix

Guard flag + requestAnimationFrame: resize deferred to the next frame, breaking the synchronous recursion. Flag prevents queuing more than one resize at a time.

Test plan

  • Open Map Explorer — no stack overflow in console
  • Click Locate button → map flies to location → tiles fill viewport (blank-map fix still works)
  • Click GeolocateControl → same result
  • Search a place → flyTo → full tiles, no error

slaveofcode and others added 4 commits August 4, 2026 16:45
Promote to production: fix blank map after detect-my-location
Promote to production: Cron Expression tool
Promote to production: reverse cron (natural language → expression)
The previous fix called map.resize() synchronously inside the moveend
handler. MapLibre internally calls constrainInternal during resize, which
fires another moveend within the same call stack → infinite recursion →
RangeError: Maximum call stack size exceeded.

Fix: guard flag + requestAnimationFrame so resize() runs after the current
call stack clears. The flag ensures at most one pending resize at a time,
and rAF breaks the synchronous recursion path entirely.

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

cloudflare-workers-and-pages Bot commented Aug 7, 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 37407af Aug 07 2026, 08:55 AM

@slaveofcode
slaveofcode merged commit 8bfa164 into develop Aug 7, 2026
2 checks passed
@slaveofcode
slaveofcode deleted the fix/map-explorer-resize-stack-overflow branch August 7, 2026 08:55
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