Skip to content

Commit

Permalink
fix: correctly restore _original (#4280)
Browse files Browse the repository at this point in the history
* correctly restore _original

* Update test/browser/components.test.js
  • Loading branch information
JoviDeCroock committed Feb 15, 2024
1 parent 65310c6 commit f808dcb
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
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 correctly in subsequent renders', () => {
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

0 comments on commit f808dcb

Please sign in to comment.