From f9e3e38fdb8aba75b3214c0434ccbb40ce0afb16 Mon Sep 17 00:00:00 2001 From: Evan You Date: Tue, 30 Oct 2018 00:42:26 -0400 Subject: [PATCH] chore: add warning when attempting to mutate non-observable hooks return value --- packages/runtime-core/src/componentProxy.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/runtime-core/src/componentProxy.ts b/packages/runtime-core/src/componentProxy.ts index 43be1136..8319a962 100644 --- a/packages/runtime-core/src/componentProxy.ts +++ b/packages/runtime-core/src/componentProxy.ts @@ -2,6 +2,7 @@ import { ComponentInstance } from './component' import { isFunction, isReservedKey } from '@vue/shared' import { warn } from './warning' import { isRendering } from './componentUtils' +import { isObservable } from '@vue/observer' const bindCache = new WeakMap() @@ -75,6 +76,12 @@ const renderProxyHandlers = { target.$data[key] = value return true } else if ((i = target._hookProps) !== null && i.hasOwnProperty(key)) { + if (__DEV__ && !isObservable(i)) { + warn( + `attempting to mutate a property returned from hooks(), but the ` + + `value is not observable.` + ) + } // this enables returning observable objects from hooks() i[key] = value return true