@@ -193,25 +193,40 @@ describe('renderer: VaporTeleport', () => {
193
193
194
194
const { component : Child } = define ( {
195
195
__hmrId : childId ,
196
- render ( ) {
197
- return template ( '<div>teleported</div>' ) ( )
196
+ setup ( ) {
197
+ const msg = ref ( 'teleported' )
198
+ return { msg }
199
+ } ,
200
+ render ( ctx ) {
201
+ const n0 = template ( `<div> </div>` ) ( )
202
+ const x0 = child ( n0 as any )
203
+ renderEffect ( ( ) => setText ( x0 as any , ctx . msg ) )
204
+ return [ n0 ]
198
205
} ,
199
206
} )
200
207
createRecord ( childId , Child as any )
201
208
202
209
const { mount, component : Parent } = define ( {
203
210
__hmrId : parentId ,
204
- render ( ) {
211
+ setup ( ) {
212
+ const msg = ref ( 'root' )
213
+ const disabled = ref ( false )
214
+ return { msg, disabled }
215
+ } ,
216
+ render ( ctx ) {
205
217
const n0 = createComp (
206
218
VaporTeleport ,
207
219
{
208
220
to : ( ) => target ,
221
+ disabled : ( ) => ctx . disabled ,
209
222
} ,
210
223
{
211
224
default : ( ) => createComp ( Child ) ,
212
225
} ,
213
226
)
214
- const n1 = template ( '<div>root</div>' ) ( )
227
+ const n1 = template ( `<div> </div>` ) ( )
228
+ const x0 = child ( n1 as any )
229
+ renderEffect ( ( ) => setText ( x0 as any , ctx . msg ) )
215
230
return [ n0 , n1 ]
216
231
} ,
217
232
} ) . create ( )
@@ -221,38 +236,187 @@ describe('renderer: VaporTeleport', () => {
221
236
expect ( root . innerHTML ) . toBe ( '<!--teleport--><div>root</div>' )
222
237
expect ( target . innerHTML ) . toBe ( '<div>teleported</div>' )
223
238
224
- // reload child
239
+ // reload child by changing msg
225
240
reload ( childId , {
226
241
__hmrId : childId ,
227
242
__vapor : true ,
228
- render ( ) {
229
- return template ( '<div>teleported 2</div>' ) ( )
243
+ setup ( ) {
244
+ const msg = ref ( 'teleported 2' )
245
+ return { msg }
246
+ } ,
247
+ render ( ctx : any ) {
248
+ const n0 = template ( `<div> </div>` ) ( )
249
+ const x0 = child ( n0 as any )
250
+ renderEffect ( ( ) => setText ( x0 as any , ctx . msg ) )
251
+ return [ n0 ]
230
252
} ,
231
253
} )
232
254
expect ( root . innerHTML ) . toBe ( '<!--teleport--><div>root</div>' )
233
255
expect ( target . innerHTML ) . toBe ( '<div>teleported 2</div>' )
234
256
235
- // reload parent
257
+ // reload parent by changing msg
236
258
reload ( parentId , {
237
259
__hmrId : parentId ,
238
260
__vapor : true ,
239
- render ( ) {
261
+ setup ( ) {
262
+ const msg = ref ( 'root 2' )
263
+ const disabled = ref ( false )
264
+ return { msg, disabled }
265
+ } ,
266
+ render ( ctx : any ) {
240
267
const n0 = createComp (
241
268
VaporTeleport ,
242
269
{
243
270
to : ( ) => target ,
271
+ disabled : ( ) => ctx . disabled ,
244
272
} ,
245
273
{
246
274
default : ( ) => createComp ( Child ) ,
247
275
} ,
248
276
)
249
- const n1 = template ( '<div>root 2</div>' ) ( )
277
+ const n1 = template ( `<div> </div>` ) ( )
278
+ const x0 = child ( n1 as any )
279
+ renderEffect ( ( ) => setText ( x0 as any , ctx . msg ) )
250
280
return [ n0 , n1 ]
251
281
} ,
252
282
} )
253
283
254
284
expect ( root . innerHTML ) . toBe ( '<!--teleport--><div>root 2</div>' )
255
285
expect ( target . innerHTML ) . toBe ( '<div>teleported 2</div>' )
286
+
287
+ // reload parent again by changing disabled
288
+ reload ( parentId , {
289
+ __hmrId : parentId ,
290
+ __vapor : true ,
291
+ setup ( ) {
292
+ const msg = ref ( 'root 2' )
293
+ const disabled = ref ( true )
294
+ return { msg, disabled }
295
+ } ,
296
+ render ( ctx : any ) {
297
+ const n0 = createComp (
298
+ VaporTeleport ,
299
+ {
300
+ to : ( ) => target ,
301
+ disabled : ( ) => ctx . disabled ,
302
+ } ,
303
+ {
304
+ default : ( ) => createComp ( Child ) ,
305
+ } ,
306
+ )
307
+ const n1 = template ( `<div> </div>` ) ( )
308
+ const x0 = child ( n1 as any )
309
+ renderEffect ( ( ) => setText ( x0 as any , ctx . msg ) )
310
+ return [ n0 , n1 ]
311
+ } ,
312
+ } )
313
+
314
+ expect ( root . innerHTML ) . toBe (
315
+ '<div>teleported 2</div><!--teleport--><div>root 2</div>' ,
316
+ )
317
+ expect ( target . innerHTML ) . toBe ( '' )
318
+ } )
319
+
320
+ test . todo ( 'reload child + toggle disabled' , async ( ) => {
321
+ const target = document . createElement ( 'div' )
322
+ const root = document . createElement ( 'div' )
323
+ const childId = 'test3-child'
324
+ const parentId = 'test3-parent'
325
+
326
+ const disabled = ref ( true )
327
+ const { component : Child } = define ( {
328
+ __hmrId : childId ,
329
+ setup ( ) {
330
+ const msg = ref ( 'teleported' )
331
+ return { msg }
332
+ } ,
333
+ render ( ctx ) {
334
+ const n0 = template ( `<div> </div>` ) ( )
335
+ const x0 = child ( n0 as any )
336
+ renderEffect ( ( ) => setText ( x0 as any , ctx . msg ) )
337
+ return [ n0 ]
338
+ } ,
339
+ } )
340
+ createRecord ( childId , Child as any )
341
+
342
+ const { mount, component : Parent } = define ( {
343
+ __hmrId : parentId ,
344
+ setup ( ) {
345
+ const msg = ref ( 'root' )
346
+ return { msg, disabled }
347
+ } ,
348
+ render ( ctx ) {
349
+ const n0 = createComp (
350
+ VaporTeleport ,
351
+ {
352
+ to : ( ) => target ,
353
+ disabled : ( ) => ctx . disabled ,
354
+ } ,
355
+ {
356
+ default : ( ) => createComp ( Child ) ,
357
+ } ,
358
+ )
359
+ const n1 = template ( `<div> </div>` ) ( )
360
+ const x0 = child ( n1 as any )
361
+ renderEffect ( ( ) => setText ( x0 as any , ctx . msg ) )
362
+ return [ n0 , n1 ]
363
+ } ,
364
+ } ) . create ( )
365
+ createRecord ( parentId , Parent as any )
366
+ mount ( root )
367
+
368
+ expect ( root . innerHTML ) . toBe (
369
+ '<div>teleported</div><!--teleport--><div>root</div>' ,
370
+ )
371
+ expect ( target . innerHTML ) . toBe ( '' )
372
+
373
+ // reload child by changing msg
374
+ reload ( childId , {
375
+ __hmrId : childId ,
376
+ __vapor : true ,
377
+ setup ( ) {
378
+ const msg = ref ( 'teleported 2' )
379
+ return { msg }
380
+ } ,
381
+ render ( ctx : any ) {
382
+ const n0 = template ( `<div> </div>` ) ( )
383
+ const x0 = child ( n0 as any )
384
+ renderEffect ( ( ) => setText ( x0 as any , ctx . msg ) )
385
+ return [ n0 ]
386
+ } ,
387
+ } )
388
+ expect ( root . innerHTML ) . toBe (
389
+ '<div>teleported 2</div><!--teleport--><div>root</div>' ,
390
+ )
391
+ expect ( target . innerHTML ) . toBe ( '' )
392
+
393
+ // reload child again by changing msg
394
+ reload ( childId , {
395
+ __hmrId : childId ,
396
+ __vapor : true ,
397
+ setup ( ) {
398
+ const msg = ref ( 'teleported 3' )
399
+ return { msg }
400
+ } ,
401
+ render ( ctx : any ) {
402
+ const n0 = template ( `<div> </div>` ) ( )
403
+ const x0 = child ( n0 as any )
404
+ renderEffect ( ( ) => setText ( x0 as any , ctx . msg ) )
405
+ return [ n0 ]
406
+ } ,
407
+ } )
408
+ expect ( root . innerHTML ) . toBe (
409
+ '<div>teleported 3</div><!--teleport--><div>root</div>' ,
410
+ )
411
+ expect ( target . innerHTML ) . toBe ( '' )
412
+
413
+ //bug: child reload not update teleport fragment's nodes
414
+
415
+ // toggle disabled
416
+ disabled . value = false
417
+ await nextTick ( )
418
+ expect ( root . innerHTML ) . toBe ( '<!--teleport--><div>root</div>' )
419
+ expect ( target . innerHTML ) . toBe ( '<div>teleported 3</div>' )
256
420
} )
257
421
} )
258
422
} )
0 commit comments