Skip to content

Commit 2fd3905

Browse files
committedJan 9, 2024
revert: "dx(computed): warn incorrect use of getCurrentInstance inside computed"
This reverts commit 324e817.
1 parent 3135fcb commit 2fd3905

File tree

3 files changed

+5
-92
lines changed

3 files changed

+5
-92
lines changed
 

‎packages/runtime-core/__tests__/apiComputed.spec.ts

-44
This file was deleted.
+3-35
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,10 @@
1-
import {
2-
type ComputedGetter,
3-
type WritableComputedOptions,
4-
computed as _computed,
5-
} from '@vue/reactivity'
1+
import { computed as _computed } from '@vue/reactivity'
62
import { isInSSRComponentSetup } from './component'
7-
import { isFunction } from '@vue/shared'
8-
9-
/**
10-
* For dev warning only.
11-
* Context: https://github.com/vuejs/core/discussions/9974
12-
*/
13-
export let isInComputedGetter = false
14-
15-
function wrapComputedGetter(
16-
getter: ComputedGetter<unknown>,
17-
): ComputedGetter<unknown> {
18-
return () => {
19-
isInComputedGetter = true
20-
try {
21-
return getter()
22-
} finally {
23-
isInComputedGetter = false
24-
}
25-
}
26-
}
273

284
export const computed: typeof _computed = (
29-
getterOrOptions: ComputedGetter<unknown> | WritableComputedOptions<unknown>,
5+
getterOrOptions: any,
306
debugOptions?: any,
317
) => {
32-
if (__DEV__) {
33-
if (isFunction(getterOrOptions)) {
34-
getterOrOptions = wrapComputedGetter(getterOrOptions)
35-
} else {
36-
getterOrOptions.get = wrapComputedGetter(getterOrOptions.get)
37-
}
38-
}
39-
40-
// @ts-expect-error the 3rd argument is hidden from public types
8+
// @ts-expect-error
419
return _computed(getterOrOptions, debugOptions, isInSSRComponentSetup)
4210
}

‎packages/runtime-core/src/component.ts

+2-13
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ import {
8585
} from './compat/compatConfig'
8686
import type { SchedulerJob } from './scheduler'
8787
import type { LifecycleHooks } from './enums'
88-
import { isInComputedGetter } from './apiComputed'
8988

9089
export type Data = Record<string, unknown>
9190

@@ -632,18 +631,8 @@ export function createComponentInstance(
632631

633632
export let currentInstance: ComponentInternalInstance | null = null
634633

635-
export const getCurrentInstance: () => ComponentInternalInstance | null =
636-
() => {
637-
if (__DEV__ && isInComputedGetter) {
638-
warn(
639-
`getCurrentInstance() called inside a computed getter. ` +
640-
`This is incorrect usage as computed getters are not guaranteed ` +
641-
`to be executed with an active component instance. If you are using ` +
642-
`a composable inside a computed getter, move it ouside to the setup scope.`,
643-
)
644-
}
645-
return currentInstance || currentRenderingInstance
646-
}
634+
export const getCurrentInstance: () => ComponentInternalInstance | null = () =>
635+
currentInstance || currentRenderingInstance
647636

648637
let internalSetCurrentInstance: (
649638
instance: ComponentInternalInstance | null,

2 commit comments

Comments
 (2)

ferferga commented on Jan 9, 2024

@ferferga
Contributor

@yyx990803 Sorry for commenting in a commit, but it's the only reference I could find for this change.

May we know the reason for the revert?

ferferga commented on Jan 9, 2024

@ferferga
Contributor

Found the ongoing discussion (leaving this for future lurkers): #9974 (comment)

Please sign in to comment.