-
-
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
Rewrite RTKQ internal subscription lookups and subscription syncing #3824
Rewrite RTKQ internal subscription lookups and subscription syncing #3824
Conversation
- Changed `subscriptionUpdated` from a microtask to a 500ms throttle - Exposed the RTKQ internal middleware state to be returned via an internal action, so that hooks can read that state directly without needing to call `dispatch()` on every render. - Reworked tests to completely ignore `subscriptionsUpdated` in any action sequence checks due to timing changes and irrelevance - Fixed case where `invalidateTags` was still reading from store state
Review or Edit in CodeSandboxOpen the branch in Web Editor • VS Code • Insiders |
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 e0c3869:
|
@@ -681,6 +682,27 @@ export function buildHooks<Definitions extends EndpointDefinitions>({ | |||
Definitions | |||
> | |||
const dispatch = useDispatch<ThunkDispatch<any, any, UnknownAction>>() | |||
const internalStateRef = useRef<InternalMiddlewareState | null>(null) |
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 logic in the hooks file hurts a bit. Maybe the middleware could return a hasSubscription
function instead of the internal state itself?
const subscriptionSubState = | ||
internalState.currentSubscriptions[queryCacheKey] ?? {} |
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.
Thank you for catching this one!
2fc1ee6
to
e0c3869
Compare
subscriptionUpdated
from a microtask to a 500ms throttleExposed the RTKQ internal middleware state to be returned via aninternal action, so that hooks can read that state directly without
needing to call
dispatch()
on every render.Updated the
batchActions
middleware to return aSubscriptionSelectors
object with{getSubscriptions, getSubscriptionCount, isRequestSubscribed}
, and used that in the hook (and tests)subscriptionsUpdated
in anyaction sequence checks due to timing changes and irrelevance
invalidateTags
was still reading from store state