raygun4js icon indicating copy to clipboard operation
raygun4js copied to clipboard

raygun4js only initialises if apiKey is set when `onLoadHandler` is called

Open Widdershin opened this issue 3 years ago • 3 comments
trafficstars

This makes it difficult to initialise raygun4js asynchronously, which is becoming more common.

Related: #453, #383, #259

Widdershin avatar Apr 26 '22 05:04 Widdershin

We've come across this issue today and did some digging / reproduction on the issue.

Please see this minimum reproduction and readme here: https://github.com/Codex-/rg4js-init-issue

The issue is that in a lot of cases a key is configured for raygun after the library has initialised, to work around this a consumer can call rg4js('boot'); (typescript typings pr raised for the typings issue: https://github.com/DefinitelyTyped/DefinitelyTyped/pull/61397 )

I have a few ideas how this could be resolved but wanted to bounce ideas with the raygun team before I make a PR. Simplest thing would be to flag is onLoadHandler has been executed, then if an API key is configured after this has been executed, simply execute onLoadHandler again (which is what people are effectively doing by manually calling boot).

Another would be a stepping retry as a floated promise.

Let me know your thoughts :)

Codex- avatar Jul 22 '22 03:07 Codex-

Hey @Codex- , thanks for the reproduction and types PR!

@Widdershin is currently away for a bit, but I've spoken to @darcythomas and we can take a look if you want to make a PR. The simplest approach seems fine for now 👍

Deacon-McIntyre avatar Jul 25 '22 04:07 Deacon-McIntyre

No problem at all, I've raised #474 now with a fix :)

Also, if you haven't seen it, I have also raised: https://github.com/DefinitelyTyped/DefinitelyTyped/pull/61397

This is to add the missing typing for calling 'boot', as users were doing some spooky casting to get around the missing type 😅

Codex- avatar Jul 25 '22 22:07 Codex-