File tree 2 files changed +69
-0
lines changed
2 files changed +69
-0
lines changed Original file line number Diff line number Diff line change @@ -332,4 +332,65 @@ describe('hot module replacement', () => {
332
332
rerender ( last . __hmrId ! , compileToFunction ( `<Parent class="test"/>` ) )
333
333
expect ( serializeInner ( root ) ) . toBe ( `<div class="test">child</div>` )
334
334
} )
335
+
336
+ // #3302
337
+ test ( 'rerender with Teleport' , ( ) => {
338
+ const root = nodeOps . createElement ( 'div' )
339
+ const target = nodeOps . createElement ( 'div' )
340
+ const parentId = 'parent-teleport'
341
+
342
+ const Child : ComponentOptions = {
343
+ data ( ) {
344
+ return {
345
+ // style is used to ensure that the div tag will be tracked by Teleport
346
+ style : { } ,
347
+ target
348
+ }
349
+ } ,
350
+ render : compileToFunction ( `
351
+ <teleport :to="target">
352
+ <div :style="style">
353
+ <slot/>
354
+ </div>
355
+ </teleport>
356
+ ` )
357
+ }
358
+
359
+ const Parent : ComponentOptions = {
360
+ __hmrId : parentId ,
361
+ components : { Child } ,
362
+ render : compileToFunction ( `
363
+ <Child>
364
+ <template #default>
365
+ <div>1</div>
366
+ </template>
367
+ </Child>
368
+ ` )
369
+ }
370
+ createRecord ( parentId , Parent )
371
+
372
+ render ( h ( Parent ) , root )
373
+ expect ( serializeInner ( root ) ) . toBe (
374
+ `<!--teleport start--><!--teleport end-->`
375
+ )
376
+ expect ( serializeInner ( target ) ) . toBe ( `<div style={}><div>1</div></div>` )
377
+
378
+ rerender (
379
+ parentId ,
380
+ compileToFunction ( `
381
+ <Child>
382
+ <template #default>
383
+ <div>1</div>
384
+ <div>2</div>
385
+ </template>
386
+ </Child>
387
+ ` )
388
+ )
389
+ expect ( serializeInner ( root ) ) . toBe (
390
+ `<!--teleport start--><!--teleport end-->`
391
+ )
392
+ expect ( serializeInner ( target ) ) . toBe (
393
+ `<div style={}><div>1</div><div>2</div></div>`
394
+ )
395
+ } )
335
396
} )
Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ import {
11
11
import { VNode , VNodeArrayChildren , VNodeProps } from '../vnode'
12
12
import { isString , ShapeFlags } from '@vue/shared'
13
13
import { warn } from '../warning'
14
+ import { isHmrUpdating } from '../hmr'
14
15
15
16
export type TeleportVNode = VNode < RendererNode , RendererElement , TeleportProps >
16
17
@@ -85,6 +86,13 @@ export const TeleportImpl = {
85
86
const disabled = isTeleportDisabled ( n2 . props )
86
87
const { shapeFlag, children } = n2
87
88
89
+ // #3302
90
+ // HMR updated, force full diff
91
+ if ( __DEV__ && isHmrUpdating ) {
92
+ optimized = false
93
+ n2 . dynamicChildren = null
94
+ }
95
+
88
96
if ( n1 == null ) {
89
97
// insert anchors in the main view
90
98
const placeholder = ( n2 . el = __DEV__
You can’t perform that action at this time.
0 commit comments