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

[bug]: useTransition breaks in <StrictMode> with React 18 #1828

Closed
1 of 5 tasks
Tracked by #1563
jamesknelson opened this issue Jan 30, 2022 · 3 comments · Fixed by #1875
Closed
1 of 5 tasks
Tracked by #1563

[bug]: useTransition breaks in <StrictMode> with React 18 #1828

jamesknelson opened this issue Jan 30, 2022 · 3 comments · Fixed by #1875
Labels
area: core relates to core classes // parts of the library kind: bug Something isn't working released in beta this has been released on a beta

Comments

@jamesknelson
Copy link

jamesknelson commented Jan 30, 2022

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?

react-spring 9.4.2 (also tested with 9.4.3-beta.0 and 9.3.3)

What's Wrong?

tl;dr, changes to how <StrictMode> work in React 18 seem to have broken useTransition.

When transitioning, the first item's leave transition completes successfully, but the new item never enters. It appears to get stuck in the mount phase.

This is easier to see in practice - the linked CodeSandbox demo is only ~50 lines and shows the problem clearly.

If I had to hazard a guess at what is going on here, it's likely due to the fact that React 18's <StrictMode> now immediately calls the cleanup function of all effects on mount, before calling the effect callbacks a second time.

For example https://github.com/pmndrs/react-spring/blob/master/packages/core/src/hooks/useTransition.tsx#L106 looks like it may break in React 18's StrictMode, as the cleanup function will now be called immediately on mount.

I've had a quick go at fixing this, but wasn't able to get any results in the half-an-hour or so I spent on this. For now, I've disabled StrictMode as a workaround.

To Reproduce

Use useTransition within a component rendered inside a <StrictMode> in React 18 (currently tested with rc.0 and some newest "next" releases).

Expected Behaviour

useTransition should work with <StrictMode> in React 18.

Link to repo

https://codesandbox.io/s/jovial-microservice-n35r6?file=/src/index.js

@jamesknelson jamesknelson added the template: bug This issue might be a bug label Jan 30, 2022
@joshuaellis joshuaellis added kind: bug Something isn't working area: core relates to core classes // parts of the library and removed template: bug This issue might be a bug labels Apr 5, 2022
@joshuaellis
Copy link
Member

I've just released 9.4.5-beta.1 that should address this issue, please give it a go and let me know if it solves your issue.

@joshuaellis joshuaellis reopened this Apr 14, 2022
@joshuaellis joshuaellis added this to To do in Picked for development via automation Apr 14, 2022
@joshuaellis joshuaellis added the released in beta this has been released on a beta label Apr 14, 2022
@joshuaellis joshuaellis moved this from To do to In beta / alpha in Picked for development Apr 14, 2022
@jafin
Copy link

jafin commented Apr 15, 2022

@joshuaellis beta.1 worked here with React 18 strictmode. Thank you!

@morlay
Copy link

morlay commented Apr 15, 2022

@joshuaellis With 9.4.5-beta.1, everything works again 🥳 . Thank you!

Picked for development automation moved this from In beta / alpha to Done May 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: core relates to core classes // parts of the library kind: bug Something isn't working released in beta this has been released on a beta
Projects
No open projects
Development

Successfully merging a pull request may close this issue.

4 participants