Scenario where components being injected into DOM can be initialized multiple times #2372
Unanswered
johndwells
asked this question in
5. Bugs
Replies: 1 comment
-
Definitely a bug, thanks for narrowing it down. I've raised #2376 to fix it. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I'm building an app with Unpoly & AlpineJS (I've done this a handful of times and it's always gone beautifully), and encountered a scenario where AlpineJS components were being initialized multiple times.
(Unpoly is a tool similar to HTMX, Intercooler, Hotwire etc. It fetches & injects server-rendered HTML into the DOM.)
I first raised it with the Unpoly community, and the framework's author presented a working code example to suggest there may be an issue with Alpine's mutation observer code:
^ unpoly/unpoly#314 (comment)
I dropped this code sample into a codepen to demonstrate, and I also added a 2nd block of code that avoided the duplicate initialization - by wrapping the 2nd element creation & insertion in a
setTimeout()
call (like a$nextTick
where we give the browser a chance to finish updating the DOM before carrying on with the 2nd element insertion):https://codepen.io/johndwells-the-decoder/pen/QWMVYRR
Any thoughts?
Beta Was this translation helpful? Give feedback.
All reactions