diff --git a/src/component.js b/src/component.js index a5e7fd513f..d38f60ca36 100644 --- a/src/component.js +++ b/src/component.js @@ -143,6 +143,7 @@ function renderComponent(component, commitQueue, refQueue) { refQueue ); + newVNode._original = oldVNode._original; newVNode._parent._children[newVNode._index] = newVNode; newVNode._nextDom = undefined; diff --git a/test/browser/components.test.js b/test/browser/components.test.js index 2c1a80c35d..39a5dc8457 100644 --- a/test/browser/components.test.js +++ b/test/browser/components.test.js @@ -340,6 +340,50 @@ describe('Components', () => { expect(scratch.innerHTML).to.equal('

B

'); }); + 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 ( +

+ {counter}-{this.state.counter} +

+ ); + } + } + class App extends Component { + constructor(props) { + super(props); + this.state = { counter: 0 }; + update = () => { + this.setState({ counter: this.state.counter + 1 }); + }; + } + + render() { + return ; + } + } + + render(, scratch); + expect(scratch.innerHTML).to.equal(''); + + update2(); + rerender(); + update(); + rerender(); + expect(scratch.innerHTML).to.equal('

1-1

'); + }); + 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() {