From 0519b9bd73169ceea6104e5f7c82e854cebc1830 Mon Sep 17 00:00:00 2001 From: wenincode Date: Fri, 13 Oct 2023 14:40:48 -0600 Subject: [PATCH] Move destroy handler registration in with-copyable --- ui/packages/consul-ui/app/modifiers/with-copyable.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/ui/packages/consul-ui/app/modifiers/with-copyable.js b/ui/packages/consul-ui/app/modifiers/with-copyable.js index 9867607f12e9..6c0bc5354282 100644 --- a/ui/packages/consul-ui/app/modifiers/with-copyable.js +++ b/ui/packages/consul-ui/app/modifiers/with-copyable.js @@ -12,7 +12,7 @@ const typeAssertion = (type, value, withDefault) => { }; function cleanup(instance) { - if (instance?.source && instance?.hash) { + if (instance && instance?.source && instance?.hash) { instance.source?.off('success', instance.hash.success)?.off('error', instance.hash.error); instance.source?.destroy(); @@ -49,11 +49,15 @@ export default class WithCopyableModifier extends Modifier { this.hash = hash; } + constructor() { + super(...arguments); + registerDestructor(this, cleanup); + } + modify(element, [value], namedArgs) { this.element = element; this.disconnect(); this.connect(value, namedArgs); - registerDestructor(this, cleanup); } disconnect() {