Reducers without immer
See original GitHub issueHey,
I’m aware of the position of the maintainers regarding disabling immer, as stated in #242 and #183. However, both of those discussions are the top google results when searching redux toolkit without immer
. After some time, I realized that I could both keep RTK and add additional reducers without immer, which is required in edge cases for performance reasons*. I’ve created a gist with the solution, if you’re interested it could be nice to add the gist to the end of the discussion in #242, as that is the top-level result and I’m sure many people have been landing there without a clear way to solve their issue.
Here is the link: https://gist.github.com/romgrk/bb16d7b8d3827481d04eb535e8d1bc74
This issue can be closed.
* I’m not sure what goes on inside immer’s produce()
, but in the edge-case I encountered, using a raw reducer took the runtime of a single action from ~200ms to ~2ms.
Issue Analytics
- State:
- Created a year ago
- Reactions:3
- Comments:16 (6 by maintainers)
Freezing the data brings the performance to the same level as not using immer. I’ll send a PR to add the detail to the doc. I know it’s been said enough, but I really wish there was a way to use this module without immer; it adds too much magic to be comfortable to use.
Can you share a fully running sandbox or repo that shows this behavior, with a meaningful dataset?
Also, note that Immer does recursively freeze data by default. Can’t tell if that’s the issue here because there’s not enough of the perf capture shown in those screenshots. However, if that is the issue, note that you can do an
Object.freeze(value)
on the top-level object to prevent Immer from recursing:https://immerjs.github.io/immer/freezing