Skip to content

Commit 67f89fd

Browse files
committed
refactor: add private prop to identify compted ref
1 parent 7582a83 commit 67f89fd

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

packages/reactivity/__tests__/readonly.spec.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,11 @@ describe('reactivity/readonly', () => {
445445
r.value = true
446446

447447
expect(rC.value).toBe(true)
448-
;(rC as any).randomProperty = 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
449453

450454
expect(
451455
'Set operation on key "randomProperty" failed: target is readonly.'

packages/reactivity/src/baseHandlers.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,7 @@ export const mutableHandlers: ProxyHandler<object> = {
198198
export const readonlyHandlers: ProxyHandler<object> = {
199199
get: readonlyGet,
200200
set(target, key, value, receiver) {
201-
// is computed()
202-
if ((target as any).__v_isRef && (target as any).effect) {
201+
if ((target as any).__v_isComputed) {
203202
// computed should be able to set its own private properties
204203
if (key === '_dirty' || key === '_value') {
205204
return set(target, key, value, receiver)

packages/reactivity/src/computed.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ class ComputedRefImpl<T> {
2626

2727
public readonly effect: ReactiveEffect<T>
2828

29-
public readonly __v_isRef = true;
29+
public readonly __v_isRef = true
30+
// flag to properly handle computed refs in readonly basehandlers
31+
public readonly __v_isComputed = true;
3032
public readonly [ReactiveFlags.IS_READONLY]: boolean
3133

3234
constructor(

0 commit comments

Comments
 (0)