Skip to content

Fix tree-shake issue#7

Merged
giswqs merged 2 commits intomainfrom
examples
Jan 20, 2026
Merged

Fix tree-shake issue#7
giswqs merged 2 commits intomainfrom
examples

Conversation

@giswqs
Copy link
Copy Markdown
Member

@giswqs giswqs commented Jan 20, 2026

The issue was that the examples worked locally during development but failed on GitHub Pages with the error e.setBasemap is not a function. This happened because:
Root Cause: The examples were using a side-effect-only import (import '../../src/index') to extend the Map prototype. In production builds, Rollup/Vite can tree-shake these imports away because no exported values are being used.

Copilot AI review requested due to automatic review settings January 20, 2026 17:09
@giswqs giswqs merged commit 35a7af7 into main Jan 20, 2026
2 checks passed
@giswqs giswqs deleted the examples branch January 20, 2026 17:10
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a tree-shaking issue by making the extendMapPrototype function public and ensuring it's explicitly called in all examples. This prevents bundlers from removing the prototype extension code in production builds.

Changes:

  • Exported extendMapPrototype function with idempotent behavior (returns boolean to indicate if extension occurred)
  • Added explicit extendMapPrototype() calls in all 6 example files
  • Enhanced JSDoc documentation to explain the tree-shaking issue and safe multi-call behavior

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/index.ts Made extendMapPrototype public, added guard flag for idempotency, changed return type to boolean, and improved documentation
examples/zarr/main.ts Changed from side-effect import to explicit function call
examples/zarr-simple/main.ts Changed from side-effect import to explicit function call
examples/react/main.tsx Changed from side-effect import to explicit function call
examples/cog/main.ts Changed from side-effect import to explicit function call
examples/cog-simple/main.ts Changed from side-effect import to explicit function call
examples/basic/main.ts Changed from side-effect import to explicit function call

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/index.ts
Comment on lines +57 to +61
export function extendMapPrototype(): boolean {
if (prototypeExtended) {
return false;
}
prototypeExtended = true;
Copy link

Copilot AI Jan 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new exported extendMapPrototype function and its idempotency behavior (using the prototypeExtended flag) lack test coverage. Consider adding tests to verify:

  1. The function returns true on first call and false on subsequent calls
  2. The Map prototype is properly extended with all expected methods after calling the function
  3. Multiple calls don't cause duplicate assignments or errors

This is particularly important since this function is now part of the public API and addresses a critical tree-shaking issue.

Copilot uses AI. Check for mistakes.
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.

2 participants