Skip to content

When calling a useTransition startTransition callback outside of event handlers, isPending is never set to true #17272

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
kentcdodds opened this issue Nov 4, 2019 · 9 comments · Fixed by #17382

Comments

@kentcdodds
Copy link

Do you want to request a feature or report a bug?

Bug

What is the current behavior?

isPending is never set to true when calling startTransition within useEffect, but it does work properly when within a useLayoutEffect.

https://codesandbox.io/s/usetransition-useeffect-issues-p1j9s

Here's the correct behavior (accomplished via useLayoutEffect):

good

Here's the incorrect behavior (via useEffect):

bad

Note the difference is that the opacity never changes to 0.4 (which is determined based on the isPending state).

What is the expected behavior?

I expect them to both behave the same (at least as far as the user can observe).

Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?

  • react@0.0.0-experimental-f6b8d31a7
  • react-dom@0.0.0-experimental-f6b8d31a7
@dai-shi
Copy link
Contributor

dai-shi commented Nov 4, 2019

I guess startTransition is never intended to be used in effects. I didn't expect it even works.
Looking at the doc again,
https://reactjs.org/docs/concurrent-mode-reference.html#usetransition
Hmm, it doesn't clearly say so. 😓

@leonardoelias
Copy link

Ok @dai-shi but the use cases is interesting.

@gaearon
Copy link
Collaborator

gaearon commented Nov 5, 2019

Do you think this is the same as #17279?

@kentcdodds
Copy link
Author

Yes, I believe that's the same issue.

@Lenne231
Copy link

Lenne231 commented Nov 7, 2019

Hello,

I think I have a similar issue when using useTransition with useReducer. When useReducer returns a new value I would like to create a new resource. I tried to use useMemo for this, but I don't even have an idea where to put startTransition ...

https://codesandbox.io/s/usetransition-usereducer-i03wk

@Lam9090
Copy link

Lam9090 commented Nov 11, 2019

@kentcdodds you can see the isPending is true if the timeoutMS is bigger than 5100 when calling in useEffect.

@jhuleatt
Copy link

jhuleatt commented Nov 15, 2019

I'm seeing the same behavior as @lintuming - setting timeoutMS to a value of 5200 or higher causes isPending to fire reliably in the original CodeSandbox: https://codesandbox.io/s/usetransition-useeffect-issues-pgzo9?fontsize=14&hidenavigation=1&theme=dark

@gaearon
Copy link
Collaborator

gaearon commented Nov 15, 2019

That is a bug we need to fix regardless.

@gaearon gaearon changed the title When calling a useTransition startTransition callback in useEffect, isPending is never set to true When calling a useTransition startTransition callback outside of event handlers, isPending is never set to true Nov 15, 2019
@acdlite
Copy link
Collaborator

acdlite commented Nov 15, 2019

Fixed by #17382. Updated Sandbox: https://codesandbox.io/s/usetransition-useeffect-issues-ccq5e

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants