Skip to content

Destroy components inside a removed plain element - #4956

Open
Yahiro025 wants to merge 1 commit into
alpinejs:mainfrom
Yahiro025:fix-removed-wrapper-cleanup
Open

Yahiro025 wants to merge 1 commit into
alpinejs:mainfrom
Yahiro025:fix-removed-wrapper-cleanup

Conversation

@Yahiro025

@Yahiro025 Yahiro025 commented Dec 1, 2026 •

Copy link
Copy Markdown

When Alpine starts, it only initializes the matched root elements, so a plain wrapper around a component never gets an _x_marker. If that wrapper is removed, the mutation observer skipped it entirely and the component's listeners and effects kept running on the detached subtree.

The removed-node check now also accepts a wrapper that contains an initialized descendant. Nodes with no Alpine state still return early, so the fast path for untouched DOM is unchanged. An element that morph replaces is marked and skipped, which keeps the detached old tree reactive as it was before.

tests/vitest/mutation-cleanup.spec.js removes such a wrapper and asserts the component is destroyed. It fails on main.

Fixes #4951

@Yahiro025
Yahiro025 force-pushed the fix-removed-wrapper-cleanup branch from d056c00 to 1c3e479 Compare December 1, 2026 07:40

This branch has not been deployed

No deployments
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.

Components inside a removed element with no Alpine directive are never cleaned up

1 participant