-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Don't call reobserve
when changing most options in useQuery
and instead apply them
#12681
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
Conversation
🦋 Changeset detectedLatest commit: b75c2d7 The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
src/core/ObservableQuery.ts
Outdated
newOptions: Partial<ObservableQuery.Options<TData, TVariables>> | ||
) { | ||
const mergedOptions = compact(this.options, newOptions || {}); | ||
assign(this.options, mergedOptions); | ||
|
||
if (this.options.fetchPolicy === "standby") { |
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 mimics what reobserve
does so that polling doesn't continue.
commit: |
: T extends SnapshotStream<infer Snapshot, any> ? | ||
(options: ToRerenderWithSimilarSnapshotOptions<Snapshot>) => Promise<R> | ||
(options?: ToRerenderWithSimilarSnapshotOptions<Snapshot>) => Promise<R> |
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.
It looks like the implementation allows has this argument as optional so I updated this to work the same.
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.
Yup, that was the intention, thank you for catching that!
size-limit report 📦
|
@@ -946,11 +946,15 @@ Did you mean to call refetch(variables) instead of refetch({ variables })?`, | |||
} | |||
|
|||
/** @internal */ | |||
public silentSetOptions( | |||
public applyOptions( |
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 old name was never my favorite. Hope this is ok. Sorry for the noise 😆
.changeset/many-seas-call.md
Outdated
- `query` | ||
- `variables` | ||
- `skip` | ||
- Changing `fetchPolicy` from `standby` to a different `fetchPolicy` |
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.
- Changing `fetchPolicy` from `standby` to a different `fetchPolicy` | |
- Changing `fetchPolicy` from or to `standby` |
src/react/hooks/useQuery.ts
Outdated
function shouldReobserve<TData, TVariables extends OperationVariables>( | ||
previousOptions: Readonly<WatchQueryOptions<TVariables, TData>>, | ||
options: Readonly<WatchQueryOptions<TVariables, TData>> | ||
) { | ||
return ( | ||
previousOptions.query !== options.query || | ||
!equal(previousOptions.variables, options.variables) || | ||
(previousOptions.fetchPolicy === "standby" && | ||
options.fetchPolicy !== "standby") | ||
); | ||
} |
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.
Should this whole logic maybe go into applyOptions
? It doesn't really hurt and also could lead to some of the logic in InternalQueryReference.applyOptions
being removed 🤔
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.
Discussed in person. We don't want to move here so that useLazyQuery
doesn't get reobserve
behavior when rerendering with new options before calling execute
. execute
is the catalyst that will potentially kick off the request (since it calls reobserve
). Keeping it out of applyOptions
will ensure we have more control over which behavior to use based on the hook using it.
: T extends SnapshotStream<infer Snapshot, any> ? | ||
(options: ToRerenderWithSimilarSnapshotOptions<Snapshot>) => Promise<R> | ||
(options?: ToRerenderWithSimilarSnapshotOptions<Snapshot>) => Promise<R> |
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.
Yup, that was the intention, thank you for catching that!
7ff3b66
to
9577cd7
Compare
|
||
await expect(renderStream).toRerenderWithSimilarSnapshot({ | ||
// We waited 50ms before, so waiting another 50ms + 50ms = 100ms | ||
timeout: 50, |
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.
timeout: 50, | |
timeout: 55, |
This will get very flaky in tests otherwise.
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.
9577cd7
to
fe8f0fa
Compare
Fixes #11835
Changing most options for
useQuery
no longer callsreobserve
to avoid network requests when unnecessary. Instead the options are applied to the next fetch.