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

[v9.0.0-rc.3] When state is updated in render code, it causes useSpring to return undefined #1096

Closed
zachintosh opened this issue Jul 29, 2020 · 1 comment · Fixed by #1509
Assignees
Labels
kind: bug Something isn't working
Milestone

Comments

@zachintosh
Copy link

When updating state as part of render code (ugh), if it causes a component that uses react-spring to re-render, useSpring will return undefined on the second render.

I know updating state directly as part of render code can be bad. This was discovered when working with some older code written by someone newer to react. 😅

This started happening after upgrading from version 9.0.0-canary.808.17.55c5691 to the most recent v9.0.0-rc.3, so the break happened somewhere in there.

Here's a sandbox reproducing the issue:

https://codesandbox.io/s/elastic-sky-xthi0?file=/src/App.js

(You might have to refresh the live demo to get the console logs to start showing)

The quick fix is, of course, to follow good practices and not update your state during the render cycle, like with a useEffect (shown in the sandbox). But since this started happening between versions, I figured it was a bug somewhere in the recent v9 versions.

As a note, this bug can be caused by anything updating state in their render code (component or hook), as long as it causes whatever component is using react-spring to also re-render.

Also described in #1046 (it's a different issue, though, I think)

@zachintosh zachintosh changed the title [V9-rc.3] When state is updated in render code, it causes useSpring to return undefined [v9.0.0-rc.3] When state is updated in render code, it causes useSpring to return undefined Jul 29, 2020
@aleclarson aleclarson added kind: bug Something isn't working v9 labels Jul 29, 2020
@joshuaellis joshuaellis added this to the v9.1.0 milestone Mar 18, 2021
@joshuaellis joshuaellis modified the milestones: v9.1.0, v9.2.0 Apr 8, 2021
@joshuaellis
Copy link
Member

Hey @zachintosh, Only a year later 😅 but there's a PR open to fix this.

cameron-martin pushed a commit to cameron-martin/react-spring that referenced this issue May 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants