-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Fix: Remove element markers to allow reinitialization. #4509
base: main
Are you sure you want to change the base?
Conversation
This change removes the _x_marker system, which was previously used to track initialized elements and prevent double-initialization. By eliminating these markers: Elements can now be re-reinitialized if needed, rather than being skipped based on a prior state.
This fixes an issue I was having. |
I've created this PR to address an issue I encountered with Livewire and Alpine. The problem arises when Livewire dynamically renders a new view that contains an Alpine component. When this happens, the component doesn't initialize properly. However, if I refresh the page and the same view is rendered again, the component initializes as expected and behaves correctly. A possible reason for this issue is that I have a view (let's call it foo) that is rendered inside a FAQ accordion. When I click an FAQ item to expand it, Livewire re-renders the FAQ component, now including this item, which contains an Alpine component with a Flatpickr date picker input. When I click a second FAQ item, Livewire re-renders the component again, adding another item with the same foo view and another Flatpickr input for a different item. However, at this point, the new Flatpickr input no longer responds to clicks and doesn't display the calendar. Interestingly, since the server retains the state of the open FAQ item, refreshing the page correctly renders the item, and the Alpine component works flawlessly. |
That change was introduced not long ago to address another livewire bug. I don't particularly love it but just to let you know that it won't be easily reverted. It may be worth including an example to show the bug (can you recreate it in https://wirebox.app/). |
Well, it definitely should pass tests first... |
@wpoortman thanks for the PR! @SimoTod is correct, this was only just added to fix issues in Livewire, so it's not something we're going to remove without good justification for it. That being said though, if it's causing bugs, then we definitely want to investigate that to see if there might be another solution than just removing it. Can you please provide a detailed description of the issue and a code snippet that we can copy and paste into our own apps with steps to reproduce. Be sure to include any Blade variable definitions that are used and use a little code as possible to reproduce the issue. @ryanhissey if you are able to, can you also do the same with your bug, that would be great! Thanks! |
@joshhanley, thanks for taking the time to reply. I completely agree with you, and I would prefer a solution where a dynamic component could be flagged using something like a custom directive. The issue, however, is that this approach wouldn't be backwards compatible, and I see it as a potential breaking change. Is this the direction you'd like to proceed with? I believe many people will encounter this problem. I'll work on an example and provide more supporting code as soon as I can! |
This change removes the
_x_marker
system, which was previously used to track initialized elements and prevent double-initialization. By eliminating these markers elements can now be re-reinitialized if needed, rather than being skipped based on a prior state.