Skip to content

Conversation

@seanpdoyle
Copy link
Collaborator

If the package is accidentally imported a second time, the Custom
Element registrations will raise an exception like:

NotSupportedError: Cannot define multiple custom elements with the same tag name

This commit adds a guard that checks whether or not the element has been
registered through a call to CustomElementRegistry.get. When
present, the redundant call to CustomElementRegistry.define is
skipped.

If the package is accidentally imported a second time, the Custom
Element registrations will raise an exception like:

```
NotSupportedError: Cannot define multiple custom elements with the same tag name
```

This commit adds a guard that checks whether or not the element has been
registered through a call to [CustomElementRegistry.get][]. When
present, the redundant call to [CustomElementRegistry.define][] is
skipped.

[CustomElementRegistry.get]: https://developer.mozilla.org/en-US/docs/Web/API/CustomElementRegistry/get
[CustomElementRegistry.define]: https://developer.mozilla.org/en-US/docs/Web/API/CustomElementRegistry/define
@afcapel afcapel merged commit 12fa9ef into basecamp:main Nov 7, 2022
@afcapel
Copy link
Contributor

afcapel commented Nov 7, 2022

Thanks @seanpdoyle 🙏

FYI V2 has a similar check although slightly different implementation.

@seanpdoyle seanpdoyle deleted the support-idempotent-registration branch November 7, 2022 17:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants