@@ -102,6 +102,8 @@ export const transformElement: NodeTransform = (node, context) => {
102102 let vnodeDynamicProps : VNodeCall [ 'dynamicProps' ]
103103 let dynamicPropNames : string [ ] | undefined
104104 let vnodeDirectives : VNodeCall [ 'directives' ]
105+ let needsPatch = false
106+ let isBlockRequired = false
105107
106108 let shouldUseBlock =
107109 // dynamic component may resolve to plain elements
@@ -127,6 +129,8 @@ export const transformElement: NodeTransform = (node, context) => {
127129 vnodeProps = propsBuildResult . props
128130 patchFlag = propsBuildResult . patchFlag
129131 dynamicPropNames = propsBuildResult . dynamicPropNames
132+ needsPatch = propsBuildResult . needsPatch
133+ isBlockRequired = propsBuildResult . isBlockRequired
130134 const directives = propsBuildResult . directives
131135 vnodeDirectives =
132136 directives && directives . length
@@ -206,7 +210,7 @@ export const transformElement: NodeTransform = (node, context) => {
206210 vnodeDynamicProps = stringifyDynamicPropNames ( dynamicPropNames )
207211 }
208212
209- node . codegenNode = createVNodeCall (
213+ const vnodeCall = ( node . codegenNode = createVNodeCall (
210214 context ,
211215 vnodeTag ,
212216 vnodeProps ,
@@ -218,7 +222,15 @@ export const transformElement: NodeTransform = (node, context) => {
218222 false /* disableTracking */ ,
219223 isComponent ,
220224 node . loc ,
221- )
225+ ) )
226+ needsPatch =
227+ needsPatch && ( patchFlag === 0 || patchFlag === PatchFlags . NEED_HYDRATION )
228+ if ( needsPatch ) {
229+ vnodeCall . needsPatch = true
230+ }
231+ if ( isBlockRequired ) {
232+ vnodeCall . isBlockRequired = true
233+ }
222234 }
223235}
224236
@@ -382,13 +394,16 @@ export function buildProps(
382394 patchFlag : number
383395 dynamicPropNames : string [ ]
384396 shouldUseBlock : boolean
397+ needsPatch : boolean
398+ isBlockRequired : boolean
385399} {
386400 const { tag, loc : elementLoc , children } = node
387401 let properties : ObjectExpression [ 'properties' ] = [ ]
388402 const mergeArgs : PropsExpression [ ] = [ ]
389403 const runtimeDirectives : DirectiveNode [ ] = [ ]
390404 const hasChildren = children . length > 0
391405 let shouldUseBlock = false
406+ let isBlockRequired = false
392407
393408 // patchFlag analysis
394409 let patchFlag = 0
@@ -444,6 +459,10 @@ export function buildProps(
444459 hasVnodeHook = true
445460 }
446461
462+ if ( name === 'ref' ) {
463+ hasRef = true
464+ }
465+
447466 if ( isEventHandler && value . type === NodeTypes . JS_CALL_EXPRESSION ) {
448467 // handler wrapped with internal helper e.g. withModifiers(fn)
449468 // extract the actual expression
@@ -460,13 +479,15 @@ export function buildProps(
460479 return
461480 }
462481
463- if ( name === 'ref' ) {
464- hasRef = true
465- } else if ( name === 'class' ) {
482+ if ( name === 'class' ) {
466483 hasClassBinding = true
467484 } else if ( name === 'style' ) {
468485 hasStyleBinding = true
469- } else if ( name !== 'key' && ! dynamicPropNames . includes ( name ) ) {
486+ } else if (
487+ name !== 'ref' &&
488+ name !== 'key' &&
489+ ! dynamicPropNames . includes ( name )
490+ ) {
470491 dynamicPropNames . push ( name )
471492 }
472493
@@ -573,14 +594,21 @@ export function buildProps(
573594 continue
574595 }
575596
597+ // #938: elements with dynamic keys should be forced into blocks
598+ if ( isVBind && isStaticArgOf ( arg , 'key' ) ) {
599+ shouldUseBlock = true
600+ }
601+ // inline before-update hooks need to remain blocks so that they are
602+ // invoked before children
576603 if (
577- // #938: elements with dynamic keys should be forced into blocks
578- ( isVBind && isStaticArgOf ( arg , 'key' ) ) ||
579- // inline before-update hooks need to force block so that it is invoked
580- // before children
581- ( isVOn && hasChildren && isStaticArgOf ( arg , 'vue:before-update' ) )
604+ isVOn &&
605+ hasChildren &&
606+ arg &&
607+ isStaticExp ( arg ) &&
608+ camelize ( arg . content ) === 'vue:beforeUpdate'
582609 ) {
583610 shouldUseBlock = true
611+ isBlockRequired = true
584612 }
585613
586614 if ( isVBind && isStaticArgOf ( arg , 'ref' ) ) {
@@ -691,6 +719,7 @@ export function buildProps(
691719 // to ensure before-update gets called before children update
692720 if ( hasChildren ) {
693721 shouldUseBlock = true
722+ isBlockRequired = true
694723 }
695724 }
696725 }
@@ -736,11 +765,10 @@ export function buildProps(
736765 patchFlag |= PatchFlags . NEED_HYDRATION
737766 }
738767 }
739- if (
740- ! shouldUseBlock &&
768+ const needsPatch =
741769 ( patchFlag === 0 || patchFlag === PatchFlags . NEED_HYDRATION ) &&
742770 ( hasRef || hasVnodeHook || runtimeDirectives . length > 0 )
743- ) {
771+ if ( ! shouldUseBlock && needsPatch ) {
744772 patchFlag |= PatchFlags . NEED_PATCH
745773 }
746774
@@ -825,6 +853,8 @@ export function buildProps(
825853 patchFlag,
826854 dynamicPropNames,
827855 shouldUseBlock,
856+ needsPatch,
857+ isBlockRequired,
828858 }
829859}
830860
0 commit comments