Skip to content
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

Open
wants to merge 1 commit into
base: 2.x
Choose a base branch
from

Conversation

Kobo-one
Copy link

Q A
Bug fix? yes
New feature? no
Issues /
License MIT

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:

@carsonbot carsonbot added Bug Bug Fix LiveComponent Status: Needs Review Needs to be reviewed labels Oct 11, 2024
Copy link
Member

@Kocal Kocal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@carsonbot carsonbot added Status: Reviewed Has been reviewed by a maintainer and removed Status: Needs Review Needs to be reviewed labels Oct 11, 2024
@smnandre
Copy link
Member

Thank you @Kobo-one

Copy link
Member

@Kocal Kocal left a 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!

@carsonbot carsonbot added Status: Needs Work Additional work is needed and removed Status: Reviewed Has been reviewed by a maintainer labels Oct 15, 2024
@Kobo-one
Copy link
Author

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Bug Fix LiveComponent Status: Needs Work Additional work is needed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants