currentInstance,
isInSSRComponentSetup,
setCurrentInstance,
- unsetCurrentInstance,
} from './component'
import type { ComponentPublicInstance } from './componentPublicInstance'
import { ErrorTypeStrings, callWithAsyncErrorHandling } from './errorHandling'
// Set currentInstance during hook invocation.
// This assumes the hook does not synchronously trigger other hooks, which
// can only be false when the user does something really funky.
- setCurrentInstance(target)
+ const reset = setCurrentInstance(target)
const res = callWithAsyncErrorHandling(hook, target, type, args)
- unsetCurrentInstance()
+ reset()
resetTracking()
return res
})
currentInstance,
isInSSRComponentSetup,
setCurrentInstance,
- unsetCurrentInstance,
} from './component'
import {
ErrorCodes,
cb = value.handler as Function
options = value
}
- const cur = currentInstance
- setCurrentInstance(this)
+ const reset = setCurrentInstance(this)
const res = doWatch(getter, cb.bind(publicThis), options)
- if (cur) {
- setCurrentInstance(cur)
- } else {
- unsetCurrentInstance()
- }
+ reset()
return res
}
}
export const setCurrentInstance = (instance: ComponentInternalInstance) => {
+ const prev = currentInstance
internalSetCurrentInstance(instance)
instance.scope.on()
+ return () => {
+ instance.scope.off()
+ internalSetCurrentInstance(prev)
+ }
}
export const unsetCurrentInstance = () => {
const setupContext = (instance.setupContext =
setup.length > 1 ? createSetupContext(instance) : null)
- setCurrentInstance(instance)
+ const reset = setCurrentInstance(instance)
pauseTracking()
const setupResult = callWithErrorHandling(
setup,
],
)
resetTracking()
- unsetCurrentInstance()
+ reset()
if (isPromise(setupResult)) {
setupResult.then(unsetCurrentInstance, unsetCurrentInstance)
// support for 2.x options
if (__FEATURE_OPTIONS_API__ && !(__COMPAT__ && skipOptions)) {
- setCurrentInstance(instance)
+ const reset = setCurrentInstance(instance)
pauseTracking()
try {
applyOptions(instance)
} finally {
resetTracking()
- unsetCurrentInstance()
+ reset()
}
}
type ConcreteComponent,
type Data,
setCurrentInstance,
- unsetCurrentInstance,
} from './component'
import { isEmitListener } from './componentEmits'
import { InternalObjectKey } from './vnode'
if (key in propsDefaults) {
value = propsDefaults[key]
} else {
- setCurrentInstance(instance)
+ const reset = setCurrentInstance(instance)
value = propsDefaults[key] = defaultValue.call(
__COMPAT__ &&
isCompatEnabled(DeprecationTypes.PROPS_DEFAULT_THIS, instance)
: null,
props,
)
- unsetCurrentInstance()
+ reset()
}
} else {
value = defaultValue