You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
RTK Query - useLazyQuery method call returns undefined when called from an unmounted component #5173
changed the title [-]RRK Query - UseLazyQuery method call returns undefined when called from an unmounted component[/-][+]RTK Query - UseLazyQuery method call returns undefined when called from an unmounted component[/+]on Jan 20, 2026
some component initiates a time-consuming operation on BE so BE returns ID of request and then we have separate endpoint for polling the status of operation
this component might be unmounted (e.g. if user goes to another page)
we poll via setTimeout up to N minutes and once operation status is successful we notify the customer
To be fair there are 2 issues in the case itself:
Definitely not the best UX (user might work on something and then he gets notification about operation initiated 15 minutes ago while he already completely out of context)
Not sure that we need RTKQ here at all. Our strategy for components is simple rule of thumb - RTKQ is good, axios is bad but maybe this is literally the case when we shoot ducks from bazooka.
Though I can imagine when in simple cases this behavior might cause issues - requests might take e.g. 20 seconds just because of some network issue and within this timeframe user might go to another page causing unmount of the query initiator. If the request was supposed to update the state then it might cause stale data. E.g. something like that in some change or click handler:
awaitsomeSlowRequest().unwrap()// request above took 20 seconds, user left the page and component is unmounted nowconstdata=awaitsomeLazyQuery().unwrap()// try to update e.g. LS, dispatch any action, whatever and TS gives no hint that `data` might be `undefined`
Also it seems like some kind of regression - we recently updated our core libs and this issue appeared. We have been using RTKQ for more than a year without any issues.
changed the title [-]RTK Query - UseLazyQuery method call returns undefined when called from an unmounted component[/-][+]RTK Query - `useLazyQuery` method call returns `undefined` when called from an unmounted component[/+]on Nov 2, 2026
Activity
markerikson commentedon Dec 30, 2025
That's a really weird edge case :) tbh this is not going to be a particular priority to look at due to how obscure it is.
What's the real-world situation where this is happening? What are you hoping to do with the data after it's returned?
[-]RRK Query - UseLazyQuery method call returns undefined when called from an unmounted component[/-][+]RTK Query - UseLazyQuery method call returns undefined when called from an unmounted component[/+]jtoming830 commentedon Feb 3, 2026
Seems we have same issue.
Case is following:
setTimeoutup to N minutes and once operation status is successful we notify the customerTo be fair there are 2 issues in the case itself:
Though I can imagine when in simple cases this behavior might cause issues - requests might take e.g. 20 seconds just because of some network issue and within this timeframe user might go to another page causing unmount of the query initiator. If the request was supposed to update the state then it might cause stale data. E.g. something like that in some
changeorclickhandler:Also it seems like some kind of regression - we recently updated our core libs and this issue appeared. We have been using RTKQ for more than a year without any issues.
[-]RTK Query - UseLazyQuery method call returns undefined when called from an unmounted component[/-][+]RTK Query - `useLazyQuery` method call returns `undefined` when called from an unmounted component[/+]