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

Morph key lookup issue #3658

Merged
merged 1 commit into from Jul 24, 2023

Conversation

joshhanley
Copy link
Collaborator

This PR fixes an issue with morph, where if the key already exists in the DOM and is to be moved up during morph, it wasn't getting moved correctly.

The reason was, that fromKeyDomNodeMap was empty, so the fromKeyNode in the below snippet was always empty, so the move "from" key was never running.

let fromKeyNode = fromKeyDomNodeMap[toKey]
if (fromKeyNode) {
// Move "from" key...
fromKeyHoldovers[fromKey] = currentFrom
fromChildren = dom.replace(fromChildren, currentFrom, fromKeyNode)
currentFrom = fromKeyNode

Removing the commented out keyToMap(fromChildren) got it working, but then caused an infinite loop. This was due to dom.replace() replacing the old with the new, but leaving the new one in its place in the array, causing two references to the dom node. So then when any dom.() methods run and try to find the index of the node, there would be two of them but only the first was ever returned. I opted to update dom.replace() but this could also be done in the above from key move code.

This fixes livewire/next#99

There is a failing test directives/x-bind-style.spec.js but running those tests locally they pass, so I believe it's unrelated.

Hope this helps!

@joshhanley
Copy link
Collaborator Author

Turns out the failing x-bind-style tests are due to the formatting in the test file. Someone has already submitted a PR to fix #3631

@calebporzio calebporzio merged commit c3c8f26 into alpinejs:main Jul 24, 2023
1 check failed
@joshhanley joshhanley deleted the josh/morph-key-lookup-issue branch April 24, 2024 10:26
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

2 participants