Skip to content

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

Open
MohammadYusif wants to merge 1 commit into
visgl:masterfrom
MohammadYusif:fix/issue-2595
Open

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

Conversation

@MohammadYusif

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

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

1 participant