@@ -73,38 +73,53 @@ export class DynamicFragment extends VaporFragment {
73
73
}
74
74
75
75
if ( this . fallback ) {
76
- parent && remove ( this . nodes , parent )
77
- const scope = this . scope || ( this . scope = new EffectScope ( ) )
78
- scope . run ( ( ) => {
79
- // handle nested fragment
80
- if ( isFragment ( this . nodes ) ) {
81
- ensureFallback ( this . nodes , this . fallback ! )
82
- } else if ( ! isValidBlock ( this . nodes ) ) {
83
- this . nodes = this . fallback ! ( ) || [ ]
84
- }
85
- } )
86
-
87
- parent && insert ( this . nodes , parent , this . anchor )
76
+ // set fallback for nested fragments
77
+ const isFrag = isFragment ( this . nodes )
78
+ if ( isFrag ) {
79
+ setFragmentFallback ( this . nodes as VaporFragment , this . fallback )
80
+ }
81
+
82
+ if ( ! isValidBlock ( this . nodes ) ) {
83
+ parent && remove ( this . nodes , parent )
84
+ const scope = this . scope || ( this . scope = new EffectScope ( ) )
85
+ scope . run ( ( ) => {
86
+ if ( isFrag ) {
87
+ // render fragment's fallback
88
+ renderFragmentFallback ( this . nodes as VaporFragment )
89
+ } else {
90
+ this . nodes = this . fallback ! ( ) || [ ]
91
+ }
92
+ } )
93
+ parent && insert ( this . nodes , parent , this . anchor )
94
+ }
88
95
}
89
96
90
97
setActiveSub ( prevSub )
91
98
}
92
99
}
93
100
94
- function ensureFallback ( fragment : VaporFragment , fallback : BlockFn ) : void {
95
- if ( ! fragment . fallback ) fragment . fallback = fallback
101
+ function setFragmentFallback (
102
+ fragment : VaporFragment ,
103
+ fallback : BlockFn | undefined ,
104
+ ) : void {
105
+ if ( ! fragment . fallback ) {
106
+ fragment . fallback = fallback
107
+ }
108
+ if ( isFragment ( fragment . nodes ) ) {
109
+ setFragmentFallback ( fragment . nodes , fallback )
110
+ }
111
+ }
96
112
97
- if ( fragment instanceof DynamicFragment ) {
113
+ function renderFragmentFallback ( fragment : VaporFragment ) : void {
114
+ if ( fragment instanceof ForFragment ) {
115
+ fragment . nodes [ 0 ] = [ fragment . fallback ! ( ) || [ ] ] as Block [ ]
116
+ } else if ( fragment instanceof DynamicFragment ) {
98
117
const nodes = fragment . nodes
99
118
if ( isFragment ( nodes ) ) {
100
- ensureFallback ( nodes , fallback )
101
- } else if ( ! isValidBlock ( nodes ) ) {
119
+ renderFragmentFallback ( nodes )
120
+ } else {
102
121
fragment . update ( fragment . fallback )
103
122
}
104
- } else if ( fragment instanceof ForFragment ) {
105
- if ( ! isValidBlock ( fragment . nodes [ 0 ] ) ) {
106
- fragment . nodes [ 0 ] = [ fallback ( ) || [ ] ] as Block [ ]
107
- }
108
123
} else {
109
124
// vdom slots
110
125
}
0 commit comments