relay icon indicating copy to clipboard operation
relay copied to clipboard

`refetch({}, "network-only")` suspends, even when inside `startTransition`

Open Zizico2 opened this issue 7 months ago • 4 comments

Reporting issues with Relay

refetch({}, "network-only") always causes React to suspend, even when inside startTransition. This is annoying, specially when rendering lists with usePaginationFragment, where you would want to show the existing items, while re-fetching the new ones, and not jump to a suspend boundary. Furthermore, I think the difference in behavior for different FetchPolicys is not that intuitive for a beginner. And loadNext, for example, will never suspend. I think everything that makes a network request should suspend, to avoid these confusions, and the user should be able to opt out of it with startTransition. This was the approach Apollo took (https://github.com/apollographql/apollo-client/issues/10676).

I realize this might be too dramatic of a change, but at least we should be able to use startTransition to prevent refetch from suspending.

Zizico2 avatar Nov 16 '23 17:11 Zizico2

@Zizico2 did you ever figure out a fix for this?

Seems like refetch ignores startTransition regardless of the fetchPolicy.

I'm on 16.2.0.

richardwu avatar Apr 21 '24 03:04 richardwu

Was useTransition introduced before React 18? You may be importing an API compatible version of useTransition from {somewhere} that's actually a noop.

steveluscher avatar Apr 21 '24 04:04 steveluscher

https://cdn.jsdelivr.net/npm/[email protected]/cjs/react.development.js

useTransition – not there.

steveluscher avatar Apr 21 '24 04:04 steveluscher

Sorry I meant 16.2.0 react-relay. I'm on 18.2.0 react.

richardwu avatar Apr 21 '24 04:04 richardwu