question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

RTKQ: Mass rejected queries

See original GitHub issue

I’ve noticed many rejected queries in console log

action api/executeQuery/rejected
[Log]  action     – {type: "api/executeQuery/rejected", payload: undefined, meta: Object, …} (main.js, line 136707)
{type: "api/executeQuery/rejected", payload: undefined, meta: Object, error: {name: "ConditionError", message: "Aborted due to condition callback returning false."}}Object

Since I cannot use selectors with RTK Query(#1182) I subscribe each small component to same query with selectFromResult option to retrieve my data slice. To be more specific I load all job applications with one query(GET /applications?campaignId=123) then I have long datatable with each application as a row. Each row contains few micro forms eg. candidate name to enter name and push enter to post data. So each microform subscribed to the same GET /applications?campaignId=123 request then it finds application by id and reads one field(name) from searched application item. Because of it I see 1400 rejected requests in console and everything becomes unresponsive. I think even if I turn logger off it still gonna overload redux state with thousands of dispatched actions.

Seems like I need to find another way to select data from API queries or pass query results from root element to child over and over again.

Could it be a bottleneck if I subscribe each list item to query hook?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:12 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
markeriksoncommented, May 28, 2022

Both are true.

It’s true that every line of code that runs, including adding a useSelector call, has a cost. Having 1500 subscribers is more expensive than having 10 subscribers, in that there’s now 1500 functions that will run after every dispatch. (Which is why we encourage selectors to be as fast as possible.)

But it’s also true that having more components connected, at lower portions in the tree, generally results in fewer React components re-rendering per UI update. And in general, the cost of re-rendering N React components is more expensive than the cost of having N store subscriber functions.

So, there is no one single answer, but as a general rule, more connected components results in less total re-rendering cost overall.

All that said: part of the issue here seems to be with how RTK Query manages finding cached state and dispatching that “rejected” action. I’m sure Lenz had a good reason for doing that, but tbh I’m not sure that’s really what we want to have happening, and it may be worth rethinking how we handle that.

1reaction
phryneascommented, Jun 17, 2021

They are not “internal”, just not super-exposed 😃 We do not expose those not-so-often-used hooks on the api object itself, but just on api.endpoints.endpointName to not totally clutter the api object with hooks.

As for the TS: yeah, it’s a tradeoff. I think we show it in the svelte example, but we could add it there somewhere…

Read more comments on GitHub >

github_iconTop Results From Across the Web

rtk-query mutation rejected - Stack Overflow
A rejected action in the devtools, can mean a lot of things, including "we don't need to make a new request for this...
Read more >
Automated Re-fetching | Redux Toolkit
The concept can be used to inform RTK Query that when a particular failure has been encountered, to provide a specific tag for...
Read more >
Review RTKQ "reject on existing query" behavior · Issue #2501
RTKQ uses createAsyncThunk inside, and I think we use condition to check if a query is already in progress and we should bail...
Read more >
Error Handling | RTK Query
If your query or mutation happens to throw an error when using fetchBaseQuery, it will be returned in the error property of the...
Read more >
RTK Query Best Practices - Medium
The main method of refreshing data with RTKQ is using Cache Tags. It's most helpful when dealing with resources that have both query...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found