@@ -4,6 +4,7 @@ import type {
44 GenericComponentInstance ,
55} from './component'
66import { currentRenderingInstance } from './componentRenderContext'
7+ import { setCurrentScope } from '@vue/reactivity'
78
89/**
910 * @internal
@@ -25,7 +26,10 @@ export let isInSSRComponentSetup = false
2526
2627export let setInSSRSetupState : ( state : boolean ) => void
2728
28- let internalSetCurrentInstance : (
29+ /**
30+ * @internal
31+ */
32+ export let simpleSetCurrentInstance : (
2933 instance : GenericComponentInstance | null ,
3034) => void
3135
@@ -53,7 +57,7 @@ if (__SSR__) {
5357 else setters [ 0 ] ( v )
5458 }
5559 }
56- internalSetCurrentInstance = registerGlobalSetter (
60+ simpleSetCurrentInstance = registerGlobalSetter (
5761 `__VUE_INSTANCE_SETTERS__` ,
5862 v => ( currentInstance = v ) ,
5963 )
@@ -66,7 +70,7 @@ if (__SSR__) {
6670 v => ( isInSSRComponentSetup = v ) ,
6771 )
6872} else {
69- internalSetCurrentInstance = i => {
73+ simpleSetCurrentInstance = i => {
7074 currentInstance = i
7175 }
7276 setInSSRSetupState = v => {
@@ -76,32 +80,10 @@ if (__SSR__) {
7680
7781export const setCurrentInstance = ( instance : GenericComponentInstance ) => {
7882 const prev = currentInstance
79- internalSetCurrentInstance ( instance )
80- instance . scope . on ( )
83+ simpleSetCurrentInstance ( instance )
84+ const prevScope = setCurrentScope ( instance . scope )
8185 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 ( )
86+ setCurrentScope ( prevScope )
87+ simpleSetCurrentInstance ( prev )
10688 }
10789}
0 commit comments