Issues with mutations and third party libs #2399
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Many third-party libraries (carousels, data tables) will remove portions of HTML and reinsert them wrapped into additional markup when initializing.
This behaviour triggers 2 mutations on the same tick:
Currently, since we always run added nodes first and removed nodes after,
1)
will always run last destroying event listeners and effects which means that components are no longer reactive.This PR proposes to swap the order so we always do removal first and addition after.
Before fix: https://github.com/SimoTod/alpine/runs/4270770739?check_suite_focus=true#step:6:900
After fix: https://github.com/SimoTod/alpine/runs/4210531827?check_suite_focus=true#step:6:900
This would introduce a regression if the mutations happened the other way around (not sure if it's a real use case)
Regression: https://github.com/SimoTod/alpine/runs/4210531827?check_suite_focus=true#step:6:900
but this will be prevented by main...SimoTod:bug/issue-with-mutations-and-third-party-libs#diff-84fd6cab30ac34eaf2c3376fe2e0ac7e1268a30d454cad78d402f6983edd4f4fR19
Another solution would be to respect the mutation order but this gets trickier if we want to skip elements that are removed and readded without additional markup. About this last point, I wonder if this is the desired behaviour though as you could do odd stuff like https://codepen.io/SimoTod/pen/mdMYKBG? (x-for uses
mutateDom
so it wouldn't be affected)? Happy to take the other approach if we think it's betterRelated to #2329, #2332, #1757 and probably many others