@@ -76,7 +76,6 @@ import {
76
76
import { createHydrationFunctions , RootHydrateFunction } from './hydration'
77
77
import { invokeDirectiveHook } from './directives'
78
78
import { startMeasure , endMeasure } from './profiling'
79
- import { ComponentPublicInstance } from './componentPublicInstance'
80
79
import {
81
80
devtoolsComponentAdded ,
82
81
devtoolsComponentRemoved ,
@@ -87,6 +86,7 @@ import { initFeatureFlags } from './featureFlags'
87
86
import { isAsyncWrapper } from './apiAsyncComponent'
88
87
import { isCompatEnabled } from './compat/compatConfig'
89
88
import { DeprecationTypes } from './compat/compatConfig'
89
+ import { registerLegacyRef } from './compat/ref'
90
90
91
91
export interface Renderer < HostElement = RendererElement > {
92
92
render : RootRenderFunction < HostElement >
@@ -309,34 +309,34 @@ export const setRef = (
309
309
rawRef : VNodeNormalizedRef ,
310
310
oldRawRef : VNodeNormalizedRef | null ,
311
311
parentSuspense : SuspenseBoundary | null ,
312
- vnode : VNode | null
312
+ vnode : VNode ,
313
+ isUnmount = false
313
314
) => {
314
315
if ( isArray ( rawRef ) ) {
315
316
rawRef . forEach ( ( r , i ) =>
316
317
setRef (
317
318
r ,
318
319
oldRawRef && ( isArray ( oldRawRef ) ? oldRawRef [ i ] : oldRawRef ) ,
319
320
parentSuspense ,
320
- vnode
321
+ vnode ,
322
+ isUnmount
321
323
)
322
324
)
323
325
return
324
326
}
325
327
326
- let value : ComponentPublicInstance | RendererNode | Record < string , any > | null
327
- if ( ! vnode ) {
328
- // means unmount
329
- value = null
330
- } else if ( isAsyncWrapper ( vnode ) ) {
328
+ if ( isAsyncWrapper ( vnode ) && ! isUnmount ) {
331
329
// when mounting async components, nothing needs to be done,
332
330
// because the template ref is forwarded to inner component
333
331
return
334
- } else if ( vnode . shapeFlag & ShapeFlags . STATEFUL_COMPONENT ) {
335
- value = vnode . component ! . exposed || vnode . component ! . proxy
336
- } else {
337
- value = vnode . el
338
332
}
339
333
334
+ const refValue =
335
+ vnode . shapeFlag & ShapeFlags . STATEFUL_COMPONENT
336
+ ? vnode . component ! . exposed || vnode . component ! . proxy
337
+ : vnode . el
338
+ const value = isUnmount ? null : refValue
339
+
340
340
const { i : owner , r : ref } = rawRef
341
341
if ( __DEV__ && ! owner ) {
342
342
warn (
@@ -349,7 +349,7 @@ export const setRef = (
349
349
const refs = owner . refs === EMPTY_OBJ ? ( owner . refs = { } ) : owner . refs
350
350
const setupState = owner . setupState
351
351
352
- // unset old ref
352
+ // dynamic ref changed. unset old ref
353
353
if ( oldRef != null && oldRef !== ref ) {
354
354
if ( isString ( oldRef ) ) {
355
355
refs [ oldRef ] = null
@@ -363,7 +363,11 @@ export const setRef = (
363
363
364
364
if ( isString ( ref ) ) {
365
365
const doSet = ( ) => {
366
- refs [ ref ] = value
366
+ if ( __COMPAT__ && isCompatEnabled ( DeprecationTypes . V_FOR_REF , owner ) ) {
367
+ registerLegacyRef ( refs , ref , refValue , owner , rawRef . f , isUnmount )
368
+ } else {
369
+ refs [ ref ] = value
370
+ }
367
371
if ( hasOwn ( setupState , ref ) ) {
368
372
setupState [ ref ] = value
369
373
}
@@ -584,7 +588,7 @@ function baseCreateRenderer(
584
588
585
589
// set ref
586
590
if ( ref != null && parentComponent ) {
587
- setRef ( ref , n1 && n1 . ref , parentSuspense , n2 )
591
+ setRef ( ref , n1 && n1 . ref , parentSuspense , n2 || n1 , ! n2 )
588
592
}
589
593
}
590
594
@@ -2113,7 +2117,7 @@ function baseCreateRenderer(
2113
2117
} = vnode
2114
2118
// unset ref
2115
2119
if ( ref != null ) {
2116
- setRef ( ref , null , parentSuspense , null )
2120
+ setRef ( ref , null , parentSuspense , vnode , true )
2117
2121
}
2118
2122
2119
2123
if ( shapeFlag & ShapeFlags . COMPONENT_SHOULD_KEEP_ALIVE ) {
0 commit comments