-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
feat: Update lifecycle and mutation #4000
Conversation
Did my move to Sets not fix this? |
The first try was to update the mutation system. Then the code has been changed and to update the lifecycle system. You've updated an old piece of code and I guess you force push it or something like that (so it eras the code ghat was merged) |
@calebporzio The sets would only fix an issue of Alpine trying to initialize the element twice. The concern in the original PR was that the element had both an add and a remove, but had never actually been initialized. Alpine treated it as a "move" and not an "add", and thus just ignored it. |
@Matsa59 Can you add a test to verify this works correctly? Ideally first make it not work (without your changes) and then validate your changes against it. |
Ah, I see. Thanks for the clarification @ekwoka. I'm slightly hesitant to pull this in for some reason - maybe I'd prefer more of that code to live in the mutation handler? Idk. It feels simple right now, and adding this check for an inited property doesn't feel right. Any opinions here? Any other ways to tackle this that we're not thinking of? Also, yes tests would be great. Thanks. |
The goal is to support "add reorder" that happen in the same mutation.
@ekwoka test has been added, I used the same code as |
Plus updating the lifecycle system may increase Alpine speed. Currently (on main) the check if its a "move" operation, iterate on every deleted nodes for every inserted nodes. This could have a significant impact on performance. |
Well, with the other recent change of using But yes, this should be a bit quicker. |
Ok sure, I'll do another branch next time. However on your tweaks you have some mistakes. You didn't rename every "_x_isInit" |
Haha good catch - yeah I see the failure and am working on it! |
@PhiloNL is experiencing issues due to this PR - see this issue on his repo wire-elements/modal#423 Waiting to see if we can reproduce it in a smaller testcase. |
It seems Alpine is no longer picking up any changes that happen after the initial render (using Livewire v2, in this example). For example: <?php
class Component extends Component
{
public $ready = false;
} <div x-data="{
select() {
console.log(this.$refs.resultGroups);
}
}"
wire:init="$set('ready', true)">
@if($ready)
<div x-ref="resultGroups">
<div class="wep-spotlight-group">
<ul x-ref="results">
<li @click="select" x-data>
Contacts
</li>
<li @click="select" x-data>
Billing
</li>
<li @click="select" x-data>
Docs
</li>
</ul>
</div>
</div>
@endif
</div> Click any of the If you set |
If you add @calebporzio I'm not sure reverting a PR that fixed another bug is a nice patch edit: hum I guess the problem comes from Technically, the x-data form the parent is been init, so IMO it's not the problem of AlpineJS. Or the A fix that should work: <div x-data="{
resultGroups: nil,
select() {
console.log(this.resultGroups);
}
}"
wire:init="$set('ready', true)">
@if($ready)
<div x-data x-init="resultGroups = $el">
<div class="wep-spotlight-group">
<ul x-ref="results">
<li @click="select" x-data>
Contacts
</li>
<li @click="select" x-data>
Billing
</li>
<li @click="select" x-data>
Docs
</li>
</ul>
</div>
</div>
@endif
</div> you could also use (or something like that, you get the idea, i didn't test it) |
Thanks! But that would still be a breaking change for every Livewire v2 app out there that uses Alpine v3. So it would likely affect thousands of users. It would be great if no changes were required by the end-user. |
The goal is to support "add reorder" that happen in the same mutation.
Original PR: #3951 (that was revert because it introduced a bug)