@@ -202,7 +202,7 @@ describe('SSR hydration', () => {
202
202
const fn = jest . fn ( )
203
203
const teleportContainer = document . createElement ( 'div' )
204
204
teleportContainer . id = 'teleport'
205
- teleportContainer . innerHTML = `<span>foo</span><span class="foo"></span><!---->`
205
+ teleportContainer . innerHTML = `<span>foo</span><span class="foo"></span><!--teleport anchor -->`
206
206
document . body . appendChild ( teleportContainer )
207
207
208
208
const { vnode, container } = mountWithHydration (
@@ -233,7 +233,7 @@ describe('SSR hydration', () => {
233
233
msg . value = 'bar'
234
234
await nextTick ( )
235
235
expect ( teleportContainer . innerHTML ) . toBe (
236
- `<span>bar</span><span class="bar"></span><!---->`
236
+ `<span>bar</span><span class="bar"></span><!--teleport anchor -->`
237
237
)
238
238
} )
239
239
@@ -263,7 +263,7 @@ describe('SSR hydration', () => {
263
263
264
264
const teleportHtml = ctx . teleports ! [ '#teleport2' ]
265
265
expect ( teleportHtml ) . toMatchInlineSnapshot (
266
- `"<span>foo</span><span class=\\"foo\\"></span><!----><span>foo2</span><span class=\\"foo2\\"></span><!---->"`
266
+ `"<span>foo</span><span class=\\"foo\\"></span><!--teleport anchor --><span>foo2</span><span class=\\"foo2\\"></span><!--teleport anchor -->"`
267
267
)
268
268
269
269
teleportContainer . innerHTML = teleportHtml
@@ -300,7 +300,7 @@ describe('SSR hydration', () => {
300
300
msg . value = 'bar'
301
301
await nextTick ( )
302
302
expect ( teleportContainer . innerHTML ) . toMatchInlineSnapshot (
303
- `"<span>bar</span><span class=\\"bar\\"></span><!----><span>bar2</span><span class=\\"bar2\\"></span><!---->"`
303
+ `"<span>bar</span><span class=\\"bar\\"></span><!--teleport anchor --><span>bar2</span><span class=\\"bar2\\"></span><!--teleport anchor -->"`
304
304
)
305
305
} )
306
306
@@ -327,7 +327,7 @@ describe('SSR hydration', () => {
327
327
)
328
328
329
329
const teleportHtml = ctx . teleports ! [ '#teleport3' ]
330
- expect ( teleportHtml ) . toMatchInlineSnapshot ( `"<!---->"` )
330
+ expect ( teleportHtml ) . toMatchInlineSnapshot ( `"<!--teleport anchor -->"` )
331
331
332
332
teleportContainer . innerHTML = teleportHtml
333
333
document . body . appendChild ( teleportContainer )
@@ -369,7 +369,7 @@ describe('SSR hydration', () => {
369
369
test ( 'Teleport (as component root)' , ( ) => {
370
370
const teleportContainer = document . createElement ( 'div' )
371
371
teleportContainer . id = 'teleport4'
372
- teleportContainer . innerHTML = `hello<!---->`
372
+ teleportContainer . innerHTML = `hello<!--teleport anchor -->`
373
373
document . body . appendChild ( teleportContainer )
374
374
375
375
const wrapper = {
@@ -395,6 +395,38 @@ describe('SSR hydration', () => {
395
395
expect ( nextVNode . el ) . toBe ( container . firstChild ?. lastChild )
396
396
} )
397
397
398
+ test ( 'Teleport (nested)' , ( ) => {
399
+ const teleportContainer = document . createElement ( 'div' )
400
+ teleportContainer . id = 'teleport5'
401
+ teleportContainer . innerHTML = `<div><!--teleport start--><!--teleport end--></div><!--teleport anchor--><div>child</div><!--teleport anchor-->`
402
+ document . body . appendChild ( teleportContainer )
403
+
404
+ const { vnode, container } = mountWithHydration (
405
+ '<!--teleport start--><!--teleport end-->' ,
406
+ ( ) =>
407
+ h ( Teleport , { to : '#teleport5' } , [
408
+ h ( 'div' , [ h ( Teleport , { to : '#teleport5' } , [ h ( 'div' , 'child' ) ] ) ] )
409
+ ] )
410
+ )
411
+
412
+ expect ( vnode . el ) . toBe ( container . firstChild )
413
+ expect ( vnode . anchor ) . toBe ( container . lastChild )
414
+
415
+ const childDivVNode = ( vnode as any ) . children [ 0 ]
416
+ const div = teleportContainer . firstChild
417
+ expect ( childDivVNode . el ) . toBe ( div )
418
+ expect ( vnode . targetAnchor ) . toBe ( div ?. nextSibling )
419
+
420
+ const childTeleportVNode = childDivVNode . children [ 0 ]
421
+ expect ( childTeleportVNode . el ) . toBe ( div ?. firstChild )
422
+ expect ( childTeleportVNode . anchor ) . toBe ( div ?. lastChild )
423
+
424
+ expect ( childTeleportVNode . targetAnchor ) . toBe ( teleportContainer . lastChild )
425
+ expect ( childTeleportVNode . children [ 0 ] . el ) . toBe (
426
+ teleportContainer . lastChild ?. previousSibling
427
+ )
428
+ } )
429
+
398
430
// compile SSR + client render fn from the same template & hydrate
399
431
test ( 'full compiler integration' , async ( ) => {
400
432
const mounted : string [ ] = [ ]
0 commit comments