Search code examples
reduxredux-toolkitrtk-query

High CPU usage by using onQueryStarted handler


I'm learning RTK query with Redux-toolkit. Reading this article from docs: https://redux.js.org/tutorials/essentials/part-8-rtk-query-advanced#implementing-optimistic-updates I wrote exactly the same blog from documentation, but got a big issue with CPU.

Even if I don't run the project, but my IDE is just open,- my CPU usage is loaded by 80-90% from the beginning. And onQueryStarted handler causes this. Because when I comment this handler out, - CPU usage immediately gets loaded by few %.

I tried to write blog from documentation by hands, but even If I do copy-paste entire apiSlice from redux documentation, - the problem is still the same.

So I will give a link to this slice form docs:

  1. https://codesandbox.io/s/github/reduxjs/redux-essentials-example-app/tree/checkpoint-6-rtkqConversion/?from-embed=&file=/src/features/api/apiSlice.js
  2. This part of code is the reason of my high CPU usage:
const patchResult = dispatch(
          apiSlice.util.updateQueryData('getPosts', undefined, (draft) => {
            // The `draft` is Immer-wrapped and can be "mutated" like in createSlice
            const post = draft.find((post) => post.id === postId)
            if (post) {
              post.reactions[reaction]++
            }
          })
        )

Because if I comment this out, - everything becomes OK immidiately. I created an issue for redux developers (with short video attached to show the issue): https://github.com/reduxjs/redux-toolkit/issues/3346

But 5 days already passed without answer. I want to learn this library, I like the concepts and idea, but I simply can't.

Maybe somebody already got this sort of problem and have some experience. Any answer will be appreciated. Thanks in advance!


Solution

  • The problem was caused by default plugin in php storm IDE. Even after I turned it ON again, - everything is fine. Reloading IDE before didn't help, but this plugin does. Code works fine, no problems with CPU enter image description here