jotai icon indicating copy to clipboard operation
jotai copied to clipboard

Issue: urql.atomWithMutation causes suspense on load

Open jrobber opened this issue 3 years ago • 2 comments

Any component that uses an atom that is using atomWithMutation will cause a suspense fallback to be rendered and will stay rendered indefinitely (maybe it clears on mutation, but I can't see the UI to get the mutation to go).

My atom:

export const saveSearchHistoryAtom = atomWithMutation<IAddSearchHistoryMutation, IAddSearchHistoryMutationVariables>(
  (get)=>  AddSearchHistoryDocument,
  (get) => get(urqlClientAtom)
)

Component:

function SearchRecentlyViewed() {
  const [saveSearchResp, saveSearchHistory] = useAtom(saveSearchHistoryAtom )
  ....
}

jrobber avatar Jan 07 '22 21:01 jrobber

Nice catch. I didn't know what behavior is expected. What should the the initial value if we don't suspend? Feel free to also try playing with the urql.atomWithMutation impl.

dai-shi avatar Jan 08 '22 01:01 dai-shi

Now, I think, it should be null. I'll work on it some time later.

dai-shi avatar Sep 22 '22 09:09 dai-shi

#1473 will solve this with providing a non-suspense api.

dai-shi avatar Oct 10 '22 13:10 dai-shi