-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
fix: spring does not start #2372
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
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
|
|
Do we have a reproduction of this in a sandbox? if i look at the examples in the docs, they all appear to work 🤔 |
|
@joshuaellis yes,
|
|
I'll take a look at this properly in a few hours. That line in particular was taken from the stale PR we had for React 19 before mine. I assumed it was fixing a cleanup of the ref. Would be good to test properly without it. Whatever the cause of this bug is - Seeing as the CI tests passed, we should try and enhance the coverage to try and replicate this via CI. If you were able to recreate the bug consistently is there a particular case where it fails? As Josh mentioned, the local tests and the deployed docs worked! Odd! Thoughts? |
|
I've just had a proper look through - I think we can remove this safely - I don't think the cleanup is necessary as the next runthrough of updates will overwrite any previously parsed updates. So in terms of the logic for removing it, all good on my end. One thing I would like to suggest though is to catch the crashing behaviour in a test (like i mentioned before). I guess this is dependant on what causes the crashing, i.e what error it is. What are you guys' thoughts on that? Worth doing? |
|
@kierancap agree to add a test on this, but I would first document the internal a bit. It is not easy to grasp for everyone. So, what this business code actually do? PS: the current website is not up to date so it run with the v9 |
|
Yeah agreed about documenting the internals. Based on my understanding the ref is just handling queuing updates. I think the cleanup line may have come from the thought of needing the clean up an update post process, but based on my glance yesterday it seems like thats unnecessary (I'm also guessing that the ref is used asynchronously in other parts too - hence the crashing) As to the actual design of the code, I'm not totally sure - It's not well documented so I've just tried to peace together what I can based on the code itself. The last updates to that system pre our PR was 5-6 years ago, so I doubt we can get any assistance on that either. If @joshuaellis has any understanding about the spring update system, would be great to enlighten myself and we can write some docs outlining it internally |
It was written by a previous maintainer, i normally have to read it a couple of times before i really understand it. I think the point about it not being caught by a test is important, i would revert the change temporarily and get a test to fail then go from there. It might be that this is caught in a more integration test where you render a component instead of just the hook perhaps? |
|
Ah that's fair enough! Would absolutely be worth testing this from multiple angles, seeing as it escaped us the first time! I'd be interested to see if the bug can be triggered via the hook alone - or if it's dependant on a full React environment (UI rendering etc) to appear |
|
some more in depth explanations @joshuaellis @kierancap TL;DR ====== After diving back into the code, it's clear that the cleanup line makes no sense. I'm pretty sure it was just a WIP line meant for testing, which accidentally ended up in our PR. What I learnedBug reproduction environmentWith v10, it does not appear in production mode, regardless of the following conditions:
Usage: the updates and controllers arraysThese are internal state structures:
Logic: starting the animationFor a spring, starting an animation means sending the next state to reach. Usage: useRefIn Strict Mode, React triggers two renders. When there's only one render, everything works fine
But on the second render, since the useMemo dependencies haven't changed, the useMemo hooks are not triggered, resulting in empty updates and ctrls arrays. Using useRef (and also useMemo to store ctrls) allows us to keep references to previously populated arrays. The bugThe bug originates from the cleanup line where we remove an update.
🐛🐛🐛 The spring won't start 🐛 🐛🐛 SolutionRemoving the faulty cleanup line. |
Incredible work diagnosing this!! It's so rare to see actual occasions where Strict Mode causes bugs like this, but that's what it's there for! You are probably absolutely correct that the line was probably there for debugging rather than an actual addition to the code. If the bug is purely caused by the ref being removed and Strict Mode causing the oddness, there's not much value in testing that scenario. (I saw a commit about a test, if that's already in place, feel free to keep it! I just know from personal experience that testing Strict Mode oddness is a challenge) I'd be happy for this PR to be moved forward in that case. If @joshuaellis doesn't have any further comments of course :) Great work again mate! |
|
thx @kierancap! |
joshuaellis
left a comment
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.
Amazing work 👏🏼
Why
This PR fixes a bug where useSpring lead to unmount component (eg. blank page)
Related: #2371
What
The root cause was an instruction which removes the current update during the useIsomorphicLayoutEffect callback.
@kierancap I would like your opinion on this if you have a minute. I don't know exactly the impact of this.
Checklist