-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
feat(query): Adds subscribe option to prefetch, automatically unsubscribes if not present [#1283] #1938
base: master
Are you sure you want to change the base?
feat(query): Adds subscribe option to prefetch, automatically unsubscribes if not present [#1283] #1938
Conversation
…ribes if not present [reduxjs#1283]
if (subscribe) { | ||
return result | ||
} | ||
result.unwrap().finally(result.unsubscribe) |
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 catch and swallow the error?
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 81d929a:
|
@@ -430,6 +433,8 @@ In the case of an unhandled error, no tags will be "provided" or "invalidated".` | |||
const hasMaxAge = ( | |||
options: any | |||
): options is { ifOlderThan: false | number } => 'ifOlderThan' in options | |||
const handlePrefetchSubscription = (result: QueryActionCreatorResult<any>) => | |||
result.unwrap().finally(result.unsubscribe) |
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 opted to unwrap
because that seems closer aligned to the lifecycle the end-user is expecting. My hope is it also sidesteps worrying about keepUnusedDataFor
being set to 1 second or other cache races I can't think of.
I would keep the "automatic unsubscribe" out of this PR in general and keep the scope of this to only adding a The rest should be done in a separate PR handling #1282 that would automatically subscribe all queries but automatically unsubscribe them after the thunk has resolved if |
References: #1283