-
-
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): unwrap ref types as props of arrays #1859
Conversation
I don't think this is fixing the the issue linked. It is about properties added to an array, not refs inside arrays and empty string keys |
|
@@ -81,7 +81,10 @@ function createGetter(isReadonly = false, shallow = false) { | |||
|
|||
if (isRef(res)) { | |||
// ref unwrapping, only for Objects, not for Arrays. | |||
return targetIsArray ? res : res.value | |||
const shouldUnwrap = | |||
!targetIsArray || isSymbol(key) || isNaN(key as any) || key === '' |
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.
why not just !targetIsArray || typeof key !== 'number'
?
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.
the key is a string😭
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.
In fact, there are a lot of edge cases not taken into account in this kind of check. eg. '3e7' can be treated as a legal Number by JavaScript.
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.
3e7
is actually already normalized to "30000000"
here, but this check does produce false positives for float strings like 1.234
which are not valid Array indices.
Technically we should only skip unwrap for integer keys. Maybe we can check '' + parseInt(key, 10) === key
instead.
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.
yes! according to https://jsben.ch/MMQ6b, it has better accuracy and the time cost remains the same
isSymbol(key) | ||
? builtInSymbols.has(key) | ||
keyIsSymbol | ||
? builtInSymbols.has(key as symbol) |
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.
reusing the result of isSymbol(key)
will disable type guard, so have to add as
manually 😣
close #1846