-
Notifications
You must be signed in to change notification settings - Fork 222
Conversation
@@ -38,12 +38,16 @@ export default function useQuery< | |||
} = options; | |||
const client = useApolloClient(overrideClient); | |||
|
|||
if (typeof window === 'undefined' && skip) { | |||
if ((typeof window === 'undefined' && skip) || fetchPolicy === 'no-cache') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this early return actually breaks react hook rule. Is there anyway not to do this anymore?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The rules of hooks don't matter for server rendering. They only exist so that a single component, when updated, calls hooks in the same order, but in server renders, the entire component is thrown out each time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that make sense to me, so this is really a dev experience thing to for consumer of this package to understand why they would be getting this warning.
bf591d9
to
db6378b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 really appreciate the extra tests 🙏
There are two types of
fetchPolicies
that ignore the cache:network-only
andno-cache
. We aren't currently handling either of them well: AFAICT, in both cases queries lead to infinite looping while trying to resolve during SSR, because the client will make a fresh query every time. This PR is a stab at addressing them that I think makes sense. In the case ofnetwork-only
, we can transform it to becache-first
in SSR, so that it will save to cache and re-use for all subsequent server renders.no-cache
has a promise about not putting stuff in the cache, so for those, I've updated the code to consider them equivalent toskip
ped queries.cc/ @rox163 while I was playing with this locally, it reduced the number of render loops needed for products pages to just 3 (one for the first set of queries, one for the queries rendered by the product show page, and one last one where it finds no more queries to resolve).