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

registration of a custom element is being assumed when initializing a custom element #144

Closed
thescientist13 opened this issue Feb 18, 2024 · 0 comments · Fixed by #146
Closed
Assignees
Labels
0.12.0 bug Something isn't working
Milestone

Comments

@thescientist13
Copy link
Member

Summary

In this section of code in initializeCustomElement, where in we see an element has already been registered, we only do so if we have a reference to a tag name

const element = tagName
  ? customElements.get(tagName)
  : (await import(pathname)).default;

Technically this should be fine, because in the only place where it is getting called with a tagName, it already checks if a "local" definition exists

if (definitions[tagName]) {
  const { moduleURL } = definitions[tagName];
  const elementInstance = await initializeCustomElement(moduleURL, tagName, node.attrs, definitions);

However...

Details

As observed in ProjectEvergreen/greenwood#1186 when refactoring Greenwood's bundle output and seeing in a demo repo when just running the server locally, that refactor exposed an interesting use case where in a custom element definition was getting used across two distinct API routes and for some reason the second invokation of using renderFromHTML caused a failed re-use of a custom element definition

greenwood-wcc-element-instance-no-shadow-root.mov

Not really sure, why maybe some race conditions? But a really simple solution is to just augment check if its actually in the registry first, which we probably should have been doing anyway. 😅

const element = customElements.get(tagName) ?? (await import(pathname)).default;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0.12.0 bug Something isn't working
Projects
No open projects
1 participant