react-spring icon indicating copy to clipboard operation
react-spring copied to clipboard

[bug]: UseSpring() Not firing in NextJS 14

Open hq-aw opened this issue 9 months ago • 2 comments

Which react-spring target are you using?

  • [x] @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.5

What's Wrong?

UseSpring() is not firing in NextJS 14 dev environment.

Using the first example from the docs: https://codesandbox.io/p/devbox/bold-andras-ymxghg

To Reproduce

Use the NextJS 14 Starter, create a simple component with useSpring, run npm run dev

Expected Behaviour

The element should animate.

Link to repo

https://codesandbox.io/p/devbox/bold-andras-ymxghg

hq-aw avatar Mar 12 '25 10:03 hq-aw

Apparently also the case in NextJS 13 https://github.com/pmndrs/react-spring/issues/2146

hq-aw avatar Mar 12 '25 10:03 hq-aw

In Next 14 I was seeing a looped animation not start unless it was rerendered. I used a useEffect to toggle the pause spring prop once hydration (mounting) was complete and that made the animation start correctly even after page hard reload.

ETA: Ha, now it doesn't loop when I do a client side navigation back to the page though.

Stan-Stani avatar Mar 14 '25 17:03 Stan-Stani