Skip to content

Fix: skip init() in x-data during clone, matching x-init behavior - #4901

Merged
calebporzio merged 2 commits into
alpinejs:mainfrom
MaxencePaulin:fix/x-data-init-runs-during-clone
Sep 14, 2026
Merged

Fix: skip init() in x-data during clone, matching x-init behavior#4901
calebporzio merged 2 commits into
alpinejs:mainfrom
MaxencePaulin:fix/x-data-init-runs-during-clone

Conversation

@MaxencePaulin

Copy link
Copy Markdown
Contributor

Problem

x-data's init() method runs during Alpine.morph()'s internal clone pass, unlike x-init which is correctly skipped. This causes init() to fire twice when a patch adds x-data to a node that didn't have it before.

Solution

Wrap the init() call in x-data.js with the same skipDuringClone() already used by x-init.js.

Tests

Adds a regression test in morph.spec.js covering the double-init.

Fixes #4900

@calebporzio
calebporzio merged commit 636c78c into alpinejs:main Sep 14, 2026
1 check passed
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.

x-data's init() runs twice when morph() patches an existing node to add x-data

2 participants