Replies: 18 comments
-
Thanks for reporting. (edit) |
Beta Was this translation helpful? Give feedback.
-
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]))
} |
Beta Was this translation helpful? Give feedback.
-
Sure. It worked correctly. |
Beta Was this translation helpful? Give feedback.
-
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. |
Beta Was this translation helpful? Give feedback.
-
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 |
Beta Was this translation helpful? Give feedback.
-
I think it is about a version of removed item. |
Beta Was this translation helpful? Give feedback.
-
@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. |
Beta Was this translation helpful? Give feedback.
-
Sure. I've opened very draft PR #721 to add docs. |
Beta Was this translation helpful? Give feedback.
-
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. |
Beta Was this translation helpful? Give feedback.
-
I need some time to look into it. |
Beta Was this translation helpful? Give feedback.
-
@dai-shi FYI: I found change that caused this issue |
Beta Was this translation helpful? Give feedback.
-
@Juyeong-Byeon |
Beta Was this translation helpful? Give feedback.
-
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.
|
Beta Was this translation helpful? Give feedback.
-
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, |
Beta Was this translation helpful? Give feedback.
-
I'll take a look on the weekend. |
Beta Was this translation helpful? Give feedback.
-
@serdaryesilmurat Can you describe more about your situation or share reproducible code? 🙂 I tried bellow: |
Beta Was this translation helpful? Give feedback.
-
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. |
Beta Was this translation helpful? Give feedback.
-
@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. |
Beta Was this translation helpful? Give feedback.
-
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.
Beta Was this translation helpful? Give feedback.
All reactions