mirror of
https://github.com/PrivateCaptcha/PrivateCaptcha.git
synced 2026-02-09 15:28:49 -06:00
When the widget script is loaded multiple times (possible in SPA environments with framework component lifecycles), the application crashes with:
```
Uncaught DOMException: CustomElementRegistry.define: 'progress-ring' has already been defined as a custom element
```
This occurs because `customElements.define()` throws an error if called twice with the same element name, and the Custom Elements API provides no way to undefine or replace registered elements.
### Solution
Added a guard to check if the custom element is already registered before attempting to define it:
```javascript
if (typeof window !== "undefined" &&
window.customElements &&
!window.customElements.get('progress-ring')) {
window.customElements.define('progress-ring', ProgressRing);
}
```
### Why This Matters
- **Prevents crashes** in SPA environments where components mount/unmount repeatedly
- **Idempotent behavior** - script can safely be included multiple times
This is a defensive programming practice recommended for any third-party script that registers custom elements, as you cannot control how integrators will load your code.