File tree 2 files changed +29
-6
lines changed
2 files changed +29
-6
lines changed Original file line number Diff line number Diff line change 8
8
effect ,
9
9
ref ,
10
10
shallowReadonly ,
11
- isProxy
11
+ isProxy ,
12
+ computed
12
13
} from '../src'
13
14
14
15
/**
@@ -435,6 +436,26 @@ describe('reactivity/readonly', () => {
435
436
) . toHaveBeenWarned ( )
436
437
} )
437
438
439
+ // https://github.com/vuejs/vue-next/issues/3376
440
+ test ( 'calling readonly on computed should allow computed to set its private properties' , ( ) => {
441
+ const r = ref < boolean > ( false )
442
+ const c = computed ( ( ) => r . value )
443
+ const rC = readonly ( c )
444
+
445
+ r . value = true
446
+
447
+ expect ( rC . value ) . toBe ( true )
448
+ expect (
449
+ 'Set operation on key "_dirty" failed: target is readonly.'
450
+ ) . not . toHaveBeenWarned ( )
451
+ // @ts -expect-error - non-existant property
452
+ rC . randomProperty = true
453
+
454
+ expect (
455
+ 'Set operation on key "randomProperty" failed: target is readonly.'
456
+ ) . toHaveBeenWarned ( )
457
+ } )
458
+
438
459
describe ( 'shallowReadonly' , ( ) => {
439
460
test ( 'should not make non-reactive properties reactive' , ( ) => {
440
461
const props = shallowReadonly ( { n : { foo : 1 } } )
Original file line number Diff line number Diff line change @@ -48,12 +48,14 @@ class ComputedRefImpl<T> {
48
48
}
49
49
50
50
get value ( ) {
51
- if ( this . _dirty ) {
52
- this . _value = this . effect ( )
53
- this . _dirty = false
51
+ // the computed ref may get wrapped by other proxies e.g. readonly() #3376
52
+ const self = toRaw ( this )
53
+ if ( self . _dirty ) {
54
+ self . _value = this . effect ( )
55
+ self . _dirty = false
54
56
}
55
- track ( toRaw ( this ) , TrackOpTypes . GET , 'value' )
56
- return this . _value
57
+ track ( self , TrackOpTypes . GET , 'value' )
58
+ return self . _value
57
59
}
58
60
59
61
set value ( newValue : T ) {
You can’t perform that action at this time.
0 commit comments