From acdfebbd0136a09bd4a3544939c6f23e02801db7 Mon Sep 17 00:00:00 2001 From: Sergiu Danalachi Date: Thu, 12 Oct 2023 11:52:06 +0300 Subject: [PATCH] fix: safe destroy of hcaptcha instance --- .../src/lib/ng-hcaptcha-invisible-button.directive.ts | 4 ++++ projects/ng-hcaptcha/src/lib/ng-hcaptcha.component.ts | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/projects/ng-hcaptcha/src/lib/ng-hcaptcha-invisible-button.directive.ts b/projects/ng-hcaptcha/src/lib/ng-hcaptcha-invisible-button.directive.ts index 6ea2e1b..df18d46 100644 --- a/projects/ng-hcaptcha/src/lib/ng-hcaptcha-invisible-button.directive.ts +++ b/projects/ng-hcaptcha/src/lib/ng-hcaptcha-invisible-button.directive.ts @@ -59,6 +59,10 @@ export class NgHcaptchaInvisibleButtonDirective implements OnInit, OnDestroy { } ngOnDestroy() { + if (this.widgetId) { + window.hcaptcha.remove(this.widgetId); + } + if (isPlatformServer(this.platformId)) { return; } diff --git a/projects/ng-hcaptcha/src/lib/ng-hcaptcha.component.ts b/projects/ng-hcaptcha/src/lib/ng-hcaptcha.component.ts index c3d483c..d28530d 100644 --- a/projects/ng-hcaptcha/src/lib/ng-hcaptcha.component.ts +++ b/projects/ng-hcaptcha/src/lib/ng-hcaptcha.component.ts @@ -99,6 +99,10 @@ export class NgHcaptchaComponent implements OnInit, OnDestroy, ControlValueAcces } ngOnDestroy() { + if (this.widgetId) { + window.hcaptcha.remove(this.widgetId); + } + if (isPlatformServer(this.platformId)) { return; }