|
|
@@ -1,9 +1,15 @@
|
|
|
import { resolveDynamicComponent } from '@vue/runtime-dom'
|
|
|
-import { DynamicFragment, type VaporFragment } from './block'
|
|
|
+import { DynamicFragment, type VaporFragment, insert } from './block'
|
|
|
import { createComponentWithFallback } from './component'
|
|
|
import { renderEffect } from './renderEffect'
|
|
|
import type { RawProps } from './componentProps'
|
|
|
import type { RawSlots } from './componentSlots'
|
|
|
+import {
|
|
|
+ insertionAnchor,
|
|
|
+ insertionParent,
|
|
|
+ resetInsertionState,
|
|
|
+} from './insertionState'
|
|
|
+import { isHydrating, locateHydrationNode } from './dom/hydration'
|
|
|
|
|
|
export function createDynamicComponent(
|
|
|
getter: () => any,
|
|
|
@@ -11,9 +17,18 @@ export function createDynamicComponent(
|
|
|
rawSlots?: RawSlots | null,
|
|
|
isSingleRoot?: boolean,
|
|
|
): VaporFragment {
|
|
|
+ const _insertionParent = insertionParent
|
|
|
+ const _insertionAnchor = insertionAnchor
|
|
|
+ if (isHydrating) {
|
|
|
+ locateHydrationNode()
|
|
|
+ } else {
|
|
|
+ resetInsertionState()
|
|
|
+ }
|
|
|
+
|
|
|
const frag = __DEV__
|
|
|
? new DynamicFragment('dynamic-component')
|
|
|
: new DynamicFragment()
|
|
|
+
|
|
|
renderEffect(() => {
|
|
|
const value = getter()
|
|
|
frag.update(
|
|
|
@@ -27,5 +42,10 @@ export function createDynamicComponent(
|
|
|
value,
|
|
|
)
|
|
|
})
|
|
|
+
|
|
|
+ if (!isHydrating && _insertionParent) {
|
|
|
+ insert(frag, _insertionParent, _insertionAnchor)
|
|
|
+ }
|
|
|
+
|
|
|
return frag
|
|
|
}
|