Skip to content

Commit f808dcb

Browse files
authored
fix: correctly restore _original (#4280)
* correctly restore _original * Update test/browser/components.test.js
1 parent 65310c6 commit f808dcb

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

src/component.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ function renderComponent(component, commitQueue, refQueue) {
143143
refQueue
144144
);
145145

146+
newVNode._original = oldVNode._original;
146147
newVNode._parent._children[newVNode._index] = newVNode;
147148

148149
newVNode._nextDom = undefined;

test/browser/components.test.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,50 @@ describe('Components', () => {
340340
expect(scratch.innerHTML).to.equal('<p>B</p>');
341341
});
342342

343+
it('should update children props correctly in subsequent renders', () => {
344+
let update, update2;
345+
class Counter extends Component {
346+
constructor(props) {
347+
super(props);
348+
this.state = { counter: 0 };
349+
update2 = () => {
350+
this.setState({ counter: this.state.counter + 1 });
351+
};
352+
}
353+
354+
render({ counter }) {
355+
if (!counter) return null;
356+
return (
357+
<p>
358+
{counter}-{this.state.counter}
359+
</p>
360+
);
361+
}
362+
}
363+
class App extends Component {
364+
constructor(props) {
365+
super(props);
366+
this.state = { counter: 0 };
367+
update = () => {
368+
this.setState({ counter: this.state.counter + 1 });
369+
};
370+
}
371+
372+
render() {
373+
return <Counter counter={this.state.counter} />;
374+
}
375+
}
376+
377+
render(<App />, scratch);
378+
expect(scratch.innerHTML).to.equal('');
379+
380+
update2();
381+
rerender();
382+
update();
383+
rerender();
384+
expect(scratch.innerHTML).to.equal('<p>1-1</p>');
385+
});
386+
343387
it("should render components that don't pass args into the Component constructor (unistore pattern)", () => {
344388
// Pattern unistore uses for connect: https://github.com/developit/unistore/blob/1df7cf60ac6fa1a70859d745fbaea7ea3f1b8d30/src/integrations/preact.js#L23
345389
function Wrapper() {

0 commit comments

Comments
 (0)