fix(custom-element): prevent parse slot when custom elemnt move in DOM #13164
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Bug Report: Component Disappears When Moved in DOM Using Custom Element with Slot
Description
I'm using a Custom Element to wrap a Vue component that includes a
slot
. In this setup,shadowRoot
is set tofalse
.The issue I'm encountering is that when I move this element within the DOM — either by dragging it or using
appendChild
to insert it elsewhere — thedisconnectedCallback
is triggered.Inside the
disconnectedCallback
,nextTick
is used. However, beforenextTick
gets a chance to execute, theconnectedCallback
is triggered again. As a result,_parseSlots
is called before the component is fully re-initialized, and allchildNodes
inside the element are removed. This causes the component to suddenly disappear from the DOM.Temporary Fix
To resolve this issue, I added a check to ensure
_instance
is notnull
before calling_parseSlots
. This workaround prevents the unexpected removal of slot content.Reproduction
If needed, I can provide a minimal reproduction of the problem.
Environment
shadowRoot: false
Expected Behavior
Moving the component in the DOM should not cause it to lose its slotted children or disappear.
Actual Behavior
Slotted content is removed when the component is reconnected before
nextTick
executes.Let me know if a repro is needed — I’d be happy to provide one.