Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions compat/src/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,13 @@ function handleDomVNode(vnode) {
}

if (i === 'style' && typeof value === 'object') {
let cloned = false;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let cloned = false;
let cloned;

for (let key in value) {
if (typeof value[key] === 'number' && !IS_NON_DIMENSIONAL.test(key)) {
if (!cloned) {
value = assign({}, value);
Comment thread
JoviDeCroock marked this conversation as resolved.
cloned = true;
Comment on lines +143 to +144

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
value = assign({}, value);
cloned = true;
cloned = value = assign({}, value);

}
value[key] += 'px';
}
}
Expand Down
7 changes: 7 additions & 0 deletions compat/test/browser/render.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -886,4 +886,11 @@ describe('compat render', () => {
}
}
});

it('should not mutate the original style object when appending px', () => {
const style = { margin: 10, opacity: 0.5 };
render(<div style={style} />, scratch);

expect(style).to.deep.equal({ margin: 10, opacity: 0.5 });
});
});