react-apollo-hooks icon indicating copy to clipboard operation
react-apollo-hooks copied to clipboard

bug causing nested entity to be null after second render post network response

Open alidcast opened this issue 6 years ago • 0 comments

say I have a query that eager loads its nested relation

entity {
  id 
  nestedEntity {
   id
  }
}

when receiving response from server, the payload may look like this

[{ id: 1, nestedEntity: { id: 123 }]

but after the second (post network response, loading: false) render, the response becomes:

[{ id: 1, nestedEntity: null]

For whatever reason the nestedEntity is set to null, though the original network response returned a payload for it.

I'm guessing this is a caching issue, though changing the network status options did not seem to help either.

I was able to find this temporary fix:

  const normalizedRes = useRef({ networkStatus: -1 }) 
  const res  = useQuery(entityQuery)
  if (res.networkStatus !== normalizedRes.current.networkStatus) {
    normalizedRes.current = res
  }
  return normalizedRes.current

alidcast avatar May 08 '19 13:05 alidcast