@@ -13,11 +13,12 @@ import { isAsyncWrapper } from './apiAsyncComponent'
1313import { warn } from './warning'
1414import { isRef , toRaw } from '@vue/reactivity'
1515import { ErrorCodes , callWithErrorHandling } from './errorHandling'
16- import type { SchedulerJob } from './scheduler'
16+ import { type SchedulerJob , SchedulerJobFlags } from './scheduler'
1717import { queuePostRenderEffect } from './renderer'
1818import { type ComponentOptions , getComponentPublicInstance } from './component'
1919import { knownTemplateRefs } from './helpers/useTemplateRef'
2020
21+ const pendingSetRef = new WeakMap < VNode , SchedulerJob > ( )
2122/**
2223 * Function for handling a template ref
2324 */
@@ -153,13 +154,12 @@ export function setRef(
153154 // #1789: for non-null values, set them after render
154155 // null values means this is unmount and it should not overwrite another
155156 // ref with the same key
156- const job : SchedulerJob = ( ) => {
157- if ( ! ( vnode as any ) . __isUnmounting ) doSet ( )
158- }
159- job . id = - 1
160- queuePostRenderEffect ( job , parentSuspense )
157+ ; ( doSet as SchedulerJob ) . id = - 1
158+ pendingSetRef . set ( vnode , doSet )
159+ queuePostRenderEffect ( doSet , parentSuspense )
161160 } else {
162- ; ( vnode as any ) . __isUnmounting = true
161+ const pendingSet = pendingSetRef . get ( vnode )
162+ if ( pendingSet ) pendingSet . flags ! |= SchedulerJobFlags . DISPOSED
163163 doSet ( )
164164 }
165165 } else if ( __DEV__ ) {
0 commit comments