Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

TypeError: Cannot read properties of undefined (reading 'get') when a map is removed while a color-theme LUT is decoding

Open Beginner friendly
#13,737 1 comment 0 reactions 0 assignees View on GitHub

@Piyush495 is already working on this.

Since Oct 7, 2026.

  • #13738 by @Piyush495 — open

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
82/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
typescript
Domain
frontend

Research direction

Start in src/style/style.ts at Style._loadColorTheme, where lutImage.onload only checks lutLoadingCorrelationID before calling getImage; cross-reference src/render/image_manager.ts (ImageManager.getImage, removeScope) to see why a removed scope makes it throw. Reproduce by delaying onload for data:image/png images and calling map.remove() before the LUT decodes. Done means no uncaught exception on that path and a regression test covering the race, verifying that simply calling resolve() still fails later in _reloadImports/addImages.

Written by the indexing model from the issue text.

Description

auto-triaged bug :lady_beetle:

mapbox-gl-js version: 3.31.0. The same code is in 3.32.0 and 3.33.0-rc.1, and it also reproduces on 3.15.0.

Browser/OS: any. We first saw it in production on Edge on Windows, and reproduced it in Chromium.

Steps to trigger
  1. Create a map whose style has a non-empty color-theme. For example, a style that imports
    mapbox://styles/mapbox/standard with config.theme: "faded".
  2. Call map.remove(), or replace the map's style, after the style JSON is parsed but before the
    LUT Image fires onload.

You can make it deterministic by delaying onload for data:image/png images by a few seconds,
then calling map.remove() as soon as the LUT image decodes.

Expected

No error. The removed style should drop the pending LUT load.

Actual

An uncaught exception from the Image.onload handler:

TypeError: Cannot read properties of undefined (reading 'get')
    at ImageManager.getImage (src/render/image_manager.ts:189)
    at Style.getImage (src/style/style.ts:2407)
    at lutImage.onload (src/style/style.ts:1599)

map.remove() → Style.destroy() → fragment.style._remove() → imageManager.removeScope(scope)
deletes the scope. The lutImage.onload in Style._loadColorTheme only checks
lutLoadingCorrelationID, so it then calls getImage on a scope that no longer exists.

Suggested fix

Bail out of onload when the style has been removed, without settling the promise:

lutImage.onload = () => {
    if (!this.imageManager.images.has(this.scope)) return; // style was removed
    if (this._styleColorTheme.lutLoadingCorrelationID !== correlationID) { ... }

Calling resolve() here is not enough. It runs proceedWithStyleLoad() on the removed style, which
then throws in _reloadImports (_initialBroadcastDone) and in addImages.

Dominant language
TypeScript
Stars
12.5k
Forks
2.4k
PR merge metrics
No merged PRs in 30d

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from mapbox/mapbox-gl-js

All issues in mapbox/mapbox-gl-js

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.