From 1e14862a7dc2f8edcc4e98a9e1019ad6076d8a5a Mon Sep 17 00:00:00 2001 From: Andre Wiggins <459878+andrewiggins@users.noreply.github.com> Date: Mon, 13 Nov 2023 21:23:47 -0800 Subject: [PATCH] Add test for removing children of memoed components (#4210) Repro from issue #2619 --- test/browser/keys.test.js | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/test/browser/keys.test.js b/test/browser/keys.test.js index 4bb6ee807a..d3a7ebbf68 100644 --- a/test/browser/keys.test.js +++ b/test/browser/keys.test.js @@ -443,6 +443,44 @@ describe('keys', () => { ]); }); + it('should properly remove children of memoed components', () => { + const values = [1, 2, 3, 4, 5, 6, 7, 8, 9]; + + class Item extends Component { + shouldComponentUpdate(props) { + return props.value !== this.props.value; + } + + render() { + return
  • {this.props.value}
  • ; + } + } + + function App({ values }) { + return ( + + ); + } + + render(, scratch); + expect(scratch.textContent).to.equal(values.join('')); + + clearLog(); + values.splice(3, 3); + + render(, scratch); + expect(scratch.textContent).to.equal(values.join('')); + expect(getLog()).to.deep.equal([ + '
  • 4.remove()', + '
  • 5.remove()', + '
  • 6.remove()' + ]); + }); + it("should not preserve state when a component's keys are different", () => { const Stateful = createStateful('Stateful');