-
Notifications
You must be signed in to change notification settings - Fork 222
Conversation
@@ -52,10 +53,11 @@ export default function useGraphQLDocument< | |||
[document, loadDocument], | |||
); | |||
|
|||
return [ | |||
document, | |||
useAsyncAsset( |
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.
I also moved this back into this hook, where it feels more appropriate than the useQuery
hook
useAsyncAsset(id); | ||
if (typeof window === 'undefined' && skip) { | ||
return createDefaultResult(client, variables); | ||
} |
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 is the early bailout
[queryObservable, client, variables], | ||
() => createDefaultResult(client, variables, queryObservable), | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
[queryObservable, client, serializedVariables], |
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 is the fix for the result changing when variables were deep equal
afterEach(() => { | ||
teardownAsyncReactTasks(); | ||
}); | ||
|
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.
No longer needed
const wrapper = new CustomRoot(element, context, { | ||
render: element => render(element, context, options), | ||
resolveRoot: root => root.find(element.type), | ||
}); |
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 basic gist of this fix is that instead of a Root
around the result of render(element)
, the Root
just gets the raw element under test, and we thread through the render
to the component that eventually renders the component to the DOM, since it is in charge of handling updated props.
This PR makes a couple of small improvements to react-graphql:
skip
touseQuery
on the server, it no longer attempts to fetch anything at all (before, it would try to resolve an async GraphQL document, mark it as used, and actually run the query)useQuery
is referentially equal (it always returned the same data, but the object itself was changed between renders, which is a bummer because it's a common one to use as an input to otheruseMemo
s)In fixing (2), I also made an improvement to
react-testing
. Previously, callingsetProps
on a custom mounted element would set props on whatever the component was wrapped in, not the component itself. The changes toreact-testing
makes it so that only the element itself is updated with new props, which removes the need for hacks like https://github.com/Shopify/web/blob/master/tests/modern/AppContext.tsx#L63-L66.