Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix access to undefined exception #4219

Merged
merged 3 commits into from
Nov 27, 2023
Merged
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
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
Loading