Skip to content

Commit

Permalink
Merge pull request #4219 from billti/billti/fix-is-access
Browse files Browse the repository at this point in the history
Fix access to undefined exception
  • Loading branch information
marvinhagemeister authored Nov 27, 2023
2 parents 3eb790c + 02ad4e2 commit 2629e40
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/diff/children.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ function constructNewChildrenArray(newParentVNode, renderResult, oldChildren) {
null,
null
);
} else if (childVNode._depth > 0) {
} else if (childVNode.constructor === undefined && childVNode._depth > 0) {
// VNode is already in use, clone it. This can happen in the following
// scenario:
// const reuse = <div />
Expand Down
22 changes: 22 additions & 0 deletions test/browser/components.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1897,6 +1897,28 @@ describe('Components', () => {
expect(unmounted).to.equal(',0,1,2,3');
});

it('should ignore invalid vnodes in children array', () => {
/** @type { (() => void)} */
let update;

const obj = { a: 10, b: 'hello' };
class App extends Component {
constructor(props) {
super(props);
this.state = { i: 0 };
update = () => this.setState({ i: this.state.i + 1 });
}

render() {
return <p>{obj}</p>;
}
}

render(<App />, scratch);
update();
expect(() => rerender()).not.to.throw();
});

describe('c.base', () => {
/* eslint-disable lines-around-comment */
/** @type {import('../../src').Component} */
Expand Down

0 comments on commit 2629e40

Please sign in to comment.