Repository navigation
Conversation
Alpine.morph() clones every element it patches. On the clone, x-modelable still queued its entangle microtask, which ran after cloneNode() had returned and so registered a real effect against the live component's data. That effect copied the outer value back over any inner change made in the meantime, and since the clone is thrown away without cleanup, one entanglement leaked per morph. Wrap the directive in skipDuringClone() like x-init, x-effect and x-on. Fixes alpinejs#4928
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #4928.
Alpine.morph()clones every element it patches withAlpine.cloneNode(). On the clone,x-modelalready skips its listener, butx-modelablestill queues its entangle microtask. That microtask runs aftercloneNode()has returned, when effects are real again, so the clone ends up with a live entanglement over the live component's data (the clone shares its data stack).This causes two problems:
The fix wraps the
x-modelabledirective inskipDuringClone(), the same asx-init,x-effect,x-on,x-forandx-if(as @tevinch also suggested in the issue). The clone is only used to seed the morph, so it doesn't need a binding of its own.Tests: two new Cypress tests in
morph.spec.js. One checks that a change made right after a morph is kept; the other checks that changing the value after five morphs reads the outer model the same number of times as before morphing. Both fail without the change.Replaces #4929, which got closed when my fork was accidentally detached.