@@ -231,10 +231,10 @@ export function createHydrationFunctions(
231
231
// on component's rendered output to determine the end of the fragment
232
232
// instead, we do a lookahead to find the end anchor node.
233
233
nextNode = isFragmentStart
234
- ? locateClosingAsyncAnchor ( node )
234
+ ? locateClosingAnchor ( node , '[' , ']' )
235
235
: // #4293 #6152 if teleport start look ahead for teleport end.
236
236
isComment ( node ) && node . data === 'teleport start'
237
- ? locateClosingTeleportAnchor ( node )
237
+ ? locateClosingAnchor ( node , 'teleport start' , 'teleport end' )
238
238
: nextSibling ( node )
239
239
240
240
// #3787
@@ -527,7 +527,7 @@ export function createHydrationFunctions(
527
527
528
528
if ( isFragment ) {
529
529
// remove excessive fragment nodes
530
- const end = locateClosingAsyncAnchor ( node )
530
+ const end = locateClosingAnchor ( node , '[' , ']' )
531
531
while ( true ) {
532
532
const next = nextSibling ( node )
533
533
if ( next && next !== end ) {
@@ -555,31 +555,18 @@ export function createHydrationFunctions(
555
555
return next
556
556
}
557
557
558
- const locateClosingAsyncAnchor = ( node : Node | null ) : Node | null => {
559
- let match = 0
560
- while ( node ) {
561
- node = nextSibling ( node )
562
- if ( node && isComment ( node ) ) {
563
- if ( node . data === '[' ) match ++
564
- if ( node . data === ']' ) {
565
- if ( match === 0 ) {
566
- return nextSibling ( node )
567
- } else {
568
- match --
569
- }
570
- }
571
- }
572
- }
573
- return node
574
- }
575
-
576
- const locateClosingTeleportAnchor = ( node : Node | null ) : Node | null => {
558
+ // looks ahead for a start and closing comment node
559
+ const locateClosingAnchor = (
560
+ node : Node | null ,
561
+ startData : string ,
562
+ endData : string
563
+ ) : Node | null => {
577
564
let match = 0
578
565
while ( node ) {
579
566
node = nextSibling ( node )
580
567
if ( node && isComment ( node ) ) {
581
- if ( node . data === 'teleport start' ) match ++
582
- if ( node . data === 'teleport end' ) {
568
+ if ( node . data === startData ) match ++
569
+ if ( node . data === endData ) {
583
570
if ( match === 0 ) {
584
571
return nextSibling ( node )
585
572
} else {
0 commit comments