Skip to content

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

Open
@tjhorner

Description

@tjhorner

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingembeddingIssues with using KiCanvas in other pagesp1second highest priority; affects many users

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions