-
-
Notifications
You must be signed in to change notification settings - Fork 264
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
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
Cache key could refer previous value #712
Comments
Thanks for reporting. (edit) |
Can this be a workaround for now? window.handle = function handle() {
const temp = a[0]
- a.splice(0, 1)
temp.nested.nested2.a = 'Banana'
+ a.splice(0, 1)
a.push(temp)
console.log(Object.is(temp, a[0]))
} |
Sure. It worked correctly. |
It would be nice to resolve this issue as it can cause confusion and make debugging more challenging. Currently, the Redux DevTools are not notified when the state changes, which can lead to misunderstandings. Additionally, relying on console.log for debugging further complicates the situation because proxies are updated correctly, but the snapshot is not. |
I don't think it's resolvable without breaking something else. Anyone can give a try if interested.
If you detach an object, there's no way to notify. So, people could know that they are doing something wrong. They should change the object before detaching. I think we should describe this limitation in the docs: https://github.com/pmndrs/valtio/blob/main/docs/how-tos/some-gotchas.mdx |
I think it is about a version of removed item. |
@Juyeong-Byeon Don't we update proxy version when removing? Feel free to open a draft PR. @DevSDK It would be nice if you can add a https://codesandbox.io/s/react-new reproduction in the description of this issue. |
Sure. I've opened very draft PR #721 to add docs. |
oops, my request was to just add a codesandbox link here from your jsfiddle one. hoping @Juyeong-Byeon has an idea. Otherwise, let's add it to docs #721. |
I need some time to look into it. |
@Juyeong-Byeon |
This seems to be a relatively new issue, but since there is no update over a month, let me lit the fire again 😅 We also face the same issue in our project. We have a list of objects that are rendered in an antd Table component. Whenever we update the list in the store (replace an item in the array), Table component is not re-rendered.
|
I wonder if it's the same issue as this. Maybe @Juyeong-Byeon can confirm. I thought and still think the original issue might not be fixable. But, |
I'll take a look on the weekend. |
@serdaryesilmurat Can you describe more about your situation or share reproducible code? 🙂 I tried bellow: |
Sorry for the late response. In the sample code below, you can reproduce the error by pressing "update first" after adding new rows. "update last" always updates the table, but "update first" does not. |
@serdaryesilmurat it looks like the problem you're having is specific to antd's Table component. I would have to dig into the Ant source code but it's likely they are making copies of the objects somehow. One way you could resolve it is to manually access those keys beforehand ie: I guess for any similar bugs the issue is likely to be key tracking especially when using it with third party libraries since there's no guarantee they will use the proxy objects as-is or whether they will be cloning them for their own usage which will always break the proxy logic. |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
Summary
The cache key is referred to the previous value when the shape of references in the cache key is the same.
Link to reproduction
https://jsfiddle.net/z41pyotn/
Minimum reproduction cases represent proxy in array proxy.
Here's my debugging context that may help:
It seems to be no cache invalidation when the 'remove' operation for the array.
In minimum repro. case, at line 40, the proxy and value are cached that key as a proxy of 'a'.
When handle() function is called, the array will empty. After that, the values are updated (not proxy reference.) and pushed again to a.
The result of the 'a' still refers to the same cache that has been made by 40 lines. Because it refers to the same shape of references that is used as the cache key.
Check List
Please do not ask questions in issues.
Please include a minimal reproduction.
The text was updated successfully, but these errors were encountered: