Skip to content

fix(map): resolve loading stuck caused by module-level promise ref#16

Merged
ronload merged 1 commit into
mainfrom
fix/map-loading-race-condition
Apr 15, 2026
Merged

fix(map): resolve loading stuck caused by module-level promise ref#16
ronload merged 1 commit into
mainfrom
fix/map-loading-race-condition

Conversation

@ronload

@ronload ronload commented Apr 15, 2026

Copy link
Copy Markdown
Owner

Summary

Map module frequently got stuck in loading state (showing placeholder indefinitely), but worked fine when opening a new tab.

Root cause: The module-level mapModulePromise variable held a single promise reference consumed by useEffect's .then(). This had two failure modes:

  1. On chunk-load failure, the rejected (but truthy) promise bypassed the ?? fallback -- no retry, TaiwanMap stayed null forever.
  2. Under React 19 Strict Mode, the cancelled flag lifecycle could race with the shared promise resolution timing.

Fix: Replace the stored promise reference with a fire-and-forget preload. The bundler caches the module internally, so a fresh import() call in useEffect resolves instantly from cache. Also adds a one-shot retry on transient chunk-load failures.

Test plan

  • Desktop: verify map renders on first visit (hard refresh)
  • Desktop: verify map still renders after theme toggle
  • Throttle network (slow 3G) and confirm map eventually loads with retry
  • Mobile viewport: confirm no map chunk is downloaded

The module-level mapModulePromise held a single promise reference that
the useEffect .then() consumed. Two issues caused the map to stay in
loading state intermittently:

1. On chunk-load failure the rejected (but truthy) promise prevented the
   nullish-coalescing fallback from firing, so TaiwanMap stayed null
   with no retry path.
2. Under React 19 Strict Mode the cancelled-flag lifecycle could race
   with the shared promise resolution timing.

Replace the stored promise with a fire-and-forget preload -- the bundler
caches the module anyway, so a second import() in useEffect resolves
instantly. Also add a one-shot retry on transient chunk-load failures.
@vercel

vercel Bot commented Apr 15, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
zipkit Ready Ready Preview, Comment Apr 15, 2026 8:36am

@ronload ronload merged commit baba750 into main Apr 15, 2026
3 checks passed
@ronload ronload deleted the fix/map-loading-race-condition branch April 15, 2026 08:37
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