openedx / frontend-app-discussions

A React-based micro frontend for the Open edX discussion forums.
GNU Affero General Public License v3.0
6 stars 61 forks source link

fix(deps): update dependency @reduxjs/toolkit to v1.9.7 #616

Closed renovate[bot] closed 7 months ago

renovate[bot] commented 8 months ago

Mend Renovate

This PR contains the following updates:

Package Change Age Adoption Passing Confidence
@reduxjs/toolkit (source) 1.8.0 -> 1.9.7 age adoption passing confidence

Release Notes

reduxjs/redux-toolkit (@​reduxjs/toolkit) ### [`v1.9.7`](https://togithub.com/reduxjs/redux-toolkit/releases/tag/v1.9.7) [Compare Source](https://togithub.com/reduxjs/redux-toolkit/compare/v1.9.6...v1.9.7) This bugfix release rewrites the RTKQ hook TS types to significantly improve TS perf. #### Changelog ##### RTKQ TS Perf A number of users had reported that Intellisense for RTKQ API objects was extremely slow (multiple seconds) - see discussion in [#​3214](https://togithub.com/reduxjs/redux-toolkit/issues/3214) . We did some perf investigation on user-provided examples, and concluded that the biggest factor to slow RTKQ TS perf was the calculation of hook names like `useGetPokemonQuery`, which was generating a large TS union of types. We've rewritten that hook names type calculation to use mapped types and a couple of intersections. In a specific user-provided stress test repo, it dropped TS calculation time by 60% (2600ms to 1000ms). There's more potential work we can do to improve things, but this seems like a major perf improvement worth shipping now. #### What's Changed - chore: Switch 4.9.2-rc to 4.9.5 since 4.9.5 has been released in TypeScript by [@​kahirokunn](https://togithub.com/kahirokunn) in [https://github.com/reduxjs/redux-toolkit/pull/3772](https://togithub.com/reduxjs/redux-toolkit/pull/3772) - Copy of "Work around known TS bug with type inference [#​3761](https://togithub.com/reduxjs/redux-toolkit/issues/3761)" by [@​julian-ford](https://togithub.com/julian-ford) in [https://github.com/reduxjs/redux-toolkit/pull/3777](https://togithub.com/reduxjs/redux-toolkit/pull/3777) - Rework named hooks type (v1.9) by [@​EskiMojo14](https://togithub.com/EskiMojo14) in [https://github.com/reduxjs/redux-toolkit/pull/3769](https://togithub.com/reduxjs/redux-toolkit/pull/3769) **Full Changelog**: https://github.com/reduxjs/redux-toolkit/compare/v1.9.6...v1.9.7 ### [`v1.9.6`](https://togithub.com/reduxjs/redux-toolkit/releases/tag/v1.9.6) [Compare Source](https://togithub.com/reduxjs/redux-toolkit/compare/v1.9.5...v1.9.6) This bugfix release adds a new dev-mode middleware to catch accidentally dispatching an action creator, adds a new listener middleware option around waiting for forks, adds a new option to update provided tags when `updateQueryData` is used, reworks internal types to better handle uses with TS declaration output, and fixes a variety of small issues. ##### Changelog ##### Action Creator Dev Check Middleware RTK already includes dev-mode middleware that check for the common mistakes of accidentally mutating state and putting non-serializable values into state or actions. Over the years we've also seen a semi-frequent error where users accidentally pass an action creator reference to `dispatch`, instead of *calling* it and dispatching the action it returns. We've added another dev-mode middleware that specifically catches this error and warns about it. ##### Additional Options The listener middleware's `listenerApi.fork()` method now has an optional `autoJoin` flag that can be used to keep the effect from finishing until all active forked tasks have completed. `updateQueryData` now has an `updateProvidedTags` option that will force a recalculation of that endpoint's provided tags. It currently defaults to `false`, and we'll likely turn that to `true` in the next major. ##### Other Fixes The `builder.addCase` method now throws an error if a `type` string is empty. `fetchBaseQuery` now uses an alternate method to clone the original `Request` in order to work around an obscure Chrome bug. The immutability middleware logic was tweaked to avoid a potential stack overflow. ##### Types Changes The internal type imports have been reworked to try to fix "type portability" issues when used in combination with TS declaration outputs. A couple additional types were exported to help with wrapping `createAsyncThunk`. ##### What's Changed - create action creator middleware by [@​EskiMojo14](https://togithub.com/EskiMojo14) in [https://github.com/reduxjs/redux-toolkit/pull/3414](https://togithub.com/reduxjs/redux-toolkit/pull/3414) - Implement auto fork joining by [@​ericanderson](https://togithub.com/ericanderson) in [https://github.com/reduxjs/redux-toolkit/pull/3407](https://togithub.com/reduxjs/redux-toolkit/pull/3407) - types: make it easier to wrap createAsyncThunk by [@​shrouxm](https://togithub.com/shrouxm) in [https://github.com/reduxjs/redux-toolkit/pull/3393](https://togithub.com/reduxjs/redux-toolkit/pull/3393) - Fixed Stackoverflow bug if children prop is a ref to root/parent object by [@​cheprasov](https://togithub.com/cheprasov) in [https://github.com/reduxjs/redux-toolkit/pull/3428](https://togithub.com/reduxjs/redux-toolkit/pull/3428) - Fix TransformedResponse type to unwrap promise by [@​EskiMojo14](https://togithub.com/EskiMojo14) in [https://github.com/reduxjs/redux-toolkit/pull/3500](https://togithub.com/reduxjs/redux-toolkit/pull/3500) - Throw error when type is empty in builder.addCase by [@​chawes13](https://togithub.com/chawes13) in [https://github.com/reduxjs/redux-toolkit/pull/3572](https://togithub.com/reduxjs/redux-toolkit/pull/3572) - \[RED-23] fix: Updated type references to resolve portable types issue by [@​tdurnford](https://togithub.com/tdurnford) in [https://github.com/reduxjs/redux-toolkit/pull/3728](https://togithub.com/reduxjs/redux-toolkit/pull/3728) - add option to update provided tags by [@​dutzi](https://togithub.com/dutzi) in [https://github.com/reduxjs/redux-toolkit/pull/3255](https://togithub.com/reduxjs/redux-toolkit/pull/3255) - \[RED-26] Remove Request.clone() usage in fetchBaseQuery by [@​alex-vukov](https://togithub.com/alex-vukov) in [https://github.com/reduxjs/redux-toolkit/pull/3720](https://togithub.com/reduxjs/redux-toolkit/pull/3720) - Try working around TS 4.1 mismatch by [@​markerikson](https://togithub.com/markerikson) in [https://github.com/reduxjs/redux-toolkit/pull/3739](https://togithub.com/reduxjs/redux-toolkit/pull/3739) **Full Changelog**: https://github.com/reduxjs/redux-toolkit/compare/v1.9.5...v1.9.6 ### [`v1.9.5`](https://togithub.com/reduxjs/redux-toolkit/releases/tag/v1.9.5) [Compare Source](https://togithub.com/reduxjs/redux-toolkit/compare/v1.9.4...v1.9.5) This bugfix release includes notable improvements to TS type inference when using the `enhancers` option in `configureStore`, and updates the listener middleware to only check predicates if the dispatched value is truly an action object. #### What's Changed - update to latest remark-typescript-tools by [@​EskiMojo14](https://togithub.com/EskiMojo14) in [https://github.com/reduxjs/redux-toolkit/pull/3311](https://togithub.com/reduxjs/redux-toolkit/pull/3311) - add isAction helper function, and ensure listener middleware only runs for actions by [@​EskiMojo14](https://togithub.com/EskiMojo14) in [https://github.com/reduxjs/redux-toolkit/pull/3372](https://togithub.com/reduxjs/redux-toolkit/pull/3372) - Allow inference of enhancer state extensions, and fix inference when using callback form by [@​EskiMojo14](https://togithub.com/EskiMojo14) in [https://github.com/reduxjs/redux-toolkit/pull/3207](https://togithub.com/reduxjs/redux-toolkit/pull/3207) **Full Changelog**: https://github.com/reduxjs/redux-toolkit/compare/v1.9.4...v1.9.5 ### [`v1.9.4`](https://togithub.com/reduxjs/redux-toolkit/releases/tag/v1.9.4) [Compare Source](https://togithub.com/reduxjs/redux-toolkit/compare/v1.9.3...v1.9.4) This bugfix release includes tweaks to RTKQ options handling, tweaks for perf updates, dependency updates, and updates to our CI tooling. Also, please check out our ongoing RTK 2.0 alpha releases! They have significant improvements to bundle size, ESM/CJS compatibility, TS typings, and reducer update performance. We're looking for real-world feedback on behavior, performance, and any issues you might run into. #### Changelog ##### RTK Query Options Updates Passing `transformResponse` as part of `enhanceEndpoints` can now override the TS type of the original data. `fetchBaseQuery` now properly checks for a global `responseHandler` option. ##### Performance and Internals RTK Query now uses Immer's `original()` to do comparisons inside of `copyWithStructuralSharing`, which should significantly speed up performance when applying changes from re-fetched data. RTKQ's internal `subscriptionUpdated` action is now marked as batchable. We've updated dependencies to Immer 9.0.21, Reselect 4.1.8, and Redux 4.2.1. ##### CI Updates We've added a suite of example apps built with different frameworks such as CRA 4, CRA 5, Next, and Vite, as well as examples that check for compatibility in Node with CJS and ESM modes and with various TS module resolution modes. #### What's Changed - Test published artifacts in CI by [@​markerikson](https://togithub.com/markerikson) in [https://github.com/reduxjs/redux-toolkit/pull/3213](https://togithub.com/reduxjs/redux-toolkit/pull/3213) - Use Git revision in version and add Node CI examples by [@​markerikson](https://togithub.com/markerikson) in [https://github.com/reduxjs/redux-toolkit/pull/3258](https://togithub.com/reduxjs/redux-toolkit/pull/3258) - Add `arethetypeswrong` automated CLI check by [@​markerikson](https://togithub.com/markerikson) in [https://github.com/reduxjs/redux-toolkit/pull/3294](https://togithub.com/reduxjs/redux-toolkit/pull/3294) - Add `attw` CLI option to treat problems as non-errors by [@​markerikson](https://togithub.com/markerikson) in [https://github.com/reduxjs/redux-toolkit/pull/3316](https://togithub.com/reduxjs/redux-toolkit/pull/3316) - Use original instead of immer draft for perf by [@​GeorchW](https://togithub.com/GeorchW) in [https://github.com/reduxjs/redux-toolkit/pull/3270](https://togithub.com/reduxjs/redux-toolkit/pull/3270) - enable enhanceEndpoints.transformResponse to override ResultType by [@​dmitrigrabov](https://togithub.com/dmitrigrabov) in [https://github.com/reduxjs/redux-toolkit/pull/2953](https://togithub.com/reduxjs/redux-toolkit/pull/2953) - Fix global `responseHandler` being used in `fetchBaseQuery` by [@​praxxis](https://togithub.com/praxxis) in [https://github.com/reduxjs/redux-toolkit/pull/3137](https://togithub.com/reduxjs/redux-toolkit/pull/3137) - reset internalState.currentSubscriptions on `resetApiState` by [@​phryneas](https://togithub.com/phryneas) in [https://github.com/reduxjs/redux-toolkit/pull/3333](https://togithub.com/reduxjs/redux-toolkit/pull/3333) - Bump deps and mark `subscriptionUpdated` as autobatched by [@​markerikson](https://togithub.com/markerikson) in [https://github.com/reduxjs/redux-toolkit/pull/3364](https://togithub.com/reduxjs/redux-toolkit/pull/3364) **Full Changelog**: https://github.com/reduxjs/redux-toolkit/compare/v1.9.3...v1.9.4 ### [`v1.9.3`](https://togithub.com/reduxjs/redux-toolkit/releases/tag/v1.9.3) [Compare Source](https://togithub.com/reduxjs/redux-toolkit/compare/v1.9.2...v1.9.3) This release fixes a couple issues with the `skip/skipToken` options for query hooks, and makes a small perf tweak to serializing query args. #### Changelog ##### Skip Behavior We made a change in [v1.9.0](https://togithub.com/reduxjs/redux-toolkit/releases/tag/v1.9.0) that tried to make some skip behavior more consistent, including clearing out the cached data. However, we had overlooked that our own docs actually said "skipping a query will *keep* the cached data", and several users pointed this out as they'd been relying on that behavior. We've reverted that change. Now, setting `{skip: true}` or `skipToken` for a query with existing results will keep the `data` value (reflecting the last successful query), but `currentData` will be undefined (reflecting the *current* settings). We also identified and fixed an issue that could cause subscription entries to leak under a specific combination of timing and settings changes. ##### Query Arg Serialization Perf RTKQ relies on serializing query arguments to serve as the cache keys, with the default using `JSON.stringify()` + some logic for sorting keys. There was a report that in some apps, large query arg objects could take a while to stringify and this was being done repeatedly. We've added a `WeakMap`-based cache for query args to avoid re-serializing existing arg values. #### What's Changed - Revert "clear data on skip" back to its original behavior by [@​markerikson](https://togithub.com/markerikson) in [https://github.com/reduxjs/redux-toolkit/pull/3188](https://togithub.com/reduxjs/redux-toolkit/pull/3188) - Use a WeakMap cache for query arg serialization for perf by [@​markerikson](https://togithub.com/markerikson) in [https://github.com/reduxjs/redux-toolkit/pull/3193](https://togithub.com/reduxjs/redux-toolkit/pull/3193) **Full Changelog**: https://github.com/reduxjs/redux-toolkit/compare/v1.9.2...v1.9.3 ### [`v1.9.2`](https://togithub.com/reduxjs/redux-toolkit/releases/tag/v1.9.2) [Compare Source](https://togithub.com/reduxjs/redux-toolkit/compare/v1.9.1...v1.9.2) This bugfix release fixes a memory leak in `createListenerMiddleware`, optimizes performance inside `serializableMiddleware`, adds new options for `fetchBaseQuery`, adds support for path `RegExp` exclusions in `serializableMiddleware` and `immutabilityMiddleware`, and improves some TS types. #### Changelog ##### Bug Fixes `createListenerMiddleware` had a memory leak that turned out to be [due to use of `Promise.race()`](https://togithub.com/reduxjs/redux-toolkit/issues/3020). We've restructured the logic to fix that. `fetchBaseQuery` now correctly combines global options with endpoint / default options in all cases. ##### New Options `fetchBaseQuery` now supports a `jsonReplacer` option that will be used when processing JSON. Both dev check middleware now support regular expressions in the `ignoredPaths` array in addition to strings. This adds extra flexibility in skipping certain fields. ##### TS Changes The `CaseReducer` type was sometimes incorrectly inferring its return type in rare cases. That's been fixed. The `isAnyOf/isAllOf` matcher function TS types have been tweaked to not require an individual first parameter. This allows spreading arrays of matchers as arguments, like `const isLoading = isAnyOf(...interestingPendingThunksArray)`. ##### Other Changes The `serializableMiddleware` now uses a `WeakSet` if available to cache values it's seen. This should significantly speed up checks against large state values in development builds. #### What's Changed - fix CaseReducer to infer from argument, not return value by [@​phryneas](https://togithub.com/phryneas) in [https://github.com/reduxjs/redux-toolkit/pull/3054](https://togithub.com/reduxjs/redux-toolkit/pull/3054) - fetchBaseQuery | Add jsonReplacer param by [@​tophep](https://togithub.com/tophep) in [https://github.com/reduxjs/redux-toolkit/pull/2904](https://togithub.com/reduxjs/redux-toolkit/pull/2904) - Support RegExp in ignoredPaths/ignoredActionPaths by [@​markerikson](https://togithub.com/markerikson) in [https://github.com/reduxjs/redux-toolkit/pull/3129](https://togithub.com/reduxjs/redux-toolkit/pull/3129) - fix(types): export `ThunkWithReturnValue` interface by [@​giomogna](https://togithub.com/giomogna) in [https://github.com/reduxjs/redux-toolkit/pull/3108](https://togithub.com/reduxjs/redux-toolkit/pull/3108) - remove unnecessary fetchBaseQuery defaults by [@​phryneas](https://togithub.com/phryneas) in [https://github.com/reduxjs/redux-toolkit/pull/3062](https://togithub.com/reduxjs/redux-toolkit/pull/3062) - make isAnyOf friendly for mapped matchers, but making argument optional by [@​megagon](https://togithub.com/megagon) in [https://github.com/reduxjs/redux-toolkit/pull/3123](https://togithub.com/reduxjs/redux-toolkit/pull/3123) - `raceWithSignal` method instead of `Promise.race` by [@​phryneas](https://togithub.com/phryneas) in [https://github.com/reduxjs/redux-toolkit/pull/3021](https://togithub.com/reduxjs/redux-toolkit/pull/3021) - Fix lint problems and enable linting on CI by [@​thorn0](https://togithub.com/thorn0) in [https://github.com/reduxjs/redux-toolkit/pull/2992](https://togithub.com/reduxjs/redux-toolkit/pull/2992) - Add caching to serializableStateInvariantMiddleware by [@​GeorchW](https://togithub.com/GeorchW) in [https://github.com/reduxjs/redux-toolkit/pull/3115](https://togithub.com/reduxjs/redux-toolkit/pull/3115) - Allow TS isolatedModules flag to be set for safer transpilation by [@​matmannion](https://togithub.com/matmannion) in [https://github.com/reduxjs/redux-toolkit/pull/2911](https://togithub.com/reduxjs/redux-toolkit/pull/2911) **Full Changelog**: https://github.com/reduxjs/redux-toolkit/compare/v1.9.1...v1.9.2 ### [`v1.9.1`](https://togithub.com/reduxjs/redux-toolkit/releases/tag/v1.9.1) [Compare Source](https://togithub.com/reduxjs/redux-toolkit/compare/v1.9.0...v1.9.1) This bugfix release fixes assorted issues that were reported with RTK 1.9.0, and adds a few additional requested tweaks and improvements. #### Changelog ##### Fixes The `createAsyncThunk.withTypes` function was fully broken (it type-checked correctly, but pointed to the wrong function due to a name shadowing issue). That now works correctly. The `maxRetries` option for RTKQ was inadvertently filtering out `0` values, and those are now accepted. `fulfillWithValue` had incorrect types that made it appear as if the data was nested an additional level deeper. The types are now correct. The `ActionCreatorWithoutPayload` type was tweaked to force an error when an action creator is accidentally called with an argument, which happens in cases like `onClick={todoAdded}`. This avoids accidentally passing values like React event objects as the payload. Timer handling for `batchActions` and `autoBatchEnhancer` now works in more JS runtime environments. ##### Other Changes The `TagDescription` type is now exported from RTKQ. API endpoints now have a `.name` field containing the endpoint name, such as `"getPokemon"`. Calling `promise.abort()` on a `createAsyncThunk` promise before an async `condition` resolves will now be treated as if the `condition` itself returned `false`, bailing out and not dispatching anything. The `merge` option now receives a third argument containing `{arg, baseQueryMeta, fulfilledTimeStamp, requestId}`, in case that info is useful in deciding how to merge. The `@reduxjs/rtk-codemods` package has been updated to fix cases where the `createSliceBuilder` codemod didn't preserve fields with function variable arguments, like `[todoAdded]: adapter.addOne`. That package has been updated to v0.0.3. #### What's Changed - fix createAsyncThunk.withTypes by [@​phryneas](https://togithub.com/phryneas) in [https://github.com/reduxjs/redux-toolkit/pull/2885](https://togithub.com/reduxjs/redux-toolkit/pull/2885) - Update timer polyfills to work in more environments by [@​markerikson](https://togithub.com/markerikson) in [https://github.com/reduxjs/redux-toolkit/pull/2887](https://togithub.com/reduxjs/redux-toolkit/pull/2887) - Retry now checks whether potential retry counts are undefined, rather than boolean, in order to avoid filtering out 0's by [@​OliverRadini](https://togithub.com/OliverRadini) in [https://github.com/reduxjs/redux-toolkit/pull/2958](https://togithub.com/reduxjs/redux-toolkit/pull/2958) - Fix multiple small issues with 1.9 by [@​markerikson](https://togithub.com/markerikson) in [https://github.com/reduxjs/redux-toolkit/pull/2964](https://togithub.com/reduxjs/redux-toolkit/pull/2964) - fulfillWithValue should infer return value by [@​phryneas](https://togithub.com/phryneas) in [https://github.com/reduxjs/redux-toolkit/pull/2888](https://togithub.com/reduxjs/redux-toolkit/pull/2888) - Fix Identifier/MemberExpression values in createSliceBuilder codemod by [@​kyletsang](https://togithub.com/kyletsang) in [https://github.com/reduxjs/redux-toolkit/pull/2881](https://togithub.com/reduxjs/redux-toolkit/pull/2881) - Additional 1.9.1 fixes by [@​markerikson](https://togithub.com/markerikson) in [https://github.com/reduxjs/redux-toolkit/pull/2965](https://togithub.com/reduxjs/redux-toolkit/pull/2965) **Full Changelog**: https://github.com/reduxjs/redux-toolkit/compare/v1.9.0...v1.9.1 ### [`v1.9.0`](https://togithub.com/reduxjs/redux-toolkit/releases/tag/v1.9.0) [Compare Source](https://togithub.com/reduxjs/redux-toolkit/compare/v1.8.6...v1.9.0) This **feature release** adds several new options for RTK Query's `createApi` and `fetchBaseQuery` APIs, adds a new `upsertQueryData` util, rewrites RTKQ's internals for improved performance, adds a new `autoBatchEnhancer`, deprecates the "object" syntax for `createReducer` and `createSlice.extraReducers`, deprecates and *removes* broken utils for getting running query promises, improves TS inference, exports additional types, and fixes a number of reported issues. ```bash npm i @​reduxjs/toolkit@latest yarn add @​reduxjs/toolkit@latest ``` We plan to start work on [RTK 2.0](https://togithub.com/reduxjs/redux-toolkit/issues/958) in the next few weeks. RTK 2.0 will focus on dropping legacy build compatibility and deprecated APIs, with some potential new features. See the linked discussion thread and give us feedback on ideas! #### Deprecations and Removals ##### Object Argument for `createReducer` and `createSlice.extraReducers` RTK's `createReducer` API was originally designed to accept a lookup table of action type strings to case reducers, like `{ "ADD_TODO" : (state, action) => {} }`. We later added [the "builder callback" form]() to allow more flexibility in adding "matchers" and a default handler, and did the same for `createSlice.extraReducers`. **We intend to remove the "object" form for both `createReducer` and `createSlice.extraReducers` in RTK 2.0**. The builder callback form is effectively the same number of lines of code, and works *much* better with TypeScript. Starting with this release, **RTK will print a one-time runtime warning for both `createReducer` and `createSlice.extraReducers` if you pass in an object argument**. As an example, this: ```js const todoAdded = createAction('todos/todoAdded'); createReducer(initialState, { [todoAdded]: (state, action) => {} }) createSlice({ name, initialState, reducers: {/* case reducers here */}, extraReducers: { [todoAdded]: (state, action) => {} } }) ``` should be migrated to: ```js createReducer(initialState, builder => { builder.addCase(todoAdded, (state, action) => {}) }) createSlice({ name, initialState, reducers: {/* case reducers here */}, extraReducers: builder => { builder.addCase(todoAdded, (state, action) => {}) } }) ``` ##### Codemods for Deprecated Object Reducer Syntax To simplify upgrading codebases, we've published a set of codemods that will automatically transform the deprecated "object" syntax into the equivalent "builder" syntax. The codemods package is available on NPM as [**`@reduxjs/rtk-codemods`**](https://www.npmjs.com/package/@​reduxjs/rtk-codemods). It currently contains two codemods: `createReducerBuilder` and `createSliceBuilder`. To run the codemods against your codebase, run `npx @​reduxjs/rtk-codemods path/of/files/ or/some**/*glob.js`. Examples: ```bash npx @​reduxjs/rtk-codemods createReducerBuilder ./src npx @​reduxjs/rtk-codemods createSliceBuilder ./packages/my-app/**/*.ts ``` We also recommend re-running Prettier on the codebase before committing the changes. **These codemods *should* work, but we would greatly appreciate testing and feedback on more real-world codebases!**
Object reducer codemod before/after examples Before: ```js createReducer(initialState, { [todoAdded1a]: (state, action) => { // stuff }, [todoAdded1b]: (state, action) => action.payload, }); const slice1 = createSlice({ name: "a", initialState: {}, extraReducers: { [todoAdded1a]: (state, action) => { // stuff }, [todoAdded1b]: (state, action) => action.payload, } }) ``` After: ```js createReducer(initialState, (builder) => { builder.addCase(todoAdded1a, (state, action) => { // stuff }); builder.addCase(todoAdded1b, (state, action) => action.payload); }) const slice1 = createSlice({ name: "a", initialState: {}, extraReducers: (builder) => { builder.addCase(todoAdded1a, (state, action) => { // stuff }); builder.addCase(todoAdded1b, (state, action) => action.payload); } }) ```
##### `getRunningOperationPromises` Deprecation and Replacement In [`v1.7.0`](https://togithub.com/reduxjs/redux-toolkit/releases/tag/v1.7.0), we added an `api.util.getRunningOperationPromises()` method for use with SSR scenarios, as well as a singular `getRunningOperationPromise()` method intended for possible use with React Suspense. Unfortunately, in [#​2477](https://togithub.com/reduxjs/redux-toolkit/issues/2477) we realized that **both those methods have a fatal flaw - they do not work with multiple stores in SSR**. As of this release, **we are immediately marking `getRunningOperationPromises()` as deprecated and discouraging its use before we remove it completely in RTK 2.0!** It will **now throw both runtime and compile errors in development** to enforce moving away from using it. However, we are leaving its existing behavior in production builds to avoid actual breakage. The `getRunningOperationPromise()` util was experimental, and as far as we can tell not actually being used by anyone, so **we are removing `getRunningOperationPromise` completely in this release**. As replacements, RTKQ now includes four new thunks attached to `api.util`: - `getRunningQueryThunk(endpointName, queryArgs)` - `getRunningMutationThunk(endpointName, fixedCacheKeyOrRequestId)` - `getRunningQueriesThunk()` - `getRunningMutationsThunk()` Usages would typically change like this: ```diff -await Promise.all(api.util.getRunningOperationPromises()) +await Promise.all(dispatch(api.util.getRunningQueriesThunk())) ``` #### Changelog ##### New RTK Query `createApi` Options `createApi` endpoints now have several additional options that can be passed in, some of which are intended to work together. ##### `merge` Option RTKQ was built around the assumption that the server is the source of truth, and every refetch replaces the cached data on the client. There *are* use cases when it would be useful to merge an incoming response into the existing cached data instead, such as pagination or APIs that return varying results over time. Query endpoints can now accept a `merge(cachedData, responseData)` callback that lets you do Immer-powered "mutations" to update the existing cached data instead of replacing it entirely. Since RTKQ assumes that each response per key should replace the existing cache entry by default, the `merge` option is expected to be used with the `serializeQueryArgs` and `forceRefetch` options, as described below. ##### `serializeQueryArgs` Option RTK Query always serializes the cache key value, and uses the string as the actual key for storing the cache entry. The default serialization is the name of the endpoint, plus either the primitive value or a stable-serialized object. An example might be `state.api.queries['getPokemon("pikachu")']`. RTKQ already supported customization of this serialization behavior at the `createApi` level. Now, each endpoint can specify its own `serializeQueryArgs` method. The per-endpoint `serializeQueryArgs` may return either a string, an object, a number, or a boolean. If it's a string, that value will be used as-is. Otherwise, the return value will be run through the default serialization logic. This simplifies the common case of stripping out a couple unwanted object fields from the cache key. This option serves two main purposes: leaving out values that are passed in to an endpoint but not really part of the "key" conceptually (like a socket or client instance), and altering cache key behavior to use a single entry for the endpoint (such as in an infinite loading / pagination scenario). Also, the `defaultSerializeQueryArgs` util is now exported. ```ts getPost: build.query({ queryFn: async ({ id, client }) => { const post = await client.fetchPost(id) return { data: post } }, serializeQueryArgs: ({ queryArgs, endpointDefinition, endpointName }) => { const { id } = queryArgs // This can return a string, an object, a number, or a boolean. // If it returns an object, number or boolean, that value // will be serialized automatically via `defaultSerializeQueryArgs` return { id } // omit `client` from the cache key // Alternately, you can use `defaultSerializeQueryArgs`: // return defaultSerializeQueryArgs({ // endpointName, // queryArgs: { id }, // endpointDefinition // }) // Or create and return a string yourself: // return `getPost(${id})` }, }), ``` ##### `forceRefresh` option Sometimes you may want to force a refetch, even though RTKQ thinks that the serialized query args haven't changed and there's already a fulfilled cache entry. This can be used to force RTKQ to actually refetch. One expected use case is an "infinite pagination" scenario where there is *one* cache entry for the endpoint, different page numbers are given as query args, and the incoming responses are merged into the existing cache entry: ```ts listItems: build.query({ query: (pageNumber) => `/listItems?page=${pageNumber}`, // Only have one cache entry because the arg always maps to one string serializeQueryArgs: ({ endpointName }) => { return endpointName }, // Always merge incoming data to the cache entry merge: (currentCache, newItems) => { currentCache.push(...newItems) }, // Refetch when the page arg changes forceRefetch({ currentArg, previousArg }) { return currentArg !== previousArg }, }), ``` ##### `transformErrorResponse` Option Similar to `transformResponse`, endpoints can now specify a `transformErrorResponse` option as well. ##### `upsertQueryData` Util RTKQ already has an `updateQueryData` util to synchronously modify the contents of an existing cache entry, but there was no way to create a new cache entry and its metadata programmatically. This release adds a new `api.util.upsertQueryData` API that allows creating a cache entry + its data programmatically. As with the other util methods, this is a thunk that should be dispatched, and you should pass in the exact cache key arg and complete data value you want to insert: ```ts dispatch( api.util.upsertQueryData('post', '3', { id: '3', title: 'All about cheese.', contents: 'I love cheese!', }) ) ``` The dispatch acts like all other RTKQ requests, so the process is async, and the thunk returns a promise that resolves when the upsert is complete. ##### RTK Query Performance Improvements We've significantly rewritten RTK Query's internal implementation to improve performance, especially in cases where many components with query hooks mount at the same time. The middleware has been "flattened" and runs fewer internal checks against each action, subscription updates are grouped together, and some unnecessary memoized selectors have been removed. One consequence is that **forgetting to add the RTKQ middleware now throws an *error* instead of logging a warning**. Overall, RTK Query processing time should be noticeably faster than it was in 1.8. RTK Query also can take advantage of the new "auto-batch enhancer" (described below) for some additional perf optimization, and **we recommend adding that to your Redux store configuration**. ##### `fetchBaseQuery` Options `fetchBaseQuery` has several new options for processing requests: You can now specify a `timeout` option for both individual endpoints and `fetchBaseQuery` . If provided, requests that take longer than this value will automatically abort. `fetchBaseQuery` now supports passing the `responseHandler` and `validateStatus` options directly to `fetchBaseQuery` itself, in addition to accepting it as part of specific endpoints. If provided, these options will be applied as defaults to *all* requests for that API, which simplifies using them on many endpoints. Providing them for endpoints overrides the global option. You can now specify a `jsonContentType` string that will be used to set the `content-type` header for a request with a jsonifiable body that does not have an explicit `content-type` header. Defaults to `"application/json"`. You can now specify a `isJsonContentType` callback that checks to see if the request body or response body should be stringified. The default looks for values like `"application/json"` and `"application/vnd.api+json"`. You can also now specify `responseHandler: 'content-type'` to have RTKQ automatically check to see whether a response should be treated as text or JSON. The `prepareHeaders` method can now return void and does *not* have to `return headers`. ##### Other RTK Query Changes The `refetch()` methods now return a promise that can be awaited. Query endpoints can now accept a `retryCondition` callback as an alternative to `maxRetries`. If you provide `retryCondition`, it will be called to determine if RTKQ should retry a failed request again. ##### New Auto-Batching Store Enhancer There are [several different ways to "batch actions" with Redux stores](https://blog.isquaredsoftware.com/2020/01/blogged-answers-redux-batching-techniques/), ranging from reducers to debounced subscriber notifications. RTK now includes a new `autoBatchEnhancer()` store enhancer that uses a variation on the "debounced notification" approach, inspired by React's technique of batching renders and determining if an update is low-priority or high-priority. The enhancer looks for any actions tagged with an `action.meta[SHOULD_AUTOBATCH] = true` flag, and delays notifying subscribers until a queued callback runs. This means that if multiple "auto-batched" actions are dispatched in a row, there will be only one subscriber notification. However, if any "normal-priority" action without that flag are dispatched before the queued callback runs, the enhancer will notify subscribers immediately instead and ignore the callback. This allows Redux users to selectively tag certain actions for effective batching behavior, making this purely opt-in on a per-action basis, while retaining normal notification behavior for all other actions. The enhancer defaults to using `requestAnimationFrame`, but can also be configured to use `queueMicrotask` to run at the end of an event loop tick, `setTimeout`, or a user-provided callback. RTK Query's internals have been updated to mark several key actions as batchable. While the enhancer is purely opt-in, benchmarks indicate that it can help speed up UI performance with RTK Query, especially when rendering many components with query hooks. **We recommend adding this enhancer to your store setup if you're using RTK Query**: ```ts const store = configureStore({ reducer, enhancers: (existingEnhancers) => { // Add the autobatch enhancer to the store setup return existingEnhancers.concat(autoBatchEnhancer()) }, }) ``` Additionally, there's a `prepareAutoBatched` util that can be used to help add the `SHOULD_AUTOBATCH` flag to actions, designed for use with `createSlice`: ```ts const counterSlice = createSlice({ name: 'counter', initialState: { value: 0 } as CounterState, reducers: { incrementBatched: { // Batched, low-priority reducer(state) { state.value += 1 }, // Use the `prepareAutoBatched` utility to automatically // add the `action.meta[SHOULD_AUTOBATCH]` field the enhancer needs prepare: prepareAutoBatched(), }, // Not batched, normal priority decrementUnbatched(state) { state.value -= 1 }, }, }) ``` ##### TypeScript Improvements RTK 1.9 **now requires TS 4.2 or greater**, and supports through TS 4.9. The action type strings generated by `createAction` are now full TS template literals when possible. There's now a `createAsyncThunk.withTypes()` method that creates a "pre-typed" version of `createAsyncThunk` with types like `{state, dispatch, extra}` baked in. This can be used to simplify customizing `createAsyncThunk` with the right types once during app setup. RTK Query now exports TS types for "pre-typed hook results", for cases when you want to wrap the query/mutation hooks in your own code. Additionally, RTKQ also exports `BaseQueryApi` and exposes TS-only types for endpoint definitions. `configureStore` now correctly infers changes to the store shape from any store enhancers, such as adding actual extra fields to `store`. RTK now exports additional types from `redux-thunk`. ##### Bug Fixes Manually initiated RTKQ promises should resolve correctly. Previous API tags are removed before adding new ones, instead of accidentally merging them together. `invalidateTags` works correctly when dealing with persisted query state. #### What's Changed - Add `isJsonContentType` predicate to `fetchBaseQuery` by [@​msutkowski](https://togithub.com/msutkowski) in [https://github.com/reduxjs/redux-toolkit/pull/2331](https://togithub.com/reduxjs/redux-toolkit/pull/2331) - Add `jsonContentType` to `fetchBaseQuery` options by [@​msutkowski](https://togithub.com/msutkowski) in [https://github.com/reduxjs/redux-toolkit/pull/2403](https://togithub.com/reduxjs/redux-toolkit/pull/2403) - Add ThunkMiddleware to the re-exported types from redux-thunk by [@​orta](https://togithub.com/orta) in [https://github.com/reduxjs/redux-toolkit/pull/2451](https://togithub.com/reduxjs/redux-toolkit/pull/2451) - add timeout option to fetchBaseQuery by [@​phryneas](https://togithub.com/phryneas) in [https://github.com/reduxjs/redux-toolkit/pull/2143](https://togithub.com/reduxjs/redux-toolkit/pull/2143) - createSlice: use template literal types for action type by [@​phryneas](https://togithub.com/phryneas) in [https://github.com/reduxjs/redux-toolkit/pull/2250](https://togithub.com/reduxjs/redux-toolkit/pull/2250) - add types for manually typing hook results in userland code by [@​phryneas](https://togithub.com/phryneas) in [https://github.com/reduxjs/redux-toolkit/pull/2276](https://togithub.com/reduxjs/redux-toolkit/pull/2276) - Add 'content-type' ResponseHandler by [@​taylorkline](https://togithub.com/taylorkline) in [https://github.com/reduxjs/redux-toolkit/pull/2363](https://togithub.com/reduxjs/redux-toolkit/pull/2363) - feature : endpoint-specific args serializers by [@​michal-kurz](https://togithub.com/michal-kurz) in [https://github.com/reduxjs/redux-toolkit/pull/2493](https://togithub.com/reduxjs/redux-toolkit/pull/2493) - RFC: add "merge" functionality by [@​phryneas](https://togithub.com/phryneas) in [https://github.com/reduxjs/redux-toolkit/pull/1059](https://togithub.com/reduxjs/redux-toolkit/pull/1059) - Add runtime deprecation warning for reducer object notation by [@​markerikson](https://togithub.com/markerikson) in [https://github.com/reduxjs/redux-toolkit/pull/2591](https://togithub.com/reduxjs/redux-toolkit/pull/2591) - feat: Add the ability to type `StoreEnhancers` by [@​fostyfost](https://togithub.com/fostyfost) in [https://github.com/reduxjs/redux-toolkit/pull/2550](https://togithub.com/reduxjs/redux-toolkit/pull/2550) - Batch RTKQ "subscribe on reject" actions, and improve cache collection timer handling by [@​markerikson](https://togithub.com/markerikson) in [https://github.com/reduxjs/redux-toolkit/pull/2599](https://togithub.com/reduxjs/redux-toolkit/pull/2599) - add transformErrorReponse to rtkq endpoints by [@​dreyks](https://togithub.com/dreyks) in [https://github.com/reduxjs/redux-toolkit/pull/1841](https://togithub.com/reduxjs/redux-toolkit/pull/1841) - Fix manually initiate()d rtk-query promises by [@​wesen](https://togithub.com/wesen) in [https://github.com/reduxjs/redux-toolkit/pull/2187](https://togithub.com/reduxjs/redux-toolkit/pull/2187) - Implement codemods for createReducer and createSlice builder by [@​markerikson](https://togithub.com/markerikson) in [https://github.com/reduxjs/redux-toolkit/pull/2602](https://togithub.com/reduxjs/redux-toolkit/pull/2602) - RFC: Expose endpoint types by [@​phryneas](https://togithub.com/phryneas) in [https://github.com/reduxjs/redux-toolkit/pull/1646](https://togithub.com/reduxjs/redux-toolkit/pull/1646) - add createAsyncThunk.withTypes by [@​phryneas](https://togithub.com/phryneas) in [https://github.com/reduxjs/redux-toolkit/pull/2604](https://togithub.com/reduxjs/redux-toolkit/pull/2604) - return promise from query result & hook `refetch` by [@​phryneas](https://togithub.com/phryneas) in [https://github.com/reduxjs/redux-toolkit/pull/2212](https://togithub.com/reduxjs/redux-toolkit/pull/2212) - retry condition by http error response by [@​kahirokunn](https://togithub.com/kahirokunn) in [https://github.com/reduxjs/redux-toolkit/pull/2239](https://togithub.com/reduxjs/redux-toolkit/pull/2239) - implemented upsertQueryData functionality per [#​1720](https://togithub.com/reduxjs/redux-toolkit/issues/1720) [#​2007](https://togithub.com/reduxjs/redux-toolkit/issues/2007) by [@​barnabasJ](https://togithub.com/barnabasJ) in [https://github.com/reduxjs/redux-toolkit/pull/2266](https://togithub.com/reduxjs/redux-toolkit/pull/2266) - Consolidate RTKQ middleware to simplify stack size by [@​markerikson](https://togithub.com/markerikson) in [https://github.com/reduxjs/redux-toolkit/pull/2641](https://togithub.com/reduxjs/redux-toolkit/pull/2641) - Try fixing createAsyncThunk issues with TS 4.8 by [@​markerikson](https://togithub.com/markerikson) in [https://github.com/reduxjs/redux-toolkit/pull/2643](https://togithub.com/reduxjs/redux-toolkit/pull/2643) - Fix assorted issues with the RTKQ middleware refactor by [@​markerikson](https://togithub.com/markerikson) in [https://github.com/reduxjs/redux-toolkit/pull/2644](https://togithub.com/reduxjs/redux-toolkit/pull/2644) - fix `upsertQueryData` race situations by [@​phryneas](https://togithub.com/phryneas) in [https://github.com/reduxjs/redux-toolkit/pull/2646](https://togithub.com/reduxjs/redux-toolkit/pull/2646) - Fix upsert by [@​phryneas](https://togithub.com/phryneas) in [https://github.com/reduxjs/redux-toolkit/pull/2669](https://togithub.com/reduxjs/redux-toolkit/pull/2669) - Export the BaseQueryApi interface from rtk-query so it can be used as a type in TypeScript without importing from dist/. by [@​nsthorat](https://togithub.com/nsthorat) in [https://github.com/reduxjs/redux-toolkit/pull/2740](https://togithub.com/reduxjs/redux-toolkit/pull/2740) - Fix retryCondition `error`. by [@​phryneas](https://togithub.com/phryneas) in [https://github.com/reduxjs/redux-toolkit/pull/2743](https://togithub.com/reduxjs/redux-toolkit/pull/2743) - fix: export ToolkitStore interface from configureStore by [@​adamhari](https://togithub.com/adamhari) in [https://github.com/reduxjs/redux-toolkit/pull/2750](https://togithub.com/reduxjs/redux-toolkit/pull/2750) - reset `dispatchQueued` variable after flushing by [@​phryneas](https://togithub.com/phryneas) in [https://github.com/reduxjs/redux-toolkit/pull/2757](https://togithub.com/reduxjs/redux-toolkit/pull/2757) - Add `forceRefetch` to `QueryExtraOptions` by [@​schadenn](https://togithub.com/schadenn) in [https://github.com/reduxjs/redux-toolkit/pull/2663](https://togithub.com/reduxjs/redux-toolkit/pull/2663) - Speed up subscription behavior by tracking state in middleware by [@​markerikson](https://togithub.com/markerikson) in [https://github.com/reduxjs/redux-toolkit/pull/2759](https://togithub.com/reduxjs/redux-toolkit/pull/2759) - `prepareHeaders` does not need to return `headers` any more by [@​phryneas](https://togithub.com/phryneas) in [https://github.com/reduxjs/redux-toolkit/pull/2775](https://togithub.com/reduxjs/redux-toolkit/pull/2775) - Add `codemods-cli` and rewrite "object reducer" codemods by [@​markerikson](https://togithub.com/markerikson) in [https://github.com/reduxjs/redux-toolkit/pull/2768](https://togithub.com/reduxjs/redux-toolkit/pull/2768) - remove alpha compatibility fallbacks by [@​phryneas](https://togithub.com/phryneas) in [https://github.com/reduxjs/redux-toolkit/pull/2777](https://togithub.com/reduxjs/redux-toolkit/pull/2777) - fix `skipToken` behaviour in `useQueryState` by [@​phryneas](https://togithub.com/phryneas) in [https://github.com/reduxjs/redux-toolkit/pull/2779](https://togithub.com/reduxjs/redux-toolkit/pull/2779) - `fetchBaseQuery`: allow `headers` option by [@​phryneas](https://togithub.com/phryneas) in [https://github.com/reduxjs/redux-toolkit/pull/2778](https://togithub.com/reduxjs/redux-toolkit/pull/2778) - \[breaking fix] replace `getRunningOperationPromise(s)` with `getRunning(Query|Queries|Mutation|Mutations)Thunk` by [@​phryneas](https://togithub.com/phryneas) in [https://github.com/reduxjs/redux-toolkit/pull/2481](https://togithub.com/reduxjs/redux-toolkit/pull/2481) - General pre-1.9-beta cleanup by [@​markerikson](https://togithub.com/markerikson) in [https://github.com/reduxjs/redux-toolkit/pull/2789](https://togithub.com/reduxjs/redux-toolkit/pull/2789) - Convert "middleware not registered" warning into a full error by [@​markerikson](https://togithub.com/markerikson) in [https://github.com/reduxjs/redux-toolkit/pull/2792](https://togithub.com/reduxjs/redux-toolkit/pull/2792) - Rework endpoint serializeQueryArgs to allow object/number returns by [@​markerikson](https://togithub.com/markerikson) in [https://github.com/reduxjs/redux-toolkit/pull/2835](https://togithub.com/reduxjs/redux-toolkit/pull/2835) - allow for global `responseHandler` and `validateStatus` configuration by [@​phryneas](https://togithub.com/phryneas) in [https://github.com/reduxjs/redux-toolkit/pull/2823](https://togithub.com/reduxjs/redux-toolkit/pull/2823) - Fix refetches when sQA returns same value and queryArgs are object by [@​markerikson](https://togithub.com/markerikson) in [https://github.com/reduxjs/redux-toolkit/pull/2844](https://togithub.com/reduxjs/redux-toolkit/pull/2844) - Add an auto-batching enhancer that delays low-pri notifications and use with RTKQ by [@​markerikson](https://togithub.com/markerikson) in [https://github.com/reduxjs/redux-toolkit/pull/2846](https://togithub.com/reduxjs/redux-toolkit/pull/2846) - Check middleware registration directly to avoid persistence issues by [@​markerikson](https://togithub.com/markerikson) in [https://github.com/reduxjs/redux-toolkit/pull/2850](https://togithub.com/reduxjs/redux-toolkit/pull/2850) - Fix "running thunks" types and remove unnecessary RTKQ selectors by [@​markerikson](https://togithub.com/markerikson) in [https://github.com/reduxjs/redux-toolkit/pull/2856](https://togithub.com/reduxjs/redux-toolkit/pull/2856) - Make autobatching notification queueing configurable by [@​markerikson](https://togithub.com/markerikson) in [https://github.com/reduxjs/redux-toolkit/pull/2857](https://togithub.com/reduxjs/redux-toolkit/pull/2857) - Hopefully final v1.9 tweaks by [@​markerikson](https://togithub.com/markerikson) in [https://github.com/reduxjs/redux-toolkit/pull/2859](https://togithub.com/reduxjs/redux-toolkit/pull/2859) **Full Changelog**: https://github.com/reduxjs/redux-toolkit/compare/v1.8.6...v1.9.0 ### [`v1.8.6`](https://togithub.com/reduxjs/redux-toolkit/releases/tag/v1.8.6) [Compare Source](https://togithub.com/reduxjs/redux-toolkit/compare/v1.8.5...v1.8.6) This bugfix release fixes a couple of issues with RTKQ endpoint tags not invalidating correctly, and tweaks the `dispatch` type inference to handle more variations of arrays. #### What's Changed - Fix the `dispatch` type inference to correctly handle read-only middleware arrays by [@​dokmic](https://togithub.com/dokmic) in [https://github.com/reduxjs/redux-toolkit/pull/2629](https://togithub.com/reduxjs/redux-toolkit/pull/2629) - fix(toolkit): export "ThunkMiddleware" from redux-thunk by [@​VinceOPS](https://togithub.com/VinceOPS) in [https://github.com/reduxjs/redux-toolkit/pull/2745](https://togithub.com/reduxjs/redux-toolkit/pull/2745) - Remove previous api tags before adding new provided tags by [@​Bezmehrabi](https://togithub.com/Bezmehrabi) in [https://github.com/reduxjs/redux-toolkit/pull/2702](https://togithub.com/reduxjs/redux-toolkit/pull/2702) - Fix invalidateTags by [@​manceau-jb](https://togithub.com/manceau-jb) in [https://github.com/reduxjs/redux-toolkit/pull/2721](https://togithub.com/reduxjs/redux-toolkit/pull/2721) **Full Changelog**: https://github.com/reduxjs/redux-toolkit/compare/v1.8.5...v1.8.6 ### [`v1.8.5`](https://togithub.com/reduxjs/redux-toolkit/releases/tag/v1.8.5) [Compare Source](https://togithub.com/reduxjs/redux-toolkit/compare/v1.8.4...v1.8.5) This bugfix releas fixes an issue with large `keepUnusedDataFor` values overflowing JS timers, exports the types for the Redux DevTools Extension option, and and improves behavior of URL string generation. #### Changelog ##### `keepUnusedDataFor` Timer Fix `keepUnusedDataFor` accepts a value in seconds. When there are no more active subscriptions for a piece of data, RTKQ will set a timer using `setTimeout`, and `keepUnusedDataFor * 1000` as the timer value. We've been advising users that if they want to keep data in the cache forever that they should use a very large value for `keepUnusedDataFor`, such as 10 years in seconds. However, it turns out that JS engines use a 32-bit signed int for timers, and 32-bits in milliseconds is only 24.8 days. If a timer is given a value larger than that, it triggers immediately. We've updated the internal logic to clamp the `keepUnusedDataFor` value to be between 0 and `THIRTY_TWO_BIT_MAX_TIMER_SECONDS - 1`. Note that in RTK 1.9 (coming soon), RTKQ will also accept `Infinity` as a special `keepUnusedDataFor` value to indicate cached data should never be expired. ##### Other Changes RTK inlines the TS types for the Redux DevTools Extension options to avoid an extra dependency, but the TS type for the options object wasn't exported publicly. We now export the `DevToolsEnhancerOptions` type. The logic for generating a final URL has been updated to avoid adding an extra trailing `/`. #### What's Changed - Prevent `keepUnusedDataFor` values from overflowing `setTimeout` counter by [@​markerikson](https://togithub.com/markerikson) in [https://github.com/reduxjs/redux-toolkit/pull/2595](https://togithub.com/reduxjs/redux-toolkit/pull/2595) - remove typeof undefined checks where not necessary πŸƒπŸͺ’ by [@​phryneas](https://togithub.com/phryneas) in [https://github.com/reduxjs/redux-toolkit/pull/1726](https://togithub.com/reduxjs/redux-toolkit/pull/1726) - Update RDT options types, and export those + AnyListenerPredicate by [@​markerikson](https://togithub.com/markerikson) in [https://github.com/reduxjs/redux-toolkit/pull/2596](https://togithub.com/reduxjs/redux-toolkit/pull/2596) - Ensures there is no unexpected slash in url before query params by [@​ygrishajev](https://togithub.com/ygrishajev) in [https://github.com/reduxjs/redux-toolkit/pull/2470](https://togithub.com/reduxjs/redux-toolkit/pull/2470) **Full Changelog**: https://github.com/reduxjs/redux-toolkit/compare/v1.8.4...v1.8.5 ### [`v1.8.4`](https://togithub.com/reduxjs/redux-toolkit/releases/tag/v1.8.4) [Compare Source](https://togithub.com/reduxjs/redux-toolkit/compare/1.8.3...v1.8.4) This bugfix release adds exported TS types for RTKQ hooks for use in wrapping logic, adds `useDebugValue` to the hooks to improve display in the React DevTools, updates the inlined types for the Redux DevTools options, and fixes an issue in `createEntityAdapter` that could result in duplicate IDs being stored. #### Changelog ##### RTKQ Hook Result Types RTK's types heavily rely on inference to minimize the amount of type info users have to provide. However, this can also make it difficult to write functions that wrap calls to RTK APIs. Some users have asked to have types that help them write "higher-order hooks". RTK now exports types that represent "the return object for a query/mutation hook with a given value": `TypedUseQueryHookResult` and `TypedUseMutationResult`. Both require `` as generics, like this: ```ts const baseQuery = fetchBaseQuery({url: "https://some.server"}); type CustomHookResult = TypedUseQueryHookResult const useMyCustomHook = (arg: MyArgObject) : CustomHookResult => { return api.useGetSomeDataQuery(arg); } ``` ##### Redux DevTools Options Fixes As of Redux DevTools 3.0, some of field names for custom DevTools options have changed to `actionsAllowlist` and `actionsDenylist`. Since we inline the types instead of having a separate dependency, we've updated our TS types to match that. No runtime behavior was changed. ##### Other Changes RTKQ hooks now use `useDebugValue` to give a better preview of the current value in the React DevTools "Component" tab. The `` component now does a better job of registering and cleaning up focus listeners. Fixed a bug with `createEntityAdapter` that could allow duplicate IDs to be added depending on update parameters. #### What's Changed - fix: prevent duplicate ids when updating id of an element with the id of an existing element by [@​samatar26](https://togithub.com/samatar26) in [https://github.com/reduxjs/redux-toolkit/pull/2020](https://togithub.com/reduxjs/redux-toolkit/pull/2020) - ApiProvider: correctly register listeners, allow to disable listeners by [@​phryneas](https://togithub.com/phryneas) in [https://github.com/reduxjs/redux-toolkit/pull/2277](https://togithub.com/reduxjs/redux-toolkit/pull/2277) - Update devtools options TS types based on RDT 3.0 by [@​markerikson](https://togithub.com/markerikson) in [https://github.com/reduxjs/redux-toolkit/pull/2480](https://togithub.com/reduxjs/redux-toolkit/pull/2480) - fix: typo in unhandled error message by [@​MichielTondeur](https://togithub.com/MichielTondeur) in [https://github.com/reduxjs/redux-toolkit/pull/2538](https://togithub.com/reduxjs/redux-toolkit/pull/2538) - Use useDebugValue in useQuery and useMutation hooks by [@​kaankeskin](https://togithub.com/kaankeskin) in [https://github.com/reduxjs/redux-toolkit/pull/2500](https://togithub.com/reduxjs/redux-toolkit/pull/2500) - add types for manually typing hook results in userland code by [@​markerikson](https://togithub.com/markerikson) in [https://github.com/reduxjs/redux-toolkit/pull/2580](https://togithub.com/reduxjs/redux-toolkit/pull/2580) **Full Changelog**: https://github.com/reduxjs/redux-toolkit/compare/v1.8.3...v1.8.4 ### [`v1.8.3`](https://togithub.com/reduxjs/redux-toolkit/releases/tag/v1.8.3) [Compare Source](https://togithub.com/reduxjs/redux-toolkit/compare/v1.8.2...1.8.3) This bugfix release fixes a few minor issues and bits of behavior, including updating the React-Redux peer dep to `^8.0.2` final, stable sorting in `createEntityAdapter.updateMany` and some initial state handling in `createSlice`. #### Changelog ##### React-Redux Peer Dep We'd previously published an RTK build that accepted React-Redux v8 beta as a peer dep (for use with RTK Query). Since React-Redux v8 is out now, we've updated the peer dep to `^8.0.2`. ##### Entity Adapter Updates Previously, applying updates via `createEntityAdapter.updateMany` caused sorting order to change. Entities that had the same sorting result *should* have stayed in the same order relative to each other, but if one of those items had any updates, it would sort to the back of that group. This was due to items being removed from the lookup table and re-added, and since JS engines iterate keys in insertion order, the updated item would now end up compared later than before. We've reworked the implementation of `updateMany` to avoid that. This also ended up fixing another issue where multiple update entries targeting the same item ID would only have the first applied. #### `createSlice` Initial State `createSlice` now logs an error if `initialState` is `undefined`. This is most commonly seen when users misspell `initialState`. It also has better handling for values that can't be frozen by Immer such as primitives. ##### RTK Query Several assorted improvements, including TS types for `BaseQuery` and checking if the body can actually be safely stringified. #### What's Changed - Add Missing Else to enhanceEndpoints Function by [@​kinson](https://togithub.com/kinson) in [https://github.com/reduxjs/redux-toolkit/pull/2386](https://togithub.com/reduxjs/redux-toolkit/pull/2386) - Check initial state is draftable before using immer to freeze it. by [@​EskiMojo14](https://togithub.com/EskiMojo14) in [https://github.com/reduxjs/redux-toolkit/pull/2378](https://

Configuration

πŸ“… Schedule: Branch creation - "before 4am on Monday" in timezone America/New_York, Automerge - At any time (no schedule defined).

🚦 Automerge: Enabled.

β™» Rebasing: Whenever PR is behind base branch, or you tick the rebase/retry checkbox.

πŸ”• Ignore: Close this PR and you won't be reminded about this update again.



This PR has been generated by Mend Renovate. View repository job log here.

codecov[bot] commented 8 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Comparison is base (e5a21f4) 92.41% compared to head (c7f9e73) 92.41%.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #616 +/- ## ======================================= Coverage 92.41% 92.41% ======================================= Files 169 169 Lines 3468 3468 Branches 900 900 ======================================= Hits 3205 3205 Misses 243 243 Partials 20 20 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.