File tree 1 file changed +15
-0
lines changed
1 file changed +15
-0
lines changed Original file line number Diff line number Diff line change @@ -299,6 +299,21 @@ const patchInsertBefore = (HostElementPrototype: HTMLElement) => {
299
299
} ) ;
300
300
if ( found ) return newChild ;
301
301
}
302
+
303
+ /**
304
+ * Fixes an issue where slotted elements are dynamically relocated in React, such as after data fetch.
305
+ *
306
+ * When a slotted element is passed to another scoped component (e.g., <A><C slot="header"/></A>),
307
+ * the child’s __parentNode (original parent node property) does not match this.
308
+ *
309
+ * To prevent errors, this checks if the current child's parent node differs from this.
310
+ * If so, appendChild(newChild) is called to ensure the child is correctly inserted,
311
+ * allowing Stencil to properly manage the slot placement.
312
+ */
313
+ const parentNode = ( currentChild as d . PatchedSlotNode ) ?. __parentNode ;
314
+ if ( parentNode && ! this . isSameNode ( parentNode ) ) {
315
+ return this . appendChild ( newChild ) ;
316
+ }
302
317
return ( this as d . RenderNode ) . __insertBefore ( newChild , currentChild ) ;
303
318
} ;
304
319
} ;
You can’t perform that action at this time.
0 commit comments