Skip to content
This repository was archived by the owner on Dec 16, 2021. It is now read-only.

Commit 605b943

Browse files
xxxiindevelopit
authored andcommitted
fix multi cloned element lose props.children bug (#415)
1 parent 1a88d10 commit 605b943

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ function cloneElement(element, props, ...children) {
304304
let elementProps = element.attributes || element.props;
305305
let node = h(
306306
element.nodeName || element.type,
307-
elementProps,
307+
extend({}, elementProps),
308308
element.children || elementProps && elementProps.children
309309
);
310310
// Only provide the 3rd argument if needed.

test/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,9 @@ describe('preact-compat', () => {
249249

250250
it('should support props.children', () => {
251251
let element = <foo children={<span>b</span>}></foo>;
252-
expect(cloneElement(element)).to.eql(element);
252+
let clone = cloneElement(element);
253+
expect(clone).to.eql(element);
254+
expect(cloneElement(clone).props.children).to.eql(element.props.children);
253255
});
254256

255257
it('children take precedence over props.children', () => {

0 commit comments

Comments
 (0)