Skip to content

Commit

Permalink
fix(runtime-core): track access to $attrs
Browse files Browse the repository at this point in the history
fix #1346
  • Loading branch information
yyx990803 committed Jun 12, 2020
1 parent 91fa528 commit 6abac87
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
10 changes: 9 additions & 1 deletion packages/runtime-core/src/componentProps.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { toRaw, shallowReactive } from '@vue/reactivity'
import {
toRaw,
shallowReactive,
trigger,
TriggerOpTypes
} from '@vue/reactivity'
import {
EMPTY_OBJ,
camelize,
Expand Down Expand Up @@ -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)
}
Expand Down
9 changes: 6 additions & 3 deletions packages/runtime-core/src/componentProxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ import {
UnwrapRef,
toRaw,
shallowReadonly,
ReactiveFlags
ReactiveFlags,
track,
TrackOpTypes
} from '@vue/reactivity'
import {
ExtractComputedReturns,
Expand Down Expand Up @@ -260,8 +262,9 @@ export const PublicInstanceProxyHandlers: ProxyHandler<any> = {
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 (
Expand Down

0 comments on commit 6abac87

Please sign in to comment.