@@ -4,10 +4,15 @@ import {
4
4
currentInstance ,
5
5
} from './component'
6
6
import { type Block , setupComponent } from './apiRender'
7
- import type { NormalizedRawProps , RawProps } from './componentProps'
7
+ import {
8
+ type NormalizedRawProps ,
9
+ type RawProps ,
10
+ normalizeRawProps ,
11
+ walkRawProps ,
12
+ } from './componentProps'
8
13
import type { DynamicSlots , Slots } from './componentSlots'
9
- import { walkRawProps , withAttrs } from './componentAttrs'
10
- import { isArray , isString } from '@vue/shared'
14
+ import { withAttrs } from './componentAttrs'
15
+ import { isString } from '@vue/shared'
11
16
import { renderEffect } from './renderEffect'
12
17
import { normalizeBlock } from './dom/element'
13
18
import { setDynamicProp } from './dom/prop'
@@ -21,40 +26,9 @@ export function createComponent(
21
26
once : boolean = false ,
22
27
) {
23
28
if ( isString ( comp ) ) {
24
- // eslint-disable-next-line no-restricted-globals
25
- const el = document . createElement ( comp )
26
-
27
- if ( rawProps ) {
28
- if ( ! isArray ( rawProps ) ) rawProps = [ rawProps ]
29
- renderEffect ( ( ) => {
30
- walkRawProps ( rawProps as NormalizedRawProps , ( key , value , getter ) => {
31
- setDynamicProp ( el , key , getter ? value ( ) : value )
32
- } )
33
- } )
34
- }
35
-
36
- if ( ( dynamicSlots && dynamicSlots . length ) || ( slots && slots . default ) ) {
37
- renderEffect ( ( ) => {
38
- let block : Block | undefined
39
-
40
- if ( slots && slots . default ) {
41
- block = slots . default ( )
42
- } else {
43
- for ( const slotFn of dynamicSlots ! ) {
44
- const slot = slotFn ( )
45
- if ( slot . name === 'default' ) {
46
- block = slot . fn ( )
47
- break
48
- }
49
- }
50
- }
51
-
52
- if ( block ) el . append ( ...normalizeBlock ( block ) )
53
- } )
54
- }
55
-
56
- return el
29
+ return fallbackComponent ( comp , rawProps , slots , dynamicSlots , singleRoot )
57
30
}
31
+
58
32
const current = currentInstance !
59
33
const instance = createComponentInstance (
60
34
comp ,
@@ -70,3 +44,44 @@ export function createComponent(
70
44
71
45
return instance
72
46
}
47
+
48
+ function fallbackComponent (
49
+ comp : string ,
50
+ rawProps : RawProps | null = null ,
51
+ slots : Slots | null = null ,
52
+ dynamicSlots : DynamicSlots | null = null ,
53
+ singleRoot : boolean = false ,
54
+ ) {
55
+ // eslint-disable-next-line no-restricted-globals
56
+ const el = document . createElement ( comp )
57
+
58
+ if ( rawProps ) {
59
+ rawProps = normalizeRawProps ( rawProps )
60
+ renderEffect ( ( ) => {
61
+ walkRawProps ( rawProps as NormalizedRawProps , ( key , value , getter ) => {
62
+ setDynamicProp ( el , key , getter ? value ( ) : value )
63
+ } )
64
+ } )
65
+ }
66
+
67
+ if ( ( dynamicSlots && dynamicSlots . length ) || ( slots && slots . default ) ) {
68
+ renderEffect ( ( ) => {
69
+ let block : Block | undefined
70
+
71
+ if ( slots && slots . default ) {
72
+ block = slots . default ( )
73
+ } else {
74
+ for ( const slotFn of dynamicSlots ! ) {
75
+ const slot = slotFn ( )
76
+ if ( slot . name === 'default' ) {
77
+ block = slot . fn ( )
78
+ break
79
+ }
80
+ }
81
+ }
82
+
83
+ if ( block ) el . append ( ...normalizeBlock ( block ) )
84
+ } )
85
+ }
86
+ return { __return : el , rawProps }
87
+ }
0 commit comments