@@ -227,20 +227,18 @@ export function createHydrationFunctions(
227
227
optimized
228
228
)
229
229
230
- // component may be async, so in the case of fragments we cannot rely
231
- // on component's rendered output to determine the end of the fragment
232
- // instead, we do a lookahead to find the end anchor node.
233
- nextNode = isFragmentStart
234
- ? locateClosingAsyncAnchor ( node )
235
- : nextSibling ( node )
236
-
237
- // #4293 teleport as component root
238
- if (
239
- nextNode &&
240
- isComment ( nextNode ) &&
241
- nextNode . data === 'teleport end'
242
- ) {
243
- nextNode = nextSibling ( nextNode )
230
+ // Locate the next node.
231
+ if ( isFragmentStart ) {
232
+ // If it's a fragment: since components may be async, we cannot rely
233
+ // on component's rendered output to determine the end of the
234
+ // fragment. Instead, we do a lookahead to find the end anchor node.
235
+ nextNode = locateClosingAnchor ( node )
236
+ } else if ( isComment ( node ) && node . data === 'teleport start' ) {
237
+ // #4293 #6152
238
+ // If a teleport is at component root, look ahead for teleport end.
239
+ nextNode = locateClosingAnchor ( node , node . data , 'teleport end' )
240
+ } else {
241
+ nextNode = nextSibling ( node )
244
242
}
245
243
246
244
// #3787
@@ -533,7 +531,7 @@ export function createHydrationFunctions(
533
531
534
532
if ( isFragment ) {
535
533
// remove excessive fragment nodes
536
- const end = locateClosingAsyncAnchor ( node )
534
+ const end = locateClosingAnchor ( node )
537
535
while ( true ) {
538
536
const next = nextSibling ( node )
539
537
if ( next && next !== end ) {
@@ -561,13 +559,18 @@ export function createHydrationFunctions(
561
559
return next
562
560
}
563
561
564
- const locateClosingAsyncAnchor = ( node : Node | null ) : Node | null => {
562
+ // looks ahead for a start and closing comment node
563
+ const locateClosingAnchor = (
564
+ node : Node | null ,
565
+ open = '[' ,
566
+ close = ']'
567
+ ) : Node | null => {
565
568
let match = 0
566
569
while ( node ) {
567
570
node = nextSibling ( node )
568
571
if ( node && isComment ( node ) ) {
569
- if ( node . data === '[' ) match ++
570
- if ( node . data === ']' ) {
572
+ if ( node . data === open ) match ++
573
+ if ( node . data === close ) {
571
574
if ( match === 0 ) {
572
575
return nextSibling ( node )
573
576
} else {
0 commit comments