From eb482562114ed0cd3ea255c916329fac67605846 Mon Sep 17 00:00:00 2001 From: Jovi De Croock Date: Thu, 15 Feb 2024 14:53:11 +0100 Subject: [PATCH 1/2] correctly restore _original --- src/component.js | 1 + test/browser/components.test.js | 44 +++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) 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..36a4aa1c01 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 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 ( +

+ {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() { From fe2899ac296bfabb67c5848ac96d41c9bd28f680 Mon Sep 17 00:00:00 2001 From: Jovi De Croock Date: Thu, 15 Feb 2024 14:56:54 +0100 Subject: [PATCH 2/2] Update test/browser/components.test.js --- test/browser/components.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/browser/components.test.js b/test/browser/components.test.js index 36a4aa1c01..39a5dc8457 100644 --- a/test/browser/components.test.js +++ b/test/browser/components.test.js @@ -340,7 +340,7 @@ describe('Components', () => { expect(scratch.innerHTML).to.equal('

B

'); }); - it('should update children props correct', () => { + it('should update children props correctly in subsequent renders', () => { let update, update2; class Counter extends Component { constructor(props) {