Skip to content

setAttribute error when morphing elements with Alpine.js shorthand syntax (@change, :class, etc.) #147

@Gloib

Description

@Gloib

When using Idiomorph with Alpine.js, morphing fails when server-returned content contains Alpine's shorthand attribute syntax (e.g., @change) on non-input elements (like div, span, etc.).

Error:
InvalidCharacterError: Failed to execute 'setAttribute' on 'Element': '@change' is not a valid attribute name.

<!-- Original -->
<div>Content</div>

<!-- Server returns morphed content with shorthand syntax -->
<div @change="doSomething()">Content</div>

The issue is that setAttribute() validates attribute names strictly, while the browser's HTML parser may have accepted invalid names when parsing the server response.

For now I'm using the full Alpine syntax x-on:change instead of shorthands @change in server responses. It would be nice to support shorthands since they work in the initial DOM and are idiomatic Alpine.js.

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions