fix: unset marker style properties that become undefined (#2595) - #2596
Open
MohammadYusif wants to merge 2 commits into
Open
fix: unset marker style properties that become undefined (#2595)#2596MohammadYusif wants to merge 2 commits into
MohammadYusif 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


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.