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

r-svg-eqn illegally sets attributes in its constructor #30

Open
justinfagnani opened this issue Jun 29, 2022 · 0 comments
Open

r-svg-eqn illegally sets attributes in its constructor #30

justinfagnani opened this issue Jun 29, 2022 · 0 comments

Comments

@justinfagnani
Copy link

Custom elements are not allowed to set their own attributes in the constructor. This is because new SomeElement() should be created without attributes, like every built-in element.

<r-svg-eqn> does this here: https://github.com/curvenote/svg/blob/main/src/components/equation.ts#L60

This limitation is enforced by browsers, but only when elements are defined before parsed in the main page. This happens when using the bundled script from https://unpkg.com/@curvenote/article. Since that script is a classic script, and not a module, it is executed before the rest of the page parses, then when <r-svg-eqn> is parsed it's instantiated, sets an attribute, and errors.

Here's a live reproduction that starts our not working. You can see the error in the console.

You can make it work by adding async to the curvenote script, causing it to run after the page is parsed, or by commenting out the <r-svg-eqn> elements.

In this case this can probably be fixed by giving the stroke property a default value instead of setting the attribute, which is also how reflected properties in built-in elements work.

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

No branches or pull requests

1 participant