Le0Developer / react-turnstile

A very simple React library for Cloudflare Turnstile.
https://turnstile-demo.pages.dev/
MIT License
106 stars 15 forks source link

globalThis usage/check is crashing browsers #9

Closed zehawki closed 1 year ago

zehawki commented 1 year ago

Hello, since adding this package in early Dec 2022 we've been getting 100s of:

ReferenceError: "globalThis is not defined" in production

from all over the place - multiple older browsers, including safari and android webview etc

After various debugging I think I've isolated the issue to this package, and this:

https://github.com/Le0Developer/react-turnstile/blob/a21309e2d17158438b706fa33262de5494501cf9/src/index.tsx#L4

Please see more on this here: https://mathiasbynens.be/notes/globalthis

Le0Developer commented 1 year ago

globalThis has been supported on all major browsers for the past 3+ years, but it appears that Android has been lagging behind.

Although you are right, my check is flawed, it should be typeof globalThis !== "undefined" ? globalThis : window. (can't rely on pure window due to node SSR) Will publish an update :soon:

zehawki commented 1 year ago

Note that we are not doing SSR, these errors are being reported on client browsers.

globalThis has been supported on all major browsers for the past 3+ years

Yes it has, nevertheless many have older browsers, esp older Safari. If you search for "referenceerror globalthis is not defined" - you'll see lots of people running into it... so a fix would be good :-)

I've anyway included a polyfill on my side: @ungap/global-this

Le0Developer commented 1 year ago

Fixed in 39d643c, which is being released as v1.1.0 this moment.