Skip to content
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: invalidate snap cache when property is removed from object #736

Closed

Conversation

Juyeong-Byeon
Copy link

@Juyeong-Byeon Juyeong-Byeon commented Jun 9, 2023

Related Issues or Discussions

related to
#712

Just like that change [1], I suggest removing snap cache when props are removed from the parent object or array

[1] This change is removing the listeners for removed props from the parent object or array.

FYI: #712 is an issue that has occurred since version 1.8.0 caused by ec44557 or #599

Fixes #712

Summary

Adding remove snap cache logic to deleteProperty function

Check List

  • yarn run prettier for formatting code and docs

@vercel
Copy link

vercel bot commented Jun 9, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
valtio ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 10, 2023 2:38pm

@codesandbox-ci
Copy link

codesandbox-ci bot commented Jun 9, 2023

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 5e7403c:

Sandbox Source
React Configuration
React Typescript Configuration
React Browserify Configuration
React Snowpack Configuration
React Parcel Configuration

@Juyeong-Byeon Juyeong-Byeon deleted the fix-snap-cache-invalid branch June 9, 2023 16:31
@Juyeong-Byeon Juyeong-Byeon restored the fix-snap-cache-invalid branch June 9, 2023 16:31
@dai-shi dai-shi reopened this Jun 9, 2023
@dai-shi dai-shi marked this pull request as draft June 9, 2023 22:34
Copy link
Member

@dai-shi dai-shi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you be able to add a failing test?

src/vanilla.ts Outdated
@@ -244,6 +244,7 @@ const buildProxyFunction = (
const handler: ProxyHandler<T> = {
deleteProperty(target: T, prop: string | symbol) {
const prevValue = Reflect.get(target, prop)
snapCache.delete(target as Object)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We never delete the cache elsewhere, so it doesn't feel very nice.
Do you happen to know why deleteProperty doesn't increment the version number?
I think we should increment it if it doesn't.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I will try more on that way.
And I found out that although if I increase the target version of deleted property in deleteProperty it is still getting the same version in here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you be able to add a failing test?

Do you mean that adding a test fails when this symptom has occurred?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, yeah. adding a test to represent #712 issue, which fails in the current main branch, and will be resolved with this PR.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is still getting the same version

Is it like reading a stale version from somewhere?

* [2]. Remove target item should be nested object
* [3]. The array should be subscribed
* [4]. The array should pass to snapshot() before the target item removed
*/
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dai-shi I added test and reverted the previous commit.
And wrote the error occurrence conditions.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Can you resolve conflicts and merge the main branch?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done! And I will look in to it about another approach that you suggested. 😀

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, are you still around?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made some tries after this, but it didn't worked. (ex- force version update if child object removed)
I think It will be hard to fix without breaking something, as you said.

Do you have any idea about approach to fix it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#712 (comment) is my current understanding.

@dai-shi
Copy link
Member

dai-shi commented Nov 3, 2023

Closing as inactive. Let's reopen when there's a progress.

@dai-shi dai-shi closed this Nov 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cache key could refer previous value
2 participants