Skip to content

fix: unset marker style properties that become undefined (#2595) - #2596

Open
MohammadYusif wants to merge 2 commits into
visgl:masterfrom
MohammadYusif:fix/issue-2595
Open

fix: unset marker style properties that become undefined (#2595)#2596
MohammadYusif wants to merge 2 commits into
visgl:masterfrom
MohammadYusif:fix/issue-2595

Conversation

@MohammadYusif

@MohammadYusif MohammadYusif commented Jul 14, 2026

Copy link
Copy Markdown

Summary

  • <Marker style={...}> did not unset a CSS property when it changed to undefined or was removed from the style object (e.g. {background: 'red'} -> {background: undefined} or {} left background set).
  • Root cause: applyReactStyle only wrote the keys present in the incoming style object and never cleared previously-applied keys; assigning undefined to a style property is a no-op, so stale values lingered.

Changes

  • modules/react-mapbox/src/utils/apply-react-style.ts / modules/react-maplibre/src/utils/apply-react-style.ts: track applied keys per element via a WeakMap, skip undefined/null values, and clear any previously-applied key that is no longer present.
  • modules/react-mapbox/test/utils/apply-react-style.spec.js / modules/react-maplibre/test/utils/apply-react-style.spec.js: add regression test covering the {background: undefined} and {} cases.

Fixes #2595


Note

Low Risk
Localized DOM styling helper change with tests; no auth, data, or API surface changes.

Overview
Fixes stale inline styles on map overlays (e.g. <Marker style={...}>) when a property is cleared via undefined/null or dropped from the style object.

applyReactStyle in react-mapbox and react-maplibre now remembers which keys it applied per DOM node (WeakMap), skips undefined/null values, and resets any previously applied key that is no longer present by setting style[key] = ''. Regression tests cover the background: undefined and empty {} cases.

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

applyReactStyle only wrote the keys present in the incoming style object
and never removed keys that were previously applied but later became
undefined or were omitted. Because assigning undefined to a CSS property
is a no-op, the stale value lingered on the element (e.g. a Marker's
background stayed set after style went from {background: 'red'} to
{background: undefined} or {}).

Track the keys applied to each element via a WeakMap and clear any that
are no longer present on the next update. Applied to both the react-mapbox
and react-maplibre variants, with regression tests covering the
undefined-value and omitted-key cases.

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit bbdc9ce. Configure here.

}
const style = element.style;
const previousKeys = appliedStyleKeys.get(element);
const nextKeys: string[] = [];

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Null style crashes applyReactStyle

High Severity

Removing the !styles guard means for...in runs when styles is null or undefined, which throws. Call sites pass optional props.style, so Markers, Popups, and controls without a style prop crash on mount. An existing test still expects null style not to throw.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit bbdc9ce. Configure here.

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.

[Bug] Prop style does not unset properties that become undefined

2 participants