fix: unset marker style properties that become undefined (#2595)#2596
Open
MohammadYusif wants to merge 1 commit into
Open
fix: unset marker style properties that become undefined (#2595)#2596MohammadYusif wants to merge 1 commit into
MohammadYusif wants to merge 1 commit 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.
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