-
-
Notifications
You must be signed in to change notification settings - Fork 266
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(utils): re-implement derive to make glitch free (#335 was buggy) #341
Conversation
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/pmndrs/valtio/5hbgLdq3Gx5kJ1p3t9m4ZhpjuMVt |
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 a553473:
|
tests/derive.test.tsx
Outdated
const App = () => { | ||
const snap = useSnapshot(derived3) | ||
|
||
renderCount++ |
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.
We should count commits not renders. Let me tweak the test.
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.
Oh very interesting I didn't know useEffect was the way to count commits! I learned a lot here thanks!
tests/derive.test.tsx
Outdated
expect(computeValue).toBeCalledTimes(2) | ||
|
||
await findByText('value: v0: 1, v1: 1, v2: 1') | ||
expect(computeValue).toBeCalledTimes(3) |
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.
This should be 2
, right?
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.
Oh yes! Sorry, I made it 3 because thats the count when it was glitched. Thanks for helping fix!
Okay, I kind of new my impl in #335 was truly correct. I had another impl, and based on it, a commit is added. It's complicated, so let me try some refactoring. Meanwhile, @Noitidart could you try if it solves the issue? |
Let's release this soon, because #342 is a bigger issue. v1.2.10 is full of bugs. 😓 |
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.
Thanks for your investigation. I hope this is better than #335, but not sure if there are some bugs remaining. Please report issues if anything goes wrong.
Trying now! Sorry for delay I'm on west coast us so just woke up haha. |
With v1.2.9 this used to happen:
Notice how compute1 then compute3 happens, then again compute2 happens then compute3 happens. Now in v1.2.11 its perfect:
compute1 then compuet2 then compute3 and all variables are lined up! no extra callback is triggered! |
No worries! I knew the timezone difference. I wanted to replace troublesome v1.2.10 as soon as possible. |
Totally gotcha, thanks for giving me chance to take part of the emergency release. If possible it happens again no matter time if I see it I would definitely get on it, thanks for trying to include us man! |
By the way, this implementation might still have a limitation. A circular graph may result in an infinite loop. Would you like to test it?? |
Haha thanks! I don't understand the circular graph situation, if you could help me understand I would learn about this circular graph thing. |
The circular graph is something like this: A derived from B derived from C derived from A. |
Found this: https://en.wikipedia.org/wiki/Reactive_programming#Cyclic_dependencies It's called cyclic dependencies. |
Oh thanks! Sorry I got busy with urgently implementing a Stripe payment system update. I'll have to revisit this please. Thanks very much for trying to get me involved! |
Related: #296 (comment)