@@ -4,6 +4,7 @@ import type {
4
4
GenericComponentInstance ,
5
5
} from './component'
6
6
import { currentRenderingInstance } from './componentRenderContext'
7
+ import { type EffectScope , setCurrentScope } from '@vue/reactivity'
7
8
8
9
/**
9
10
* @internal
@@ -25,7 +26,10 @@ export let isInSSRComponentSetup = false
25
26
26
27
export let setInSSRSetupState : ( state : boolean ) => void
27
28
28
- let internalSetCurrentInstance : (
29
+ /**
30
+ * @internal
31
+ */
32
+ export let simpleSetCurrentInstance : (
29
33
instance : GenericComponentInstance | null ,
30
34
) => void
31
35
@@ -53,7 +57,7 @@ if (__SSR__) {
53
57
else setters [ 0 ] ( v )
54
58
}
55
59
}
56
- internalSetCurrentInstance = registerGlobalSetter (
60
+ simpleSetCurrentInstance = registerGlobalSetter (
57
61
`__VUE_INSTANCE_SETTERS__` ,
58
62
v => ( currentInstance = v ) ,
59
63
)
@@ -66,42 +70,22 @@ if (__SSR__) {
66
70
v => ( isInSSRComponentSetup = v ) ,
67
71
)
68
72
} else {
69
- internalSetCurrentInstance = i => {
73
+ simpleSetCurrentInstance = i => {
70
74
currentInstance = i
71
75
}
72
76
setInSSRSetupState = v => {
73
77
isInSSRComponentSetup = v
74
78
}
75
79
}
76
80
77
- export const setCurrentInstance = ( instance : GenericComponentInstance ) => {
81
+ export const setCurrentInstance = (
82
+ instance : GenericComponentInstance | null ,
83
+ scope : EffectScope | undefined = instance !== null
84
+ ? instance . scope
85
+ : undefined ,
86
+ ) : [ GenericComponentInstance | null , EffectScope | undefined ] => {
78
87
const prev = currentInstance
79
- internalSetCurrentInstance ( instance )
80
- instance . scope . on ( )
81
- return ( ) : void => {
82
- instance . scope . off ( )
83
- internalSetCurrentInstance ( prev )
84
- }
85
- }
86
-
87
- export const unsetCurrentInstance = ( ) : void => {
88
- currentInstance && currentInstance . scope . off ( )
89
- internalSetCurrentInstance ( null )
90
- }
91
-
92
- /**
93
- * Exposed for vapor only. Vapor never runs during SSR so we don't want to pay
94
- * for the extra overhead
95
- * @internal
96
- */
97
- export const simpleSetCurrentInstance = (
98
- i : GenericComponentInstance | null ,
99
- unset ?: GenericComponentInstance | null ,
100
- ) : void => {
101
- currentInstance = i
102
- if ( unset ) {
103
- unset . scope . off ( )
104
- } else if ( i ) {
105
- i . scope . on ( )
106
- }
88
+ simpleSetCurrentInstance ( instance )
89
+ const prevScope = setCurrentScope ( scope )
90
+ return [ prev , prevScope ]
107
91
}
0 commit comments