Skip to content

Commit 6abac87

Browse files
committed
fix(runtime-core): track access to $attrs
fix #1346
1 parent 91fa528 commit 6abac87

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

packages/runtime-core/src/componentProps.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
import { toRaw, shallowReactive } from '@vue/reactivity'
1+
import {
2+
toRaw,
3+
shallowReactive,
4+
trigger,
5+
TriggerOpTypes
6+
} from '@vue/reactivity'
27
import {
38
EMPTY_OBJ,
49
camelize,
@@ -215,6 +220,9 @@ export function updateProps(
215220
}
216221
}
217222

223+
// trigger updates for $attrs in case it's used in component slots
224+
trigger(instance, TriggerOpTypes.SET, '$attrs')
225+
218226
if (__DEV__ && rawProps) {
219227
validateProps(props, instance.type)
220228
}

packages/runtime-core/src/componentProxy.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ import {
1313
UnwrapRef,
1414
toRaw,
1515
shallowReadonly,
16-
ReactiveFlags
16+
ReactiveFlags,
17+
track,
18+
TrackOpTypes
1719
} from '@vue/reactivity'
1820
import {
1921
ExtractComputedReturns,
@@ -260,8 +262,9 @@ export const PublicInstanceProxyHandlers: ProxyHandler<any> = {
260262
let cssModule, globalProperties
261263
// public $xxx properties
262264
if (publicGetter) {
263-
if (__DEV__ && key === '$attrs') {
264-
markAttrsAccessed()
265+
if (key === '$attrs') {
266+
track(instance, TrackOpTypes.GET, key)
267+
__DEV__ && markAttrsAccessed()
265268
}
266269
return publicGetter(instance)
267270
} else if (

0 commit comments

Comments
 (0)