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

Add conditional check to prevent redefining existing custom stream source element #34

Merged
merged 1 commit into from
Mar 6, 2024

Conversation

omarluq
Copy link
Sponsor Contributor

@omarluq omarluq commented Mar 6, 2024

This Pull Request introduces a safeguard in the start.js file to prevent the redefinition of existing custom elements. The issue was observed when legacy JQuery page-refresh events or jest-dom testing caused anycable to reinitiate the start function. This led to an unnecessary re-triggering of the custom stream element definition, even when the element was already present in the window.

The proposed solution involves a conditional check before defining the custom element:

if (customElements.get(tagName) === undefined) {
  customElements.define(tagName, C)
}

This approach is consistent with the convention used in the hotwired turbo library.

@palkan
Copy link
Member

palkan commented Mar 6, 2024

Thanks!

@palkan palkan merged commit 445a68e into anycable:master Mar 6, 2024
2 checks passed
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