From 5c9a53dfaf255e7451db1afa476de99b68170368 Mon Sep 17 00:00:00 2001 From: Thibaud Colas Date: Wed, 14 Apr 2021 08:45:19 +0100 Subject: [PATCH] Clear save timeout handler when unmounting the editor. Fix #208 (#443) --- CHANGELOG.md | 1 + lib/components/DraftailEditor.js | 2 ++ lib/components/DraftailEditor.test.js | 2 ++ 3 files changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 67b9dc4c..19929907 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ ### Fixed - Fix empty buttons appearing when providing custom formats without a defined label or icon. [#442](https://github.com/springload/draftail/pull/442) +- Clear save timeout handler when unmounting the editor. [#208](https://github.com/springload/draftail/issues/208), [#443](https://github.com/springload/draftail/pull/443) ## [[v1.3.0]](https://github.com/springload/draftail/releases/tag/v1.3.0) diff --git a/lib/components/DraftailEditor.js b/lib/components/DraftailEditor.js index 51282cbd..8ebbe3f7 100644 --- a/lib/components/DraftailEditor.js +++ b/lib/components/DraftailEditor.js @@ -329,6 +329,8 @@ class DraftailEditor extends Component { componentWillUnmount() { this.copySource.unregister(); + + window.clearTimeout(this.updateTimeout); } /* :: onFocus: () => void; */ diff --git a/lib/components/DraftailEditor.test.js b/lib/components/DraftailEditor.test.js index cea7dbf0..309c2c3f 100644 --- a/lib/components/DraftailEditor.test.js +++ b/lib/components/DraftailEditor.test.js @@ -359,9 +359,11 @@ describe("DraftailEditor", () => { const wrapper = mount(); const { copySource } = wrapper.instance(); jest.spyOn(copySource, "unregister"); + jest.spyOn(window, "clearTimeout"); expect(copySource).not.toBeNull(); wrapper.unmount(); expect(copySource.unregister).toHaveBeenCalled(); + expect(window.clearTimeout).toHaveBeenCalled(); }); describe("onChange", () => {