-
-
Notifications
You must be signed in to change notification settings - Fork 323
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
[LiveComponent] Fix morphing for Alpine.js v3 #2259
base: 2.x
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Thank you @Kobo-one |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey, I tried your patch locally on my app (the one I've used when working on #1126), but I'm having an issue.
Below you will find a video of my app and some interaction with a dropdown which contains a LiveComponent inside.
I already use Alpine 3 and it works as I expect things to work, but when I test your patch, then the LiveCompoent disappears:
Enregistrement.de.l.ecran.2024-10-15.a.13.08.00.mov
Is there a bug somewhere, or is it the good behavior but I did something wrong in my app?
Thanks!
Hi, My current test setup uses a reversed logic; an alpine element inside of a LiveComponent. The morph is necessary to keep the alpine state when a LiveComponent re-renders with DOM changes. But as your video shows there might be an issue with LiveComponents inside an Alpine element. Oddly enough I also tested this and did not see any weird behaviour. Both with an alpine component surrounding a LiveComponent as well as sharing the same DOM element. Could you share more details about how your setup is structured in Twig? That said, this shows the PR has a breaking change and it should not be merged (yet). |
This PR fixes live component compatibility for Alpine v3.
Currently, the live component controller already implements the Alpine morph plugin. This works fine for Alpine v2, but since v3, the
__x
property is no longer used by Alpine. Instead, we can check for_x_dataStack
.Also, the morph plugin no longer requires the
__x
property; the DOM element should be used instead.I made sure the changes support both Alpine v2 and v3.
Original implementation and issue:
onBeforeElUpdated
callback - Alpine.JS compatibility #984