File tree 1 file changed +3
-3
lines changed
packages/shared/injectLocal
1 file changed +3
-3
lines changed Original file line number Diff line number Diff line change 1
- import { getCurrentInstance , inject } from 'vue'
1
+ import { getCurrentInstance , hasInjectionContext , inject } from 'vue'
2
2
import { localProvidedStateMap } from '../provideLocal/map'
3
3
4
4
/**
@@ -14,10 +14,10 @@ import { localProvidedStateMap } from '../provideLocal/map'
14
14
export const injectLocal : typeof inject = ( ...args ) => {
15
15
const key = args [ 0 ] as string | symbol
16
16
const instance = getCurrentInstance ( ) ?. proxy
17
- if ( instance == null )
17
+ if ( instance == null && ! hasInjectionContext ( ) )
18
18
throw new Error ( 'injectLocal must be called in setup' )
19
19
20
- if ( localProvidedStateMap . has ( instance ) && key in localProvidedStateMap . get ( instance ) ! )
20
+ if ( instance && localProvidedStateMap . has ( instance ) && key in localProvidedStateMap . get ( instance ) ! )
21
21
return localProvidedStateMap . get ( instance ) ! [ key ]
22
22
23
23
// @ts -expect-error overloads are not compatible
You can’t perform that action at this time.
0 commit comments