From fa2240143c07c69948ea471543c8a7c7ba150b17 Mon Sep 17 00:00:00 2001 From: Evan You Date: Fri, 1 Mar 2019 10:28:29 -0500 Subject: [PATCH] dx: warn private fields usage --- packages/runtime-core/src/componentProxy.ts | 1 + packages/runtime-core/src/componentRenderUtils.ts | 11 +++++++---- packages/runtime-core/src/errorHandling.ts | 13 ++++++++++--- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/packages/runtime-core/src/componentProxy.ts b/packages/runtime-core/src/componentProxy.ts index 1747631d..4ebbbf79 100644 --- a/packages/runtime-core/src/componentProxy.ts +++ b/packages/runtime-core/src/componentProxy.ts @@ -6,6 +6,7 @@ import { warn } from './warning' const bindCache = new WeakMap() +// TODO: bound methods should also capture/handle errors function getBoundMethod(fn: Function, target: any, receiver: any): Function { let boundMethodsForTarget = bindCache.get(target) if (boundMethodsForTarget === void 0) { diff --git a/packages/runtime-core/src/componentRenderUtils.ts b/packages/runtime-core/src/componentRenderUtils.ts index 07588600..d327d0fe 100644 --- a/packages/runtime-core/src/componentRenderUtils.ts +++ b/packages/runtime-core/src/componentRenderUtils.ts @@ -10,17 +10,20 @@ export let isRendering = false export function renderInstanceRoot(instance: ComponentInstance): VNode { let vnode const { render, $proxy, $props, $slots, $attrs, $parentVNode } = instance + if (__DEV__) { + isRendering = true + } try { - if (__DEV__) { - isRendering = true - } vnode = render.call($proxy, $props, $slots, $attrs, $parentVNode) + } catch (err) { if (__DEV__) { isRendering = false } - } catch (err) { handleError(err, instance, ErrorTypes.RENDER) } + if (__DEV__) { + isRendering = false + } return normalizeComponentRoot(vnode, $parentVNode) } diff --git a/packages/runtime-core/src/errorHandling.ts b/packages/runtime-core/src/errorHandling.ts index 301fa66b..2d427684 100644 --- a/packages/runtime-core/src/errorHandling.ts +++ b/packages/runtime-core/src/errorHandling.ts @@ -54,7 +54,7 @@ export function callLifecycleHookWithHandler( ) { try { const res = hook.call(instanceProxy, arg) - if (res && typeof res.then === 'function') { + if (res && !res._isVue && typeof res.then === 'function') { ;(res as Promise).catch(err => { handleError(err, instanceProxy._self, type) }) @@ -114,11 +114,18 @@ function logError(err: Error, type: ErrorTypes, contextVNode: VNode | null) { if (contextVNode) { pushWarningContext(contextVNode) } - warn(`Unhandled error${info ? ` ${info}` : ``}`) + if (/private field/.test(err.message)) { + warn( + `Private fields are not supported in component classes because they ` + + `cannot be tunneled through Proxies.` + ) + } else { + warn(`Unhandled error${info ? ` ${info}` : ``}`) + } + console.error(err) if (contextVNode) { popWarningContext() } - console.error(err) } else { throw err }