Skip to content

Commit

Permalink
feat(runtime-core): detect and warn against components made reactive
Browse files Browse the repository at this point in the history
close #962
  • Loading branch information
yyx990803 committed Apr 14, 2020
1 parent 3e7bb7d commit 2e06f5b
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions packages/runtime-core/src/vnode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
ClassComponent
} from './component'
import { RawSlots } from './componentSlots'
import { isReactive, Ref } from '@vue/reactivity'
import { isReactive, Ref, toRaw } from '@vue/reactivity'
import { AppContext } from './apiCreateApp'
import {
SuspenseImpl,
Expand Down Expand Up @@ -236,7 +236,7 @@ const createVNodeWithArgsTransform = (

export const InternalObjectSymbol = Symbol()

export const createVNode = (__DEV__
export const createVNode = (false
? createVNodeWithArgsTransform
: _createVNode) as typeof _createVNode

Expand Down Expand Up @@ -292,6 +292,22 @@ function _createVNode(
? ShapeFlags.FUNCTIONAL_COMPONENT
: 0

if (
__DEV__ &&
shapeFlag & ShapeFlags.STATEFUL_COMPONENT &&
isReactive(type)
) {
type = toRaw(type)
warn(
`Vue received a Component which was made a reactive object. This can ` +
`lead to unnecessary performance overhead, and should be avoided by ` +
`marking the component with \`markNonReactive\` or using \`shallowRef\` ` +
`instead of \`ref\`.`,
`\nComponent that was made reactive: `,
type
)
}

const vnode: VNode = {
_isVNode: true,
type,
Expand Down

0 comments on commit 2e06f5b

Please sign in to comment.