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

Bug - Multiple morph calls clash #2772

Merged
merged 4 commits into from
Mar 21, 2022

Conversation

SimoTod
Copy link
Collaborator

@SimoTod SimoTod commented Mar 20, 2022

When running Alpine.morph() immediately after another Alpine.morph() call, because they are async, they run in a pseudo-concurrent way. Due to the use of global variables, the second run overrides the first one altering the result of the first morph call, see https://codepen.io/SimoTod/pen/vYpKmVZ (expecting 1-2 but getting 2-2).

To make sure that variables are not shared I moved them and most of the functions inside the morph function itself. It could probably be refactored to be a class but I didn't want to make the review more complicated so I changed as little as possible (git is already a bit rubbish at showing this kind of diff, it's probably easier to pull the file locally and compare it with the current version with a split editor).

@calebporzio
Copy link
Collaborator

Thanks for this @SimoTod - what you did is good as-is I think. I pulled it down to double check like you said because git's diff is garbage in this case. Thanks!

@calebporzio calebporzio merged commit c214602 into alpinejs:main Mar 21, 2022
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.

2 participants