Skip to content
New issue

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

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

Already on GitHub? # to your account

fix: correctly restore _original #4280

Merged
merged 2 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions src/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ function renderComponent(component, commitQueue, refQueue) {
refQueue
);

newVNode._original = oldVNode._original;
newVNode._parent._children[newVNode._index] = newVNode;

newVNode._nextDom = undefined;
Expand Down
44 changes: 44 additions & 0 deletions test/browser/components.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,50 @@ describe('Components', () => {
expect(scratch.innerHTML).to.equal('<p>B</p>');
});

it('should update children props correct', () => {
let update, update2;
class Counter extends Component {
constructor(props) {
super(props);
this.state = { counter: 0 };
update2 = () => {
this.setState({ counter: this.state.counter + 1 });
};
}

render({ counter }) {
if (!counter) return null;
return (
<p>
{counter}-{this.state.counter}
</p>
);
}
}
class App extends Component {
constructor(props) {
super(props);
this.state = { counter: 0 };
update = () => {
this.setState({ counter: this.state.counter + 1 });
};
}

render() {
return <Counter counter={this.state.counter} />;
}
}

render(<App />, scratch);
expect(scratch.innerHTML).to.equal('');

update2();
rerender();
update();
rerender();
expect(scratch.innerHTML).to.equal('<p>1-1</p>');
});

it("should render components that don't pass args into the Component constructor (unistore pattern)", () => {
// Pattern unistore uses for connect: https://github.com/developit/unistore/blob/1df7cf60ac6fa1a70859d745fbaea7ea3f1b8d30/src/integrations/preact.js#L23
function Wrapper() {
Expand Down
Loading