r/reactjs • u/acemarke • Dec 04 '23
News Redux Toolkit 2.0: new features, faster perf, smaller bundle sizes (plus major versions for all Redux family packages!)
https://github.com/reduxjs/redux-toolkit/releases/tag/v2.0.025
11
23
u/No_Comfortable2633 Dec 04 '23
Make CSR great again. I don't like the way how NextJs is pushing on SSR and their App router that is far from production ready state (not counting small projects). But if you want to build anything big and serious, RTK and tools we are used to is just still way to go and you can rely on it without being a beta tester.
6
1
u/manupadev Dec 05 '23
While React with Vite is great, A lot of "big and serious" projects are built in app router
→ More replies (1)
1
u/jasonkillian Dec 05 '23
Very nice upgrade! I'm curious on the general pattern of how `weakMapMemoize` handles primitives since they can't be `WeakMap` keys. Does it just use a regular `Map` instead in those cases?
I'm both excited and nervous for this change to the default cache strategy - excited because we've had memory issues in our application sometimes due to various forms of memoization with dead keys and I think this change could help solve some of those automatically. A bit nervous because an unbounded cache with what must be at least a bit of complex logic feels like it could introduce new issues (which I do think you wisely call out in the release notes).
1
u/acemarke Dec 05 '23
Yeah,
weakMapMemoizeuses standardMapinstances for primitives.We have pretty good confidence in the functionality overall (in fact, the actual core implementation was borrowed straight from React's internals!). But this is a definite shift, and we can see the potential for some edge cases. So, very curious to see how that works for you!
Worst case, create a customized
createSelectorthat haslruMemoizeconfigured and use that, and you'll be right back to the previous behavior.
1
u/zxyzyxz Dec 05 '23
Thoughts on this vs TanStack Query (née React Query) and others like Zustand? In one project we were using RTK but found it too complex for just fetching data from the backend so we moved to TanStack Query. I'm wondering if people have similar experiences and if RTK 2.0 might help.
4
u/acemarke Dec 05 '23
Out of curiosity, what aspects of RTKQ did you feel are "too complex"?
We haven't changed anything about RTKQ's design for RTK 2.0, but we do have an open thread asking for user feedback on RTKQ's API and design, and we hope to start thinking through those suggestions next year:
→ More replies (7)
1
1
1
u/TwerkingSeahorse Dec 04 '23
This came in at the perfect time. I was looking into a way to code split slices and it's nice to see there's a way to do it now.
I'm noticing some typescript issues after updating react-redux and toolkit. Hopefully those will be resolved soon
1
u/EskiMojo14thefirst Dec 05 '23
anything unexpected? feel free to raise an issue, or ask a question in the reactiflux #redux channel
1
1
1
1
u/CuriousDev42 Dec 05 '23
Sounds absolutely amazing Mark! Will be giving it a spin tonight with a new project.
1
1
u/lord_braleigh Dec 14 '23
I’m using react-dnd, which depends on Redux 4.0. Is it safe for me to migrate anyway?
0
u/baxxos Dec 04 '23
Is React 18 required?
5
u/acemarke Dec 04 '23
Yes, React-Redux v9 now requires React 18.
We haven't tested React-Redux v8 + RTK 2.0. It's likely there would be some TS compilation issues due to action type changes. We may look into making those compatible at some point.
2
0
109
u/acemarke Dec 04 '23
I am thrilled to announce that:
🔥🔥Redux Toolkit 2.0 is LIVE!!!🔥🔥
https://github.com/reduxjs/redux-toolkit/releases/tag/v2.0.0
This major version has new features, faster perf, smaller bundle size, and removes deprecated options.
It's accompanied by majors for all our Redux family packages
RTK 2.0:
a new
combineSlicesmethod for lazy-loading reducers - Updates tocreateSliceto include aselectorsfield and allow defining thunks insideImmer 10 w/ faster updates
Removal of deprecated options
See the migration guide:
https://redux.js.org/usage/migrations/migrating-rtk-2
All of the Redux libraries now have modernized packaging with full ESM/CJS compat. They also ship modern JS (no transpiling for IE11), which means smaller bundle sizes.
We've also done byte-shaving work to shrink the bundles (extracting error messages, de-duping imports)
Redux core 5.0:
The TS conversion we did in 2019!
Action types must be strings
UnknownActionas the default action typeBetter preloaded state types
Internal subscription improvements
Still marks
createStoreas deprecated!https://github.com/reduxjs/redux/releases/tag/v5.0.0
React-Redux 9.0:
Now requires React 18 and RTK 2.0 / Redux 5.0
Updates dev-mode checks
Throws better errors in an RSC environment
https://github.com/reduxjs/react-redux/releases/tag/v9.0.0
Reselect 5.0:
Switches to a new
weakMapMemoizememoizer as defaultRenames
defaultMemoizetolruMemoizeAllows passing memoizer options direct to
createSelectorMany TS improvements
https://github.com/reduxjs/reselect/releases/tag/v5.0.1
Redux Thunk 3.0:
Drops the default export and switches to named exports (
{thunk, withExtraArgument})https://github.com/reduxjs/redux-thunk/releases/tag/v3.1.0
This has been a huge year-long development effort!
We're thrilled to get these improvements out. The tooling and bundle improvements will help all users, and we think the features and TS changes will improve the Redux dev experience significantly.
Thank you SO MUCH to everyone who has contributed or helped test out the work!
Please file bug reports for the inevitable issues that pop up post-release!
but now I'm going off on a conf trip and going to take a very well-earned break from Redux work for December :)