Skip to content

Commit 2e06f5b

Browse files
committed
feat(runtime-core): detect and warn against components made reactive
close #962
1 parent 3e7bb7d commit 2e06f5b

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

packages/runtime-core/src/vnode.ts

+18-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
ClassComponent
1818
} from './component'
1919
import { RawSlots } from './componentSlots'
20-
import { isReactive, Ref } from '@vue/reactivity'
20+
import { isReactive, Ref, toRaw } from '@vue/reactivity'
2121
import { AppContext } from './apiCreateApp'
2222
import {
2323
SuspenseImpl,
@@ -236,7 +236,7 @@ const createVNodeWithArgsTransform = (
236236

237237
export const InternalObjectSymbol = Symbol()
238238

239-
export const createVNode = (__DEV__
239+
export const createVNode = (false
240240
? createVNodeWithArgsTransform
241241
: _createVNode) as typeof _createVNode
242242

@@ -292,6 +292,22 @@ function _createVNode(
292292
? ShapeFlags.FUNCTIONAL_COMPONENT
293293
: 0
294294

295+
if (
296+
__DEV__ &&
297+
shapeFlag & ShapeFlags.STATEFUL_COMPONENT &&
298+
isReactive(type)
299+
) {
300+
type = toRaw(type)
301+
warn(
302+
`Vue received a Component which was made a reactive object. This can ` +
303+
`lead to unnecessary performance overhead, and should be avoided by ` +
304+
`marking the component with \`markNonReactive\` or using \`shallowRef\` ` +
305+
`instead of \`ref\`.`,
306+
`\nComponent that was made reactive: `,
307+
type
308+
)
309+
}
310+
295311
const vnode: VNode = {
296312
_isVNode: true,
297313
type,

0 commit comments

Comments
 (0)