Skip to content

Lazy-load globe map stack#4012

Open
koala73 wants to merge 4 commits into
mainfrom
codex/issue-3534-lazy-globe
Open

Lazy-load globe map stack#4012
koala73 wants to merge 4 commits into
mainfrom
codex/issue-3534-lazy-globe

Conversation

@koala73
Copy link
Copy Markdown
Owner

@koala73 koala73 commented Jun 1, 2026

Summary

Fixes #3534.

Lazy-loads the GlobeMap implementation so non-globe users no longer pull the globe.gl / three stack when the map container loads. Adds a dedicated globe-stack manual chunk and keeps it out of entry HTML modulepreload dependencies alongside the other lazy map chunks.

What changed

  • Replaced the static GlobeMap import in MapContainer with a cached dynamic import used only when globe mode is active.
  • Preserved flat-map startup and fallback behavior while replaying cached callbacks/data after the globe chunk resolves.
  • Added cancellation guards so pending globe imports do not instantiate after switching back to flat mode or destroying the container.
  • Added globe-stack routing for globe.gl and three in Vite manualChunks, with matching lazy preload filtering.

Validation

  • npm run typecheck
  • npx vite build
  • git diff --check
  • Push hook checks: source/API typecheck, Convex audit, CJS syntax, Unicode safety, boundary lint, rate-limit policy lint, premium-fetch lint, edge-function bundle/test checks, version sync

Bundle evidence

Production build emitted separate lazy chunks:

  • dist/assets/MapContainer-Seew60-4.js - 400.09 kB
  • dist/assets/GlobeMap-ClY9cqUr.js - 90.84 kB
  • dist/assets/globe-stack-RvfsjqqG.js - 1,689.87 kB

dist/*.html did not contain GlobeMap-*, globe-stack-*, MapContainer-*, maplibre-*, or deck-stack-* asset references, confirming the lazy map chunks are not hoisted into entry HTML preload links.

Residual risk

Browser runtime smoke was not run. The main remaining manual check is toggling 2D to 3D and startup with persisted mapMode=globe to verify the async chunk load renders as expected.

@vercel
Copy link
Copy Markdown

vercel Bot commented Jun 1, 2026

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

Project Deployment Actions Updated (UTC)
worldmonitor Ready Ready Preview, Comment Jun 1, 2026 10:58am

Request Review

@koala73 koala73 changed the title [codex] Lazy-load globe map stack Lazy-load globe map stack Jun 1, 2026
@koala73 koala73 marked this pull request as ready for review June 1, 2026 10:10
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Jun 1, 2026

Greptile Summary

This PR lazy-loads the GlobeMap / globe.gl / three stack behind a dynamic import so non-globe users no longer pull ~1.7 MB of WebGL code at startup. A cancellation guard (globeActivationId) and a destroyed flag prevent the async chunk from instantiating after the user has already switched back to flat mode or destroyed the container.

  • MapContainer.ts: Static GlobeMap import replaced with a type-only import; a cached Promise<GlobeMapCtor> is resolved on first globe activation; callbacks and data are replayed via rehydrateActiveMap() once the chunk resolves.
  • vite.config.ts: globe-stack added as a manualChunks target for globe.gl and three, and appended to LAZY_HTML_PRELOAD_CHUNKS so it is excluded from entry-HTML modulepreload links, matching the existing pattern for deck-stack.

Confidence Score: 3/5

Globe mode becomes permanently unavailable after any chunk load failure until the page is refreshed, with no user-visible error or fallback.

The cancellation guards, activation-ID pattern, and data-rehydration flow are sound. The one weak spot is that initGlobeMap has no error handling and globeMapCtorPromise is never cleared on failure, so a single chunk-load failure leaves globe mode permanently broken for the session.

src/components/MapContainer.ts — specifically the initGlobeMap and loadGlobeMapCtor pair.

Important Files Changed

Filename Overview
src/components/MapContainer.ts Replaces static GlobeMap import with a cached dynamic import guarded by activation-ID cancellation; the async initGlobeMap path has no error handling, and a rejected globeMapCtorPromise is never cleared, making globe mode permanently broken after any chunk load failure.
vite.config.ts Adds globe-stack to LAZY_HTML_PRELOAD_CHUNKS and routes globe.gl / three imports to the new chunk — straightforward and consistent with the existing deck-stack pattern.

Reviews (1): Last reviewed commit: "fix: lazy-load globe map stack" | Re-trigger Greptile

Comment thread src/components/MapContainer.ts
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.

Lazy-import GlobeMap + add manualChunk for globe.gl/three to slash initial JS for non-globe users

1 participant