You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Using subscribeToMore with watchQuery's fetchPolicy set to no-cache properly rerenders the component on new subscription data arrival.
Actual outcome:
Using subscribeToMore with watchQuery's fetchPolicy set to no-cache doesn't rerender the component on new subscription data arrival.
How to reproduce the issue:
// index.tsconstdefaultOptions: DefaultOptions={watchQuery: {fetchPolicy: 'network-only',errorPolicy: 'all',},query: {fetchPolicy: 'no-cache',// if set to 'network-only', it workserrorPolicy: 'all',},mutate: {errorPolicy: 'all',},};constclient=newApolloClient({
defaultOptions,// ...});
// Component.tsxconst{
data,
subscribeToMore,}=useQuery<Data>(query,{variables: {
id,},});useEffect(()=>{constunsubscribe=subscribeToMore({document: subscription,variables: { id },updateQuery: (prev,{subscriptionData: {data: subscriptionData}})=>{if(!subscriptionData){returnprev;}console.log('subscriptionData',subscriptionData);// logged in both scenariosreturn{name: {
...prev.name,
...subscriptionData.name,},};},});return()=>unsubscribe();// eslint-disable-next-line react-hooks/exhaustive-deps},[])// component doesn't rerender on new subscription data arrival
updateQuery is a cache write API so this is expected behavior. Your query doesn't rerender because it doesn't respond to cache update when using the no-cache fetch policy. This would explain why switching to network-only will fix the issue.
Totally understand the confusion here since the name updateQuery is a bit misleading here. You'll have to switch to one of the other fetch policies if you want this to work as you expect. Unfortunately it is a breaking change at this point to switch this behavior.
I've noted this down as a potential for improvement in a future major. If you have ideas on how you might see this change, feel free to open a feature request so we can track it. I'm going to go ahead and close this issue since there is nothing more actionable for us to look at. Thanks!
Do you have any feedback for the maintainers? Please tell us by taking a one-minute survey. Your responses will help us understand Apollo Client usage and allow us to serve you better.
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
For general questions, we recommend using StackOverflow or our discord server.
Intended outcome:
Using
subscribeToMore
withwatchQuery
'sfetchPolicy
set tono-cache
properly rerenders the component on new subscription data arrival.Actual outcome:
Using
subscribeToMore
withwatchQuery
'sfetchPolicy
set tono-cache
doesn't rerender the component on new subscription data arrival.How to reproduce the issue:
Versions
The text was updated successfully, but these errors were encountered: