Issue with cloneNode with Phoenix LiveView #4514
-
Hi, I'm trying to integrate Alpine into my Phoenix LiveView application. I followed some instructions saying that I have to put this code:
LiveView also uses Morph, so when an element is about to get updated, I have to call the It appears to do the job. That's what I did, but now, everything is broken. I have a simple broken example:
With the code above, the I checked the code and they seem to do pretty much the same thing, so I don't understand why my For information, the In both cases (with It's like if the This behavior seems logical, but I still can't figure out why it's not the same with Thank you for your help FWIW: I also have elements in my page with custom directives and I could see that, with EDIT I think now I understand why
The cloned element is the one with So,
This seems intentional however, but it prevents me from keeping my I think there are also other issues with EDIT 2 A change in the list of classes seems to trigger an attribute added event in the mutation observer. I think this could solve a part of my issue with the But there is still the issue with loops deleting their content and not recreating it. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
I figured out what was the problem and I was able to fix it. For the
The other issue was with In my use case, I could simply solve this by surrounding my I had another use case where I couldn't use |
Beta Was this translation helpful? Give feedback.
I figured out what was the problem and I was able to fix it.
For the
cloneNode
issue, here is the code to use for phoenix LiveView:cloneNode
is called on update for any element handled by Alpine. Not only root elements.This way, children of a root element being updated will be initialized by Alpine (solves my class problem).
The other issue was with
template
nodes being updated (their created elements were being removed from the DOM).The issue is actually not directly related to
template
nodes, but to the directives that create/clone elements (likex-for
,x-if
,x…