fix(compat): avoid mutating user-provided style objects when appending px#5117
Open
JSap0914 wants to merge 2 commits into
Open
fix(compat): avoid mutating user-provided style objects when appending px#5117JSap0914 wants to merge 2 commits into
JSap0914 wants to merge 2 commits into
Conversation
…g px handleDomVNode() was directly mutating the style object passed by the user via value[key] += 'px'. This permanently modifies the caller's original object—an unexpected side effect. Fix by shallow-copying the style object before the per-key px loop. The existing px-append behaviour is preserved; the user's object is left unchanged.
📊 Tachometer Benchmark ResultsSummaryA summary of the benchmark results will show here once they finish. ResultsThe full results of your benchmarks will show here once they finish. |
JSap0914
commented
Jun 17, 2026
JoviDeCroock
approved these changes
Jul 16, 2026
JoviDeCroock
left a comment
Member
There was a problem hiding this comment.
A code golfing suggestion
| } | ||
|
|
||
| if (i === 'style' && typeof value === 'object') { | ||
| let cloned = false; |
Member
There was a problem hiding this comment.
Suggested change
| let cloned = false; | |
| let cloned; |
Comment on lines
+143
to
+144
| value = assign({}, value); | ||
| cloned = true; |
Member
There was a problem hiding this comment.
Suggested change
| value = assign({}, value); | |
| cloned = true; | |
| cloned = value = assign({}, value); |
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.
Bug
handleDomVNodeincompat/src/render.jsmutates the style object supplied by the caller when appendingpxto numeric values:valueis a direct reference toprops[i](the original object passed by the user). After this loop the caller's object is permanently modified—margin: 10becomesmargin: "10px"—which is an unexpected side effect.Fix
Shallow-copy the style object before the loop so mutations stay local to
normalizedProps:The px-append behaviour and the rendered output are unchanged; only the caller's object is now left untouched.
Verification
New test: "should not mutate the original style object when appending px" — this test failed before the fix (
style.marginwas mutated to"10px") and passes after it.All 46 existing compat-render tests continue to pass; full suite: 1242 passed, 12 skipped across 101 test files.