Skip to content

Commit 397d690

Browse files
committed
move test to core
1 parent d1f8ee5 commit 397d690

File tree

3 files changed

+51
-42
lines changed

3 files changed

+51
-42
lines changed

hooks/test/browser/combinations.test.js

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -477,45 +477,4 @@ describe('combinations', () => {
477477
'anchor effect'
478478
]);
479479
});
480-
481-
it('should not crash or repeatedly add the same child when replacing a matched vnode with null', () => {
482-
const B = () => <div>B</div>;
483-
484-
let update;
485-
const Test = () => {
486-
const [state, setState] = useState(true);
487-
update = () => setState(s => !s);
488-
489-
if (state) {
490-
return (
491-
<div>
492-
<B />
493-
<div />
494-
</div>
495-
);
496-
}
497-
return (
498-
<div>
499-
<div />
500-
{null}
501-
<B />
502-
</div>
503-
);
504-
};
505-
506-
render(<Test />, scratch);
507-
expect(scratch.innerHTML).to.equal('<div><div>B</div><div></div></div>');
508-
509-
update();
510-
rerender();
511-
expect(scratch.innerHTML).to.equal('<div><div></div><div>B</div></div>');
512-
513-
update();
514-
rerender();
515-
expect(scratch.innerHTML).to.equal('<div><div>B</div><div></div></div>');
516-
517-
update();
518-
rerender();
519-
expect(scratch.innerHTML).to.equal('<div><div></div><div>B</div></div>');
520-
});
521480
});

src/diff/children.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ function constructNewChildrenArray(newParentVNode, renderResult, oldChildren) {
234234
oldVNode &&
235235
oldVNode.key == null &&
236236
oldVNode._dom &&
237-
!oldVNode._flags & MATCHED
237+
(oldVNode._flags & MATCHED) === 0
238238
) {
239239
if (oldVNode._dom == newParentVNode._nextDom) {
240240
newParentVNode._nextDom = getDomSibling(oldVNode);

test/browser/render.test.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1308,4 +1308,54 @@ describe('render()', () => {
13081308
expect(divs[1].hasAttribute('role')).to.equal(false);
13091309
expect(divs[2].hasAttribute('role')).to.equal(false);
13101310
});
1311+
1312+
it('should not crash or repeatedly add the same child when replacing a matched vnode with null', () => {
1313+
const B = () => <div>B</div>;
1314+
1315+
let update;
1316+
class App extends Component {
1317+
constructor(props) {
1318+
super(props);
1319+
this.state = { show: true };
1320+
update = () => {
1321+
this.setState(state => ({ show: !state.show }));
1322+
};
1323+
}
1324+
1325+
render() {
1326+
console.log(this.state.show);
1327+
if (this.state.show) {
1328+
return (
1329+
<div>
1330+
<B />
1331+
<div />
1332+
</div>
1333+
);
1334+
} else {
1335+
return (
1336+
<div>
1337+
<div />
1338+
{null}
1339+
<B />
1340+
</div>
1341+
);
1342+
}
1343+
}
1344+
}
1345+
1346+
render(<App />, scratch);
1347+
expect(scratch.innerHTML).to.equal('<div><div>B</div><div></div></div>');
1348+
1349+
update();
1350+
rerender();
1351+
expect(scratch.innerHTML).to.equal('<div><div></div><div>B</div></div>');
1352+
1353+
update();
1354+
rerender();
1355+
expect(scratch.innerHTML).to.equal('<div><div>B</div><div></div></div>');
1356+
1357+
update();
1358+
rerender();
1359+
expect(scratch.innerHTML).to.equal('<div><div></div><div>B</div></div>');
1360+
});
13111361
});

0 commit comments

Comments
 (0)