Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Idempotent Custom Element registration #983

Merged
merged 1 commit into from
Nov 7, 2022
Merged

Idempotent Custom Element registration #983

merged 1 commit into from
Nov 7, 2022

Conversation

seanpdoyle
Copy link
Contributor

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