Replies: 15 comments
-
Looking at it at first sight, can you try to not use <div x-data="{show: false}">
<button x-on:click="show = true">Show input</button>
<input x-show="show" type="text" wire:model="value">
</div> |
Beta Was this translation helpful? Give feedback.
-
Thanks! I tried it but it did not change the behavior. The example is over-simplified. The input element in a real app would be wrapped inside a modal. Without |
Beta Was this translation helpful? Give feedback.
-
maybe you should have a look at this. Sounds like related to or <input type="text" wire:model.lazy="value"> |
Beta Was this translation helpful? Give feedback.
-
I think it's a Livewire bug (I believe the Alpine integration lives in that repository). If you try this snippet
You can see that I don't think x-cloak makes much difference here. |
Beta Was this translation helpful? Give feedback.
-
Okay, it turned up that it might be more complicate than that. Livewire, when updating its component, walks the old dom and clones the old Alpine components into the new ones. The clone function in Alpine does clone: function clone(component, newEl) {
if (!newEl.__x) {
newEl.__x = new Component(newEl, component.getUnobservedData());
}
}, In that snippet. Livewire knows that he need to clone
This happens sequentially and it does the parent first: when Alpine initialises the parent, because it finds a x-data in one of their children, it also initialise the nested component using the original data in your html then it tries to clone the child component but, because the component has already been initialised, it skips this phase. Changing clone to clone: function clone(component, newEl) {
newEl.__x = new Component(newEl, component.getUnobservedData());
}, seems to fix the issue but I'm not familiar with the integration so I don't know if it would break something else. cc. @calebporzio |
Beta Was this translation helpful? Give feedback.
-
Thanks for diving into this! You are right. |
Beta Was this translation helpful? Give feedback.
-
I might be missing something here, but do you not just need to add |
Beta Was this translation helpful? Give feedback.
-
Then you wouldn't be able to use |
Beta Was this translation helpful? Give feedback.
-
Wouldn't |
Beta Was this translation helpful? Give feedback.
-
Not for me because it's the same element. A datepicker in a modal. |
Beta Was this translation helpful? Give feedback.
-
I've got the same issue with x-cloak and livewire component. button:
Component ('left-menu')
|
Beta Was this translation helpful? Give feedback.
-
Any solution to prehide elements? |
Beta Was this translation helpful? Give feedback.
-
I have the same behaviour with Phoenix LiveView. It's not related to What @SimoTod suggested actually works for me. |
Beta Was this translation helpful? Give feedback.
-
@ssbb can you post a snippet for LiveView? 🙏 |
Beta Was this translation helpful? Give feedback.
-
@RxAssim I am just forked Alpine repo and did this changes. |
Beta Was this translation helpful? Give feedback.
-
I was not sure wether this belongs on the Alpine or Livewire repository. If this is not the right place I will happily move it over.
I have been building a comment section using Alpine and Livewire and am really impressed. There is just one challenge which has been keeping me busy for 2 days now. Users should be able to edit comments using a modal. However, the modal disappeared the moment Livewire processed the input.
After hours trying to get to the core of the problem this is where I left.
In this example, I expect the input element to persist which is the case when you remove the nesting or the x-cloak attribute. It would be great if anyone sees a connection. I am really curious to understand what's going on.
Beta Was this translation helpful? Give feedback.
All reactions