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

fix: reuse if there is already defined custom element #958

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Donggggg
Copy link

@Donggggg Donggggg commented Oct 30, 2024

Summary of Changes

  • If a custom element(em-emoji-picker) is already defined, use it to create an instance.

Reason for Changes

In emoji-mart-react, an instance is created using custom element(Picker) during initial rendering.
If my application has more than 2 packages using emoji-mart, I get into trouble in the following scenario.

  1. When initializing emoji-mart in the first package, the custom element(em-emoji-picker) is defined because it has never been defined.
    if (
    typeof customElements !== 'undefined' &&
    !customElements.get('em-emoji-picker')
    ) {
    customElements.define('em-emoji-picker', PickerElement)
  2. When initializing emoji-mart in the second package, the custom element(em-emoji-picker) is already defined, so it does not defined.
  3. When initializing an instance using a custom element in the second package, Illegal constructor error occurs because the class used in the second package is not defined.

To fix this issue, I added guard logic to reuse custom element that is already defined.

Issues

#812

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.

1 participant