@@ -74,7 +74,7 @@ export class DynamicFragment extends VaporFragment {
74
74
75
75
update ( render ?: BlockFn , key : any = render ) : void {
76
76
if ( key === this . current ) {
77
- if ( isHydrating ) this . hydrate ( this . anchorLabel ! , true )
77
+ if ( isHydrating && this . anchorLabel ) this . hydrate ( this . anchorLabel ! , true )
78
78
return
79
79
}
80
80
this . current = key
@@ -155,30 +155,33 @@ export class DynamicFragment extends VaporFragment {
155
155
}
156
156
157
157
hydrate ( label : string , isEmpty : boolean = false ) : void {
158
- if ( ! label && isEmpty ) return
159
-
160
- // for `v-if="false"` the node will be an empty comment, use it as the anchor.
158
+ // for `v-if="false"`, the node will be an empty comment, use it as the anchor.
161
159
// otherwise, find next sibling vapor fragment anchor
162
160
if ( label === 'if' && isEmpty ) {
163
161
this . anchor = locateVaporFragmentAnchor ( currentHydrationNode ! , '' ) !
164
162
} else {
165
- let anchor = locateVaporFragmentAnchor ( currentHydrationNode ! , label ) !
166
- if ( ! anchor ) {
167
- // TODO: comment anchors are not included in ssr slot vnode fallback
163
+ this . anchor = locateVaporFragmentAnchor ( currentHydrationNode ! , label ) !
164
+ if ( ! this . anchor ) {
165
+ // comment anchors are not included in ssr slot vnode fallback
168
166
if ( label === 'slot' ) {
169
167
// fallback to fragment end anchor for
170
- anchor = locateVaporFragmentAnchor ( currentHydrationNode ! , ']' ) !
171
- } else if ( label === 'if' ) {
168
+ this . anchor = locateVaporFragmentAnchor ( currentHydrationNode ! , ']' ) !
169
+ } else {
170
+ // create anchor
171
+ const { parentNode, nextSibling } = currentHydrationNode !
172
+ parentNode ! . insertBefore (
173
+ ( this . anchor = __DEV__ ? createComment ( label ) : createTextNode ( ) ) ,
174
+ nextSibling ,
175
+ )
172
176
}
173
177
}
174
- if ( anchor ) {
175
- this . anchor = anchor
176
- } else if ( __DEV__ ) {
177
- // this should not happen
178
- throw new Error ( `${ label } fragment anchor node was not found.` )
179
- }
180
178
}
181
- advanceHydrationNode ( this . anchor )
179
+
180
+ if ( this . anchor ) {
181
+ advanceHydrationNode ( this . anchor )
182
+ } else if ( __DEV__ ) {
183
+ throw new Error ( `${ label } fragment anchor node was not found.` )
184
+ }
182
185
}
183
186
}
184
187
0 commit comments