Alpine directives not evaluated within asynchronously added x-html #1724
Unanswered
liam-edwards
asked this question in
5. Bugs
Replies: 1 comment
-
Just an update, moving that button in the last snippet to above the |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I am facing an issue where Alpine directives within
x-html
that is fetched asynchronously are not evaluated. What I've resorted to doing is runningAlpine.initTree
on thecomponent-editor
class after thex-for
andx-html
render the added HTML. This has worked for the most part but it is not reliable. Below is a simplified version of my JavaScript and markup.Up until recently, all the HTML that was added asynchronously had just been using
x-bind
and after the aforementionedAlpine.initTree
, it would work, however a new one requires more complicated Alpine logic, includingx-for
,x-show
,@click
, andx-text
. Simplifying it a bit:The
x-text
's purpose was simply to show that the Alpine directive wasn't evaluating, even withAlpine.initTree
getting applied over this. See attached video for that. On a whim, I tried runningAlpine.initTree
on all the children of.component-editor
as well, and remarkably, that fixes the button, however it breaks the initialx-for
from the first markup snippet by making it render two items despite only one being in the array. Removing theAlpine.initTree
on.component-editor
and leaving it on the children fixes that new issue, but now the button is broken again.All in all, there are a few issues here, but they all stem from Alpine directives within asynchronously added
x-html
not working.alpine-strangeness.mp4
Beta Was this translation helpful? Give feedback.
All reactions