diff --git a/packages/runtime-core/src/apiInject.ts b/packages/runtime-core/src/apiInject.ts index 93d5e39a..c7f8f327 100644 --- a/packages/runtime-core/src/apiInject.ts +++ b/packages/runtime-core/src/apiInject.ts @@ -1,4 +1,6 @@ import { currentInstance } from './component' +import { immutable } from './apiState' +import { isObject } from '@vue/shared' export interface InjectionKey extends Symbol {} @@ -29,8 +31,8 @@ export function inject(key: InjectionKey | string, defaultValue?: any) { } else { // TODO should also check for app-level provides const provides = currentInstance.parent && currentInstance.provides - return provides && key in provides - ? (provides[key as any] as any) - : defaultValue + const val = + provides && key in provides ? (provides[key as any] as any) : defaultValue + return __DEV__ && isObject(val) ? immutable(val) : val } }