Skip to content

fix: prevent app wide crash when terrain properties are undefined - #2582

Open
mbret wants to merge 9 commits into
visgl:masterfrom
mbret:fix/unpredictable-terrain-crash
Open

fix: prevent app wide crash when terrain properties are undefined#2582
mbret wants to merge 9 commits into
visgl:masterfrom
mbret:fix/unpredictable-terrain-crash

Conversation

@mbret

@mbret mbret commented Feb 17, 2026

Copy link
Copy Markdown

[Mapbox GL related]

We have frequent "random" crash on our app when unmounting components.

image

After tracking it for a while I came to the conclusion that it might be a bug in mapbox library itself. It seems that map.removeSource(id) can sometimes crash the app due to this property being undefined https://github.com/mapbox/mapbox-gl-js/blob/7a72385de5c7400647ea7d3539637145fdf616a7/src/terrain/terrain.ts#L380.

It also seems to be much much more frequent when in StrictMode.

image

Why it's undefined is honestly a mystery but I figured we may as well try/catch for good faith.

I am gonna create an issue on the official repo as well as I understand this is more of a bandaid than an actual fix.


Note

Medium Risk
Core map camera and constraint logic spans three MapLibre major versions; regression risk is mitigated by the new CI matrix but changes are in critical map lifecycle paths.

Overview
Adds MapLibre GL JS v6 compatibility across the MapLibre wrapper, examples, docs, and CI, alongside a Mapbox fix for crashes when removing sources while terrain properties are still unevaluated.

The MapLibre layer now works across v4/v5/v6: camera state is read via public getters instead of map.transform, v6 uses setTransformCameraUpdate, and min/max zoom/pitch updates avoid invalid transient ranges. GlobeControl is exported and fails clearly when the host MapLibre build lacks it.

CI runs tests against maplibre-gl ^4, ^5, and ^6 (Node 24.18). MapLibre examples and the site configure the v6 worker (setWorkerUrl / Vite ?worker&url). Docs cover namespace imports and worker setup for v6.

For Mapbox, Source removal goes through removeSource, which swallows a known terrain-related TypeError during unevaluated terrain state (with tests).

Reviewed by Cursor Bugbot for commit 67e8f72. Bugbot is set up for automated code reviews on this repo. Configure here.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: dee6ef5425

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +120 to +122
} catch (error) {
// eslint-disable-next-line
console.error(error);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Re-throw unexpected removeSource failures

This catch block swallows all map.removeSource exceptions and only logs them, which leaves the source mounted when cleanup fails; that can silently corrupt later renders because map.getSource(id) will return stale data on remount (especially with explicit ids), and in StrictMode/unmount-heavy flows it can accumulate orphaned auto-generated sources instead of actually cleaning up. Limiting the catch to the known terrain bug condition (and rethrowing otherwise) would avoid masking real cleanup failures.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

@codex, source is correctlyl removed, only the following updating terrain path is failing. Which in this situation is unrecoverable anyway.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@Pessimistress

Copy link
Copy Markdown
Collaborator

Can you run yarn lint fix?

@mbret

mbret commented Apr 11, 2026

Copy link
Copy Markdown
Author

Can you run yarn lint fix?

@cursor run yarn lint fix.

@taschik

taschik commented May 6, 2026

Copy link
Copy Markdown

@mbret any chance you could run the linter and also push the clean files, so this can be merged?

@mbret

mbret commented May 6, 2026

Copy link
Copy Markdown
Author

@codex run yarn lint fix

@chatgpt-codex-connector

Copy link
Copy Markdown

To use Codex here, create an environment for this repo.

Auspicus and others added 7 commits July 27, 2026 17:19
… order to avoid error in Maplibre (visgl#2573)

* Add updateZoomConstraint helper

* Fix types, prevent duplicate call to setMinZoom or setMaxZoom

* Add the same logic for pitch, format code

* Return whether or not changes were applied from the updatePitchConstraint and updateZoomConstraint func

* Add back propPresent

* yarn lint fix

* refactor: cleanup tests, prop names, code duplication, comments

---------

Co-authored-by: Xiaoji Chen <Pessimistress@users.noreply.github.com>
* fix(react-maplibre): support maplibre-gl v6 (transform getters, setTransformCameraUpdate, event typing)

* clean up

* clean up

* code review

* test(react-maplibre): cover public camera getters

* fix(react-maplibre): bridge box zoom event types

* fix: deduplicate gl-matrix dependency

* chore: rely on deduplicated gl-matrix lockfile

* test: configure MapLibre worker for browser tests

* ci: test MapLibre v6

* fix(react-maplibre): bridge versioned MapLibre types

* refactor(react-maplibre): simplify layer property setters

---------

Co-authored-by: Chris Gervang <chris.gervang@joby.aero>
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.

6 participants