Skip to content

fix: set projection after MapLibre styles load#1008

Open
colehart wants to merge 3 commits into
mainfrom
fix/wait-until-style-load-to-set-projection
Open

fix: set projection after MapLibre styles load#1008
colehart wants to merge 3 commits into
mainfrom
fix/wait-until-style-load-to-set-projection

Conversation

@colehart
Copy link
Copy Markdown
Contributor

@colehart colehart commented May 20, 2026

Closes https://gitlab.accelint.dev/core-ux/standard-toolkit/-/issues/114

Maureen noticed an issue that arose after the PR to expose mapLibreOptions where, when setting the defaultView to 3D on the BaseMap, MapLibre would error with the following:

image

This PR waits to set projection until after the style has been loaded to avoid the error.

✅ Pull Request Checklist

  • Included link to corresponding GitHub Issue.
  • The commit message follows conventional commit extended guidelines.
  • Added/updated unit tests and storybook for this change (for bug fixes / features).
  • Added/updated visual regression tests for this change (for bug fixes / features).
  • Added/updated documentation (for bug fixes / features)
  • Filled out test instructions.
  • Added changeset (for bug fixes / features).

📝 Test Instructions

  • to see the initial error, on main go to the next app BaseMap and set the defaultView to 3D:
Screenshot 2026-05-20 at 11 25 49 AM
  • notice the error on the Map page:
Screenshot 2026-05-20 at 11 23 58 AM
  • switch to this branch and rebuild to get the changes in map-toolkit
  • run the next app and notice you are in globe view without the error:
Screenshot 2026-05-20 at 11 25 27 AM

❓ Does this PR introduce a breaking change?

  • Yes
  • No

🤖 AI Usage

  • Added corresponding label (ai / human) to PR:

If ai was used, select all that apply:

  • Ideation / brainstorming
  • Documentation
  • Testing
  • Implementation

💬 Other information

@colehart colehart added the ai AI was used in some way in this PR label May 20, 2026
@vercel
Copy link
Copy Markdown

vercel Bot commented May 20, 2026

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

Project Deployment Actions Updated (UTC)
design-toolkit Ready Ready Preview, Comment May 20, 2026 9:23pm
map-toolkit Ready Ready Preview, Comment May 20, 2026 9:23pm

Request Review

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 20, 2026

📊 Coverage Reports

Coverage Changes by Package

Click to expand 29 package details

apps/next (No diff)

packages/bus (No diff)

packages/constants (No diff)

packages/converters (No diff)

packages/core (No diff)

packages/dataset (No diff)

packages/design-foundation (No diff)

packages/design-toolkit (No diff)

packages/formatters (No diff)

packages/geo (No diff)

packages/hotkey-manager (No diff)

packages/icons (No diff)

packages/logger (No diff)

packages/map-toolkit

metric current base change
lines 68.57% 68.78% -0.21
statements 68.52% 68.72% -0.20
functions 70.63% 70.91% -0.28
branches 61.88% 62.07% -0.19

packages/math (No diff)

packages/ntds (No diff)

packages/postcss-tailwind-css-modules (No diff)

packages/predicates (No diff)

packages/temporal (No diff)

packages/web-worker (No diff)

packages/websocket (No diff)

tooling/biome-config (No diff)

tooling/constellation-tracker (No diff)

tooling/eslint-config (No diff)

tooling/prettier-config (No diff)

tooling/smeegl (No diff)

tooling/turbo-filter (No diff)

tooling/typescript-config (No diff)

tooling/vitest-config (No diff)

Coverage data collected from all packages in the monorepo.

<MapControls id={id} mapRef={mapRef} rbzRef={rbzRef} />
)}
<MapProvider id={id}>
<MapLibre
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor Author

@colehart colehart May 20, 2026

Choose a reason for hiding this comment

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

That's the original (buggy) code - projection was being set above in the mapOptions to match the cameraState.projection value.

// Spread order: default → consumer overrides → locked keys (last wins).
//
// Don't add MapLibre options here whose setter requires `isStyleLoaded()`
// (e.g. setProjection, setLight, setTerrain, setSky). react-map-gl applies
Copy link
Copy Markdown
Contributor

@brandonjpierce brandonjpierce May 20, 2026

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

updated to be more specific to projection issue.


// `setProjection` throws if called before the style is loaded. Initial
// application happens in `handleMapLoad`; this effect syncs later changes.
useEffect(() => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I am still slightly curious as to why this isn't an issue in the baseline react-map-gl package 🤔 still leading me to believe we are chasing a potential red herring or something.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai AI was used in some way in this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants