-
-
Notifications
You must be signed in to change notification settings - Fork 8.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(reactivity): ensure computed wrapped in readonly still works (close #3376) #3377
Conversation
Size report
|
I added a test but would like input if there are more scenarios to cover. |
if ((target as any).__v_isRef && (target as any).effect) { | ||
// computed should be able to set its own private properties | ||
if (key === '_dirty' || key === '_value') { | ||
return set(target, key, value, receiver) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add __v_isComputed
to ComputedRefImpl
? like this:
class ComputedRefImpl<T> {
private _value!: T
private _dirty = true
public readonly effect: ReactiveEffect<T>
public readonly __v_isRef = true;
+ public readonly __v_isComputed = true;
public readonly [ReactiveFlags.IS_READONLY]: boolean
}
I mean, this would be safer, consider the following scenario:
const data = ref({ effect: true })
const rData = readonly(data)
rData._value = 'xxx' // Unexpectedly
with the __v_isComputed
, we can implement the isComputed
function, just like isRef
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit confused by the {effect: true}
- that shouldn't have an impact, as that would be in target.value.effect
, wouldn't it?
But nonetheless propably a safer approach., I agree.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh sure, but you know what i mean 😄
ebe7c45
to
67f89fd
Compare
@HcySunYang I did the change you proposed, can you have a look? Thanks! |
See cleaner fix in 41e02f0 |
Definitely the better solution, thanks. |
Wrapping a
computed()
inreadonly()
breaks the computed's functionality.This PR ensures that such a wrapped computed can still set its internal proeprties
_dirty
&_value
, ensuring it can continue to work as expected.close #3376