-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
[bug]: Event Handlers not getting called in StrictMode #2203
Comments
I second this, in my case, most of the hooks also exhibit this weird behavior such as useChain not triggering when components mount and events like onChange not firing in almost every hook. All of this occurs when reactStrictMode is set to true. It seems like strict mode has broken most of the functionality. |
Same behavior with last version 9.7.3 in my next js project. const [style] = useSpring(
() => ({
from: { opacity: 0 },
to: { opacity: 1 },
delay: 100,
config: {
duration: 700,
},
}),
[waitInViewport, inView]
);
return (
<animated.div className={`fade-wrapper ${className}`} style={style} ref={observe}>
{children}
</animated.div>
); |
react-spring/packages/core/src/hooks/useSprings.ts Lines 131 to 153 in 3d2523d
I debug deeply and found it probably related to the updates list is empty in strict mode second render function call.useMemo only called in the first render function and skip in the secord one!It seems like a anti-pattern to modify render function scope variable in useMemo . Such variable should be wrapped in useRef I guess.Hope this infomation help. @joshuaellis |
Which react-spring target are you using?
@react-spring/web
@react-spring/three
@react-spring/native
@react-spring/konva
@react-spring/zdog
What version of react-spring are you using?
9.7.3
What's Wrong?
When using
<StrictMode>
in React 18, the event handlers (onStart
,onRest
...) don't get called.To Reproduce
In the linked StackBlitz project, you can see in the Console that only the
console.log
s in theuseEffect
hook get executed. The event listeners never get called. If you disable StrictMode inindex.tsx
, the event listeners get called as expected.Expected Behaviour
Event listeners get called in StrictMode.
Link to repo
https://stackblitz.com/edit/stackblitz-starters-jphu4a?devToolsHeight=33&file=src%2FApp.tsx
The text was updated successfully, but these errors were encountered: