From: Evan You Date: Thu, 16 Apr 2020 14:39:51 +0000 (-0400) Subject: perf(runtime-core): use raw context on component options init X-Git-Tag: v3.0.0-beta.1~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bfd6744fb1db36a02914ef48da7116636343f313;p=thirdparty%2Fvuejs%2Fcore.git perf(runtime-core): use raw context on component options init --- diff --git a/packages/runtime-core/__tests__/apiOptions.spec.ts b/packages/runtime-core/__tests__/apiOptions.spec.ts index 836373c705..65115804ad 100644 --- a/packages/runtime-core/__tests__/apiOptions.spec.ts +++ b/packages/runtime-core/__tests__/apiOptions.spec.ts @@ -627,7 +627,7 @@ describe('api: options', () => { render(h(Comp), root) instance.foo = 1 expect( - 'Computed property "foo" was assigned to but it has no setter.' + 'Write operation failed: computed property "foo" is readonly' ).toHaveBeenWarned() }) diff --git a/packages/runtime-core/src/componentOptions.ts b/packages/runtime-core/src/componentOptions.ts index 31bb01ad0e..20c99a717e 100644 --- a/packages/runtime-core/src/componentOptions.ts +++ b/packages/runtime-core/src/componentOptions.ts @@ -40,7 +40,8 @@ import { reactive, ComputedGetter, WritableComputedOptions, - ComputedRef + ComputedRef, + toRaw } from '@vue/reactivity' import { ComponentObjectPropsOptions, @@ -276,11 +277,12 @@ export function applyOptions( errorCaptured } = options - const renderContext = + const renderContext = toRaw( instance.renderContext === EMPTY_OBJ && (computedOptions || methods || watchOptions || injectOptions) ? (instance.renderContext = reactive({})) : instance.renderContext + ) const globalMixins = instance.appContext.mixins // call it only during dev @@ -355,7 +357,7 @@ export function applyOptions( : __DEV__ ? () => { warn( - `Computed property "${key}" was assigned to but it has no setter.` + `Write operation failed: computed property "${key}" is readonly.` ) } : NOOP @@ -369,7 +371,9 @@ export function applyOptions( if (renderContext[key] && !(key in proxyTarget)) { Object.defineProperty(proxyTarget, key, { enumerable: true, - get: () => (renderContext[key] as ComputedRef).value + configurable: true, + get: () => (renderContext[key] as ComputedRef).value, + set: NOOP }) } }