Skip to content

Error: "Cannot read properties of undefined (reading 'render')" when using ngx-turnstile in Angular conditional #49

@djgrove

Description

@djgrove

We are seeing some users of our application encounter the following TypeError on pages that use ngx-turnstile:

TypeError: Cannot read properties of undefined (reading 'render')
  at window[CALLBACK_NAME] (./node_modules/ngx-turnstile/fesm2022/ngx-turnstile.mjs:72:46)
  at NgxTurnstileComponent.createWidget (./node_modules/ngx-turnstile/fesm2022/ngx-turnstile.mjs:75:20)
  at callback (./node_modules/ngx-turnstile/fesm2022/ngx-turnstile.mjs:39:36)
  at apply (./node_modules/@angular/core/fesm2022/core.mjs:15211:9)
  at _ZoneDelegate.invoke (./node_modules/zone.js/fesm2015/zone.js:369:28)

Angular version: 17.3.12 (we definitely need to upgrade this, but we are blocked atm)
ngx-turnstile version: 0.2.4

I believe I have isolated it to instances of NgxTurnstileComponent that get rendered conditionally in a template. The intermittent nature of the error, and the line of code it is pointing to, seem to suggest this is a race condition in which the Cloudflare script has not yet loaded when the component tries to initialize.

I know a non-deterministic repro sucks, but figured I would at least file the issue so you are aware of this. It looks similar to this issue that was filed against ngx-paypal.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions