|
|
@@ -85,6 +85,7 @@ import {
|
|
|
} from './compat/compatConfig'
|
|
|
import type { SchedulerJob } from './scheduler'
|
|
|
import type { LifecycleHooks } from './enums'
|
|
|
+import { isInComputedGetter } from './apiComputed'
|
|
|
|
|
|
export type Data = Record<string, unknown>
|
|
|
|
|
|
@@ -631,8 +632,18 @@ export function createComponentInstance(
|
|
|
|
|
|
export let currentInstance: ComponentInternalInstance | null = null
|
|
|
|
|
|
-export const getCurrentInstance: () => ComponentInternalInstance | null = () =>
|
|
|
- currentInstance || currentRenderingInstance
|
|
|
+export const getCurrentInstance: () => ComponentInternalInstance | null =
|
|
|
+ () => {
|
|
|
+ if (__DEV__ && isInComputedGetter) {
|
|
|
+ warn(
|
|
|
+ `getCurrentInstance() called inside a computed getter. ` +
|
|
|
+ `This is incorrect usage as computed getters are not guaranteed ` +
|
|
|
+ `to be executed with an active component instance. If you are using ` +
|
|
|
+ `a composable inside a computed getter, move it ouside to the setup scope.`,
|
|
|
+ )
|
|
|
+ }
|
|
|
+ return currentInstance || currentRenderingInstance
|
|
|
+ }
|
|
|
|
|
|
let internalSetCurrentInstance: (
|
|
|
instance: ComponentInternalInstance | null,
|