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

Issue when constructing kicanvas-source with document.createElement #74

Open
tjhorner opened this issue Jan 17, 2024 · 1 comment
Open
Labels
bug Something isn't working embedding Issues with using KiCanvas in other pages p1 second highest priority; affects many users

Comments

@tjhorner
Copy link

Describe the bug

When creating a kicanvas-source element programmatically with document.createElement, the browser gets very upset with the following error (or similar):

  • Chrome: Uncaught DOMException: Failed to construct 'CustomElement': The result must not have attributes
  • Safari: NotSupportedError: A newly constructed custom element must not have attributes
  • Firefox: Uncaught DOMException: Operation is not supported

This behavior can occur when creating kicanvas-sources directly, of course, but it can also occur as a side effect of being in an environment like React, which does the same when building custom elements inside of React components.

To Reproduce

Here is a minimal POC; you can paste it into the JS console of any page with KiCanvas loaded:

const kcSource = document.createElement("kicanvas-source")

It will result in an error in the console.

Expected behavior

The kicanvas-source element should be created dynamically without an error.

Screenshots

image

Environment

  • OS: macOS
  • OS version: 14.0 (23A344)
  • Browser: Chrome / Firefox / Safari
  • Chrome version: 120.0.6099.199
  • Firefox version: 121.0.1
  • Safari version: 17.0 (19616.1.27.211.1)

Additional context

I believe the issue is being caused around here:

constructor() {
super();
this.ariaHidden = "true";
this.hidden = true;
this.style.display = "none";
}

...or maybe by this decorator:

@attribute({ type: String })
src: string | null;

The browser apparently does not like custom elements manipulating the DOM in their constructor, since it's technically against the spec.

@tjhorner tjhorner added the bug Something isn't working label Jan 17, 2024
@theacodes theacodes added embedding Issues with using KiCanvas in other pages p1 second highest priority; affects many users labels Jan 17, 2024
@theacodes
Copy link
Owner

Looks like we probably just need to move those constructor bits into connectedCallback(). Feel free to send a PR if you'd like, otherwise, I'll get it when I have a chance to sit down with this project again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working embedding Issues with using KiCanvas in other pages p1 second highest priority; affects many users
Projects
None yet
Development

No branches or pull requests

2 participants