developit / developit/htm

Find a way to allow "@" in attribute?

Offen
#235 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
JavaScript
Sterne
9k
Forks
181
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

Both Vue and Alpine have this weird syntax where events get preceded by `@`. I'm using htm in a library for templating. Preact is more of an implementation detail, and not really exposed to users. I'm seeing someone who uses alpine on the rest of the page and wants an event handler that's handled by alpine in that template. Unfortunately the shorthand syntax doesn't seem to work due to `setAttribute`.

A reproduction is:

```js
import { render } from "preact";
import { html } from "htm/preact";

// does work
render(
html`


Expand


Content...


`,
document.body
);
```

(workaround is replacing `@` to `x-on:`, but our user wasn't aware of this)

sandbox: https://codesandbox.io/s/festive-wildflower-qeugtn?file=/src/index.js

other relevant issues:
https://github.com/alpinejs/alpine/issues/1235
https://github.com/alpinejs/alpine/issues/396
https://github.com/algolia/instantsearch/issues/5435

I'm guessing no workaround will be possible as it's actually setAttribute throwing, but I wonder if you know something that would avoid users changing their expectations.

Beitragsleitfaden

Beitragsleitfaden öffnen

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.