-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Fix issue with useQuery polling when skip was initialized with true
#13155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
b670d83
54d6136
e4aa12f
0c30515
1fda1f1
4e167ba
7a72816
816911d
6f30ec5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@apollo/client": patch | ||
| --- | ||
|
|
||
| Fix an issue where `useQuery` would poll with `pollInterval` when `skip` was initialized to `true`. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2357,6 +2357,53 @@ describe("useQuery Hook", () => { | |
| } | ||
| }); | ||
|
|
||
| // https://github.com/apollographql/apollo-client/issues/13154 | ||
| it("doesn't poll when initially skipped", async () => { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: it("does not poll when initially skipped")
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Hardanish-Singh I'm fine with it the way it is. The contraction is perfectly fine. In the future, I'd appreciate if you didn't add these kinds of review comments. They are just noise. I'm happy to answer specific questions or concerns you may have if you're looking at a PR, but please avoid |
||
| const query = gql` | ||
| query { | ||
| hello | ||
| } | ||
| `; | ||
|
|
||
| const requestHandler = jest.fn< | ||
| ReturnType<ApolloLink.RequestHandler>, | ||
| Parameters<ApolloLink.RequestHandler> | ||
| >(() => of({ data: { hello: "world" } })); | ||
|
|
||
| const cache = new InMemoryCache(); | ||
| const client = new ApolloClient({ | ||
| cache, | ||
| link: new ApolloLink(requestHandler), | ||
| }); | ||
|
|
||
| using _disabledAct = disableActEnvironment(); | ||
| const renderStream = await renderHookToSnapshotStream( | ||
| () => useQuery(query, { pollInterval: 80, skip: true }), | ||
| { | ||
| wrapper: ({ children }) => ( | ||
| <ApolloProvider client={client}>{children}</ApolloProvider> | ||
| ), | ||
| } | ||
| ); | ||
| const { takeSnapshot } = renderStream; | ||
|
|
||
| { | ||
| const result = await takeSnapshot(); | ||
|
|
||
| expect(result).toStrictEqualTyped({ | ||
| data: undefined, | ||
| dataState: "empty", | ||
| loading: false, | ||
| networkStatus: NetworkStatus.ready, | ||
| previousData: undefined, | ||
| variables: {}, | ||
| }); | ||
| } | ||
|
|
||
| await expect(takeSnapshot).not.toRerender({ timeout: 100 }); | ||
| expect(requestHandler).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it("should start polling when changing skipToken to options", async () => { | ||
| const query = gql` | ||
| { | ||
|
|
||
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.
Would it make sense to add a similar check inside of
maybeFetch, too?Currently all code paths changing any of those seem to be covered, but it seems like it could easily happen that some code path might run out of sync again.
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.
0c305150c30515