-
Notifications
You must be signed in to change notification settings - Fork 0
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
Using the callback ref on animated element (React Spring) causes a cleanup ↻ install loop #6
Comments
Does the |
Can you create an example in a branch with this behavior? |
Yes, I've pushed issue-6, containing the example above. You'll see the The width of the element is not animated. Seems like it has something to do with how React Spring handles refs on animated elements. |
Ok, so I narrowed it down to this: import { animated } from 'react-spring'
export default function App() {
const [bool, setBool] = React.useState(false)
const ref1 = React.useCallback(node => { console.log('ref1', node) }, [])
const ref2 = React.useCallback(node => { console.log('ref2', node) }, [])
return (
<div>
<div ref={ref1}>1</div>
<animated.div ref={ref2}>2</animated.div>
<button onClick={() => setBool(x => !x)}>Rerender</button>
</div>
)
} Output on first render is this:
On subsequent clicks:
So there is a clear behavior difference. We can solve half of the problem by checking if the same node is supplied twice. Getting a |
I created a ticket for |
When you pass the
ref
useElementSize
gives you to ananimated.div
(react-spring
), it'll trigger some infinite logic, causing the observer callback to get called over and over. Interestingly, thecreateObserver
function is not called again.This code triggers the issue:
This doesn't:
The text was updated successfully, but these errors were encountered: