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

fix: already init component #3951

Merged
merged 6 commits into from
Jan 21, 2024
Merged

Conversation

Matsa59
Copy link
Contributor

@Matsa59 Matsa59 commented Dec 27, 2023

Currently we defined if a mutation is a move operation if the node is in the addedNodes and in the removedNodes.

However in some case, an element is added, removed and added again. So it should considered as add + move operations. But alpine will ignore it, considering it as a move operation only (so nothing will be init).

The PR focus on introducing a new state _x_isInit that will be true for component that are initialized.

Also it may speed up a little bit the onMutate function. Previously we checked every deleted nodes before adding any new nodes. For big mutations, iterate over the deletedNodes several times could be CPU intensive.

Conversation on : #3947

Copy link
Contributor

@ekwoka ekwoka left a comment

Choose a reason for hiding this comment

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

Should probably handle tracking initialization tracking in the initialization process, not the mutation process.

@Matsa59 Matsa59 force-pushed the main branch 3 times, most recently from 036254c to 8a3ba01 Compare January 3, 2024 15:39
The only way to apply this on the node is to execute it on the
mutation. Otherwise, we have to rewrite a big part of the lifecycle
system.
@Matsa59 Matsa59 marked this pull request as draft January 19, 2024 19:44
@Matsa59 Matsa59 marked this pull request as ready for review January 19, 2024 20:15
@Matsa59
Copy link
Contributor Author

Matsa59 commented Jan 19, 2024

FINALLY I found a way to make it works ... waiting for CI to be sure

Thx @ekwoka for your time and help, really appreciated

@calebporzio calebporzio merged commit c68aba0 into alpinejs:main Jan 21, 2024
1 check passed
@calebporzio
Copy link
Collaborator

Thanks! I do think the implementation is a little heavy handed. I instead just changed the addedNodes and removedNodes to JS Sets instead of arrays so that they enforce uniqueness in the case of duplicate addeds and removes. Thanks!

@ekwoka
Copy link
Contributor

ekwoka commented Jan 22, 2024

Does that solve the actual issue this is meant to solve?

It still will incorrectly consider an element that is added and immediately moved as being a "moved" element and never initialize it, which was the issue.

@Matsa59
Copy link
Contributor Author

Matsa59 commented Jan 22, 2024

Thanks! I do think the implementation is a little heavy handed. I instead just changed the addedNodes and removedNodes to JS Sets instead of arrays so that they enforce uniqueness in the case of duplicate addeds and removes. Thanks!

It was my first though but it was more complex and didn't fix well the issue :/

@SimoTod
Copy link
Collaborator

SimoTod commented Jan 24, 2024

@Matsa59 I think this change caused #3994

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants