File tree Expand file tree Collapse file tree 3 files changed +20
-0
lines changed
packages/compiler-vapor/src Expand file tree Collapse file tree 3 files changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -55,6 +55,12 @@ export function genBlockContent(
5555 push ( ...genOperations ( operation , context ) )
5656 push ( ...genEffects ( effect , context ) )
5757
58+ if ( dynamic . needsKey ) {
59+ for ( const child of dynamic . children ) {
60+ push ( NEWLINE , `n${ child . id } .key = ${ JSON . stringify ( child . id ) } ` )
61+ }
62+ }
63+
5864 push ( NEWLINE , `return ` )
5965
6066 const returnNodes = returns . map ( n => `n${ n } ` )
Original file line number Diff line number Diff line change @@ -259,6 +259,7 @@ export interface IRDynamicInfo {
259259 children : IRDynamicInfo [ ]
260260 template ?: number
261261 hasDynamicChild ?: boolean
262+ needsKey ?: boolean
262263}
263264
264265export interface IREffect {
Original file line number Diff line number Diff line change 11import {
22 type ElementNode ,
33 ErrorCodes ,
4+ NodeTypes ,
45 createCompilerError ,
56 createSimpleExpression ,
67} from '@vue/compiler-dom'
@@ -123,5 +124,17 @@ export function createIfBranch(
123124 const branch : BlockIRNode = newBlock ( node )
124125 const exitBlock = context . enterBlock ( branch )
125126 context . reference ( )
127+ // generate key for branch result when it's in transition
128+ // the key will be used to cache node at runtime
129+ branch . dynamic . needsKey = isInTransition ( context )
126130 return [ branch , exitBlock ]
127131}
132+
133+ function isInTransition ( context : TransformContext < ElementNode > ) : boolean {
134+ const parentNode = context . parent && context . parent . node
135+ return ! ! (
136+ parentNode &&
137+ parentNode . type === NodeTypes . ELEMENT &&
138+ ( parentNode . tag === 'transition' || parentNode . tag === 'Transition' )
139+ )
140+ }
You can’t perform that action at this time.
0 commit comments