Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Check that turnstile was loaded before calling remove during onDestroy #7

Merged
merged 1 commit into from
Feb 23, 2023

Conversation

piprees
Copy link
Contributor

@piprees piprees commented Feb 22, 2023

Hi there. Great library!

Noticed a console error:
Cannot read properties of undefined (reading 'remove')

Which is caused by this method in src/lib/ngx-turnstile.component.ts:

  public ngOnDestroy(): void {
    window.turnstile.remove(this.widgetId);
  }

We do a lot of lazy loading and generally don't load many modules in our root component.

When the user logs in and our # modal gets destroyed (which contains this widget), the onDestroy method is called which subsequently calls window.turnstile.remove.

The problem in our case is that turnstile hasn't actually been loaded yet, so this pull request adds a check to make sure the widget id exists (which seems to indicate that the callback has fired) before calling window.turnstile.remove:

  public ngOnDestroy(): void {
    if (this.widgetId) {
      window.turnstile.remove(this.widgetId);
    }
  }

Happy to make any changes.

Copy link
Member

@choyiny choyiny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution, lgtm!

@choyiny choyiny merged commit 4e7509a into verto-health:main Feb 23, 2023
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants