-
-
Notifications
You must be signed in to change notification settings - Fork 357
[LiveComponent] Twig + AlpineJS x-data x-show #2683
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
Comments
A small clarification that might be important. When I load the page, x-show works correctly. However, after the first data-poll call, the DOM reloads and x-show stops working. Curiously, if I close the page (without reloading it) using the features (which still work) and the data-poll is called again, I no longer have this problem. |
I would not mix two JS framework on the same div to be honest. The DOM changes are the main feature of LiveComponent, so we won't be able to do much on that. If you have any idea / solutions we could look at, but this does not look like a bug on LiveComponent side, did you open an issue / looked for support on the Alpine one ? |
Hi ! I’ve changed my approach. Instead of using AlpineJS in a TwigLiveComponent, I opted for a Stimulus controller to manage my dropdown menu For now, I haven’t found another solution, but I agree with you on this point. The issue probably doesn’t come from AlpineJS or TwigLiveComponent The compatibility of both within the same DOM doesn’t seem to be a good practice |
Just by chance, did you try <div class="relative" {{ attributes }} data-poll>
<div x-data="{ notificationDropdown: false }">
<button @click="notificationDropdown = !notificationDropdown">
Open
</button>
<div x-show="false" x-cloak @click.away="notificationDropdown = false">
CONTENT
</div>
</div>
</div> ? |
A random ID on the element with your x-data should force Alpine.js to perform a fresh render (re-render) ;) |
Hello,
I am encountering an issue with a
TwigLiveComponent
that integratesAlpineJS
and adata-poll
. Here’s an explanation of the problem:Here is a code snippet:
The problem is that during the first
data-poll
, theCONTENT
is displayed even though I haven’t clicked on the element. It works correctly for other AlpineJS elements that are not affected by aTwigLiveComponent
. However, every time the DOM is rendered, theCONTENT
appears as if the variable is set to true or as if thex-show
attribute is being ignored.Here’s what I’ve tried to solve the issue:
I also tried modifying the code like this:
I thought the notificationDropdown variable was causing the problem, but even after changing the first
data-poll
, theCONTENT
still displays.I am using
AlpineJS
version3.14.9
andSymfony UX
version2.24
(including Twig, etc.).I haven’t found a viable solution. Maybe I am trying to do something impossible or I am doing it wrong. I think the issue comes from the DOM changing with the first data-poll. I had already encountered this issue with a form managed by TwigLiveComponent, and I eventually gave up on that approach. However, I am determined to make this dropdown display method work.
Could you help me?
Thank you.
The text was updated successfully, but these errors were encountered: