pmndrs / valtio

💊 Valtio makes proxy-state simple for React and Vanilla
http://valtio.pmnd.rs
MIT License
8.7k stars 244 forks source link

test: add cyclical class test #794

Closed Gregoor closed 9 months ago

Gregoor commented 9 months ago

Hi there,

thanks for the great library!

I've got a case of mildly cursed cyclical classes, that I don't think I can data model my way around. valtio seems like a great solution to make it work, but I seem to have run into a proxy-ing bug which I've been able to repro here (the test case succeeds without the proxy()-wrap).

Now the docs do say

Not everything can be proxied. Generally, you are safe if it is serializable. Classes can also be proxied. But avoid special objects.

And it's not serializable and it's definitely special (the bad kind of special), but as I said, it also seems necessary for my use case.

So here's my question: would fixing this be possible and in-scope? If so I'd also be happy to see if I can figure it out on my own, though guidance would certainly help.

Cheers!

vercel[bot] commented 9 months ago

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 Oct 3, 2023 8:31pm
codesandbox-ci[bot] commented 9 months ago

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 46c0879b16ad7a83d145067a0b41e34a840e7cb5:

Sandbox Source
React Configuration
React TypeScript Configuration
React Browserify Configuration
React Snowpack Configuration
React Parcel Configuration
dai-shi commented 9 months ago

Thanks for opening up a discussion.

would fixing this be possible and in-scope?

One thing we can't change is we kind of support classes by not touching prototype chain. So, leaving prototype untouched is the design decision. tbh, I'm not sure if it's fixable under this constraint.

If so I'd also be happy to see if I can figure it out on my own, though guidance would certainly help.

I'd encourage you to dig a little deeper. I don't yet know why it doesn't work. We do support cyclical objects, which is a unique feature to my knowledge.

Gregoor commented 9 months ago

I did not manage to figure it out and in the scramble I managed to unscramble my data model. So I'll close this PR. Thanks for the words and the lib! Also for Jotai, which I'm going back to now, since it indeed was the only solid lib I found that does cyclical objects.