fix: unset marker style properties that become undefined (#2595) - #2596
fix: unset marker style properties that become undefined (#2595)#2596MohammadYusif wants to merge 2 commits into
Conversation
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.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Reviewed by Cursor Bugbot for commit bbdc9ce. Configure here.
| } | ||
| const style = element.style; | ||
| const previousKeys = appliedStyleKeys.get(element); | ||
| const nextKeys: string[] = []; |
There was a problem hiding this comment.
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)
Reviewed by Cursor Bugbot for commit bbdc9ce. Configure here.
|
Thanks for working on this! While reviewing, we found a few additional edge cases around CSS shorthand/longhand transitions and removing the style prop. In particular, removed properties need to be cleared before applying new values; otherwise transitions such as We opened #2601 as an alternative implementation. It keeps the per-element Curious to hear your thoughts on this and whether there’s anything from your implementation we should carry over? Thanks again for getting the fix started! |


Summary
<Marker style={...}>did not unset a CSS property when it changed toundefinedor was removed from the style object (e.g.{background: 'red'}->{background: undefined}or{}leftbackgroundset).applyReactStyleonly wrote the keys present in the incoming style object and never cleared previously-applied keys; assigningundefinedto 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 aWeakMap, skipundefined/nullvalues, 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 viaundefined/nullor dropped from the style object.applyReactStylein react-mapbox and react-maplibre now remembers which keys it applied per DOM node (WeakMap), skipsundefined/nullvalues, and resets any previously applied key that is no longer present by settingstyle[key] = ''. Regression tests cover thebackground: undefinedand empty{}cases.Reviewed by Cursor Bugbot for commit bbdc9ce. Bugbot is set up for automated code reviews on this repo. Configure here.