From 6abac87b3d1b7a22df80b7a70a10101a7f3d3732 Mon Sep 17 00:00:00 2001 From: Evan You Date: Fri, 12 Jun 2020 16:59:15 -0400 Subject: [PATCH] fix(runtime-core): track access to $attrs fix #1346 --- packages/runtime-core/src/componentProps.ts | 10 +++++++++- packages/runtime-core/src/componentProxy.ts | 9 ++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/packages/runtime-core/src/componentProps.ts b/packages/runtime-core/src/componentProps.ts index 0f6fecb14e6..28f5ed00ea0 100644 --- a/packages/runtime-core/src/componentProps.ts +++ b/packages/runtime-core/src/componentProps.ts @@ -1,4 +1,9 @@ -import { toRaw, shallowReactive } from '@vue/reactivity' +import { + toRaw, + shallowReactive, + trigger, + TriggerOpTypes +} from '@vue/reactivity' import { EMPTY_OBJ, camelize, @@ -215,6 +220,9 @@ export function updateProps( } } + // trigger updates for $attrs in case it's used in component slots + trigger(instance, TriggerOpTypes.SET, '$attrs') + if (__DEV__ && rawProps) { validateProps(props, instance.type) } diff --git a/packages/runtime-core/src/componentProxy.ts b/packages/runtime-core/src/componentProxy.ts index f986c3a8275..de7765d3f4d 100644 --- a/packages/runtime-core/src/componentProxy.ts +++ b/packages/runtime-core/src/componentProxy.ts @@ -13,7 +13,9 @@ import { UnwrapRef, toRaw, shallowReadonly, - ReactiveFlags + ReactiveFlags, + track, + TrackOpTypes } from '@vue/reactivity' import { ExtractComputedReturns, @@ -260,8 +262,9 @@ export const PublicInstanceProxyHandlers: ProxyHandler = { let cssModule, globalProperties // public $xxx properties if (publicGetter) { - if (__DEV__ && key === '$attrs') { - markAttrsAccessed() + if (key === '$attrs') { + track(instance, TrackOpTypes.GET, key) + __DEV__ && markAttrsAccessed() } return publicGetter(instance) } else if (