Replies: 2 comments
-
@fivelive thanks for reporting!
I think this is probably the most pragmatic approach. There is a future feature called Scoped Custom Element Registries that might give you a better option someday, but for now I would recommend that you just have a custom build that uses a specialized tag name. Another thing you could try, if are willing to make a custom build and you want to get fancy, is something like this: let number = 1;
let tagName = 'model-viewer';
while (customElements.get(tagName) != null) {
tagName = `${tagName}-${++number}`; // Try model-viewer-2, model-viewer-3, model-viewer-4 etc.
}
customElements.define(tagName, ModelViewerElement); But in practice, you are probably safe 99% of the time if you just pick a unique tag name like That said, the main areas (that I can think of) that could cause problems are the following:
There are probably other caveats, and I'll try to document them for you if I think of them. In general, it should be feasible for you to define multiple, different tags for |
Beta Was this translation helpful? Give feedback.
-
Waouw! Thanks @cdata for this complete answer, you really helped here. |
Beta Was this translation helpful? Give feedback.
-
I’m thinking of a scenario where I would want to dynamically add a
model-viewer
element on a customer’s website, not knowing if that website already has amodel-viewer
script tag in its DOM.(Note: I'm talking about the script tag to import model-viewer, not the model-viewer tag itself).
Also, if that website already has a
model-viewer
script tag in its DOM, now the issue would be the version of the existingmodel-viewer
script tag. (Assuming that I need to work with a specific version ofmodel-viewer
).If a
model-viewer
script tag is already in the DOM and we try to include our ownmodel-viewer
script tag, the CustomElementRegistry will throw an exception, because the "model-viewer" custom element name is already in the registry. Thus, the model-viewer version used will be the one of the existing script tag.The only solution I can think of to be able to use a specific version of model viewer in my dynamically added HTML on a customer's website would be this:
Have a custom distribution of model-viewer with a different custom element name (ex:
my-model-viewer
).This way, there would be no conflict in the CustomElementRegistry when trying to include my own script tag, and by using a
my-model-viewer
tag, also making sure to use the specific version I need.Does that make sens? Could it have some side effect I'm not aware of?
Is there any better solution to this problem?
Thanks
Beta Was this translation helpful? Give feedback.
All reactions