Skip to content

Commit b08a98b

Browse files
committedDec 22, 2024
fix(injectLocal): allow inject to app context
1 parent ece6a39 commit b08a98b

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed
 

‎packages/shared/injectLocal/index.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getCurrentInstance, inject } from 'vue'
1+
import { getCurrentInstance, hasInjectionContext, inject } from 'vue'
22
import { localProvidedStateMap } from '../provideLocal/map'
33

44
/**
@@ -14,10 +14,10 @@ import { localProvidedStateMap } from '../provideLocal/map'
1414
export const injectLocal: typeof inject = (...args) => {
1515
const key = args[0] as string | symbol
1616
const instance = getCurrentInstance()?.proxy
17-
if (instance == null)
17+
if (instance == null && !hasInjectionContext())
1818
throw new Error('injectLocal must be called in setup')
1919

20-
if (localProvidedStateMap.has(instance) && key in localProvidedStateMap.get(instance)!)
20+
if (instance && localProvidedStateMap.has(instance) && key in localProvidedStateMap.get(instance)!)
2121
return localProvidedStateMap.get(instance)![key]
2222

2323
// @ts-expect-error overloads are not compatible

0 commit comments

Comments
 (0)
Please sign in to comment.