From b22dab30ac5c929889bd2fc436d358b2f1353195 Mon Sep 17 00:00:00 2001 From: Matthew Weidner <17693586+mweidner037@users.noreply.github.com> Date: Thu, 12 Dec 2024 21:30:05 -0600 Subject: [PATCH] Don't update the DOM if the toggle has been removed Currently, if the toggle causes the element to be removed from the DOM, the code that updates the DOM fails with `TypeError: Cannot read property 'querySelector' of null` --- addon/components/x-toggle.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/addon/components/x-toggle.js b/addon/components/x-toggle.js index 4d6be76..c14f302 100644 --- a/addon/components/x-toggle.js +++ b/addon/components/x-toggle.js @@ -54,6 +54,9 @@ export default class XToggle extends Component { @action toggleSwitch(value) { + // Prevent re-renders when the element is cleaning up (which cause errors). + if (this.isDestroyed || this.isDestroying) return + let onToggle = this.args.onToggle; let disabled = this.disabled;