Skip to content

Comments

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

Open
mbret wants to merge 1 commit intovisgl:masterfrom
mbret:fix/unpredictable-terrain-crash
Open

fix: prevent app wide crash when terrain properties are undefined#2582
mbret wants to merge 1 commit intovisgl:masterfrom
mbret:fix/unpredictable-terrain-crash

Conversation

@mbret
Copy link

@mbret mbret commented Feb 17, 2026

[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.

Copy link

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

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);

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
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.

Choose a reason for hiding this comment

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

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