File tree Expand file tree Collapse file tree 2 files changed +45
-9
lines changed Expand file tree Collapse file tree 2 files changed +45
-9
lines changed Original file line number Diff line number Diff line change @@ -1083,5 +1083,29 @@ describe('SSR hydration', () => {
1083
1083
expect ( teleportContainer . innerHTML ) . toBe ( `<span>value</span>` )
1084
1084
expect ( `Hydration children mismatch` ) . toHaveBeenWarned ( )
1085
1085
} )
1086
+ // #6152
1087
+ test ( 'Teleport is disabled' , ( ) => {
1088
+ const { container } = mountWithHydration (
1089
+ '<!--[--><div>Parent fragment</div><!--teleport start--><div>Teleport content</div><!--teleport end--><!--]-->' ,
1090
+ ( ) => [
1091
+ h ( 'div' , 'Parent fragment' ) ,
1092
+ h (
1093
+ defineComponent (
1094
+ ( ) => ( ) =>
1095
+ h ( Teleport , { to : 'body' , disabled : true } , [
1096
+ h ( 'div' , 'Teleport content' )
1097
+ ] )
1098
+ )
1099
+ )
1100
+ ]
1101
+ )
1102
+ expect ( document . body . innerHTML ) . toBe ( '' )
1103
+ expect ( container . innerHTML ) . toBe (
1104
+ '<!--[--><div>Parent fragment</div><!--teleport start--><div>Teleport content</div><!--teleport end--><!--]-->'
1105
+ )
1106
+ expect (
1107
+ `Hydration completed but contains mismatches.`
1108
+ ) . not . toHaveBeenWarned ( )
1109
+ } )
1086
1110
} )
1087
1111
} )
Original file line number Diff line number Diff line change @@ -232,17 +232,11 @@ export function createHydrationFunctions(
232
232
// instead, we do a lookahead to find the end anchor node.
233
233
nextNode = isFragmentStart
234
234
? locateClosingAsyncAnchor ( node )
235
+ : // #4293 #6152 if teleport start look ahead for teleport end.
236
+ isComment ( node ) && node . data === 'teleport start'
237
+ ? locateClosingTeleportAnchor ( node )
235
238
: nextSibling ( node )
236
239
237
- // #4293 teleport as component root
238
- if (
239
- nextNode &&
240
- isComment ( nextNode ) &&
241
- nextNode . data === 'teleport end'
242
- ) {
243
- nextNode = nextSibling ( nextNode )
244
- }
245
-
246
240
// #3787
247
241
// if component is async, it may get moved / unmounted before its
248
242
// inner component is loaded, so we need to give it a placeholder
@@ -579,5 +573,23 @@ export function createHydrationFunctions(
579
573
return node
580
574
}
581
575
576
+ const locateClosingTeleportAnchor = ( node : Node | null ) : Node | null => {
577
+ let match = 0
578
+ while ( node ) {
579
+ node = nextSibling ( node )
580
+ if ( node && isComment ( node ) ) {
581
+ if ( node . data === 'teleport start' ) match ++
582
+ if ( node . data === 'teleport end' ) {
583
+ if ( match === 0 ) {
584
+ return nextSibling ( node )
585
+ } else {
586
+ match --
587
+ }
588
+ }
589
+ }
590
+ }
591
+ return node
592
+ }
593
+
582
594
return [ hydrate , hydrateNode ] as const
583
595
}
You can’t perform that action at this time.
0 commit comments