Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions docs/api/immutabilityMiddleware.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ interface ImmutableStateInvariantMiddlewareOptions {
ignoredPaths?: (string | RegExp)[]
/** Print a warning if checks take longer than N ms. Default: 32ms */
warnAfter?: number
// @deprecated. Use ignoredPaths
ignore?: string[]
}
```

Expand Down
11 changes: 0 additions & 11 deletions packages/toolkit/src/createSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,6 @@ import type { Id, NoInfer, Tail } from './tsHelpers'
import { freezeDraftable } from './utils'
import type { CombinedSliceReducer, InjectConfig } from './combineSlices'

let hasWarnedAboutObjectNotation = false

/**
* An action creator attached to a slice.
*
* @deprecated please use PayloadActionCreator directly
*
* @public
*/
export type SliceActionCreator<P> = PayloadActionCreator<P>

/**
* The return value of `createSlice`
*
Expand Down
12 changes: 0 additions & 12 deletions packages/toolkit/src/devtoolsExtension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,18 +90,6 @@ export interface DevToolsEnhancerOptions {
* function which takes `state` object and index as arguments, and should return `state` object back.
*/
stateSanitizer?: <S>(state: S, index: number) => S
/**
* *string or array of strings as regex* - actions types to be hidden / shown in the monitors (while passed to the reducers).
* If `actionsWhitelist` specified, `actionsBlacklist` is ignored.
* @deprecated Use actionsDenylist instead.
*/
actionsBlacklist?: string | string[]
/**
* *string or array of strings as regex* - actions types to be hidden / shown in the monitors (while passed to the reducers).
* If `actionsWhitelist` specified, `actionsBlacklist` is ignored.
* @deprecated Use actionsAllowlist instead.
*/
actionsWhitelist?: string | string[]
/**
* *string or array of strings as regex* - actions types to be hidden / shown in the monitors (while passed to the reducers).
* If `actionsAllowlist` specified, `actionsDenylist` is ignored.
Expand Down
6 changes: 0 additions & 6 deletions packages/toolkit/src/immutableStateInvariantMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,6 @@ export interface ImmutableStateInvariantMiddlewareOptions {
ignoredPaths?: IgnorePaths
/** Print a warning if checks take longer than N ms. Default: 32ms */
warnAfter?: number
// @deprecated. Use ignoredPaths
ignore?: string[]
}

/**
Expand Down Expand Up @@ -226,12 +224,8 @@ export function createImmutableStateInvariantMiddleware(
isImmutable = isImmutableDefault,
ignoredPaths,
warnAfter = 32,
ignore,
} = options

// Alias ignore->ignoredPaths, but prefer ignoredPaths if present
ignoredPaths = ignoredPaths || ignore

const track = trackForMutations.bind(null, isImmutable, ignoredPaths)

return ({ getState }) => {
Expand Down
5 changes: 0 additions & 5 deletions packages/toolkit/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ export type {
SliceCaseReducers,
ValidateSliceCaseReducers,
CaseReducerWithPrepare,
SliceActionCreator,
} from './createSlice'
export {
// js
Expand All @@ -90,10 +89,6 @@ export type {
// types
SerializableStateInvariantMiddlewareOptions,
} from './serializableStateInvariantMiddleware'
export {
// js
getDefaultMiddleware,
} from './getDefaultMiddleware'
export type {
// types
ActionReducerMapBuilder,
Expand Down
34 changes: 0 additions & 34 deletions packages/toolkit/src/query/core/buildInitiate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,6 @@ export type MutationActionCreatorResult<
The value returned by the hook will reset to `isUninitialized` afterwards.
*/
reset(): void
/** @deprecated has been renamed to `reset` */
unsubscribe(): void
}

export function buildInitiate({
Expand Down Expand Up @@ -219,37 +217,6 @@ export function buildInitiate({
getRunningMutationThunk,
getRunningQueriesThunk,
getRunningMutationsThunk,
getRunningOperationPromises,
removalWarning,
}

/** @deprecated to be removed in 2.0 */
function removalWarning(): never {
throw new Error(
`This method had to be removed due to a conceptual bug in RTK.
Please see https://github.com/reduxjs/redux-toolkit/pull/2481 for details.
See https://redux-toolkit.js.org/rtk-query/usage/server-side-rendering for new guidance on SSR.`
)
}

/** @deprecated to be removed in 2.0 */
function getRunningOperationPromises() {
if (
typeof process !== 'undefined' &&
process.env.NODE_ENV === 'development'
) {
removalWarning()
} else {
const extract = <T>(
v: Map<Dispatch<AnyAction>, Record<string, T | undefined>>
) =>
Array.from(v.values()).flatMap((queriesForStore) =>
queriesForStore ? Object.values(queriesForStore) : []
)
return [...extract(runningQueries), ...extract(runningMutations)].filter(
isNotNullish
)
}
}

function getRunningQueryThunk(endpointName: string, queryArgs: any) {
Expand Down Expand Up @@ -464,7 +431,6 @@ You must add the middleware for RTK-Query to function correctly!`
requestId,
abort,
unwrap,
unsubscribe: reset,
reset,
})

Expand Down
2 changes: 0 additions & 2 deletions packages/toolkit/src/query/core/buildSelectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ export type SkipToken = typeof skipToken
* return an uninitialized state.
*/
export const skipToken = /* @__PURE__ */ Symbol.for('RTKQ/skipToken')
/** @deprecated renamed to `skipToken` */
export const skipSelector = skipToken

declare module './module' {
export interface ApiEndpointQuery<
Expand Down
2 changes: 0 additions & 2 deletions packages/toolkit/src/query/core/buildSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -494,8 +494,6 @@ export function buildSlice({
...subscriptionSlice.actions,
...internalSubscriptionsSlice.actions,
...mutationSlice.actions,
/** @deprecated has been renamed to `removeMutationResult` */
unsubscribeMutationResult: mutationSlice.actions.removeMutationResult,
resetApiState,
}

Expand Down
41 changes: 4 additions & 37 deletions packages/toolkit/src/query/core/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ export type CoreModule =
| ReferenceQueryLifecycle
| ReferenceCacheCollection

export interface ThunkWithReturnValue<T> extends ThunkAction<T, any, any, AnyAction> {}
export interface ThunkWithReturnValue<T>
extends ThunkAction<T, any, any, AnyAction> {}

declare module '../apiTypes' {
export interface ApiModules<
Expand Down Expand Up @@ -139,28 +140,6 @@ declare module '../apiTypes' {
* A collection of utility thunks for various situations.
*/
util: {
/**
* This method had to be removed due to a conceptual bug in RTK.
*
* Despite TypeScript errors, it will continue working in the "buggy" way it did
* before in production builds and will be removed in the next major release.
*
* Nonetheless, you should immediately replace it with the new recommended approach.
* See https://redux-toolkit.js.org/rtk-query/usage/server-side-rendering for new guidance on SSR.
*
* Please see https://github.com/reduxjs/redux-toolkit/pull/2481 for details.
* @deprecated
*/
getRunningOperationPromises: never // this is now types as `never` to immediately throw TS errors on use, but still allow for a comment

/**
* This method had to be removed due to a conceptual bug in RTK.
* It has been replaced by `api.util.getRunningQueryThunk` and `api.util.getRunningMutationThunk`.
* Please see https://github.com/reduxjs/redux-toolkit/pull/2481 for details.
* @deprecated
*/
getRunningOperationPromise: never // this is now types as `never` to immediately throw TS errors on use, but still allow for a comment

/**
* A thunk that (if dispatched) will return a specific running query, identified
* by `endpointName` and `args`.
Expand Down Expand Up @@ -268,11 +247,7 @@ declare module '../apiTypes' {
Definitions,
RootState<Definitions, string, ReducerPath>
>
/** @deprecated renamed to `updateQueryData` */
updateQueryResult: UpdateQueryDataThunk<
Definitions,
RootState<Definitions, string, ReducerPath>
>

/**
* A Redux thunk action creator that, when dispatched, acts as an artificial API request to upsert a value into the cache.
*
Expand Down Expand Up @@ -326,11 +301,7 @@ declare module '../apiTypes' {
Definitions,
RootState<Definitions, string, ReducerPath>
>
/** @deprecated renamed to `patchQueryData` */
patchQueryResult: PatchQueryDataThunk<
Definitions,
RootState<Definitions, string, ReducerPath>
>

/**
* A Redux action creator that can be dispatched to manually reset the api state completely. This will immediately remove all existing cache entries, and all queries will be considered 'uninitialized'.
*
Expand Down Expand Up @@ -571,8 +542,6 @@ export const coreModule = (): Module<CoreModule> => ({
getRunningMutationsThunk,
getRunningQueriesThunk,
getRunningQueryThunk,
getRunningOperationPromises,
removalWarning,
} = buildInitiate({
queryThunk,
mutationThunk,
Expand All @@ -582,8 +551,6 @@ export const coreModule = (): Module<CoreModule> => ({
})

safeAssign(api.util, {
getRunningOperationPromises: getRunningOperationPromises as any,
getRunningOperationPromise: removalWarning as any,
getRunningMutationThunk,
getRunningMutationsThunk,
getRunningQueryThunk,
Expand Down
14 changes: 0 additions & 14 deletions packages/toolkit/src/query/endpointDefinitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,20 +230,6 @@ export type ResultDescription<
| ReadonlyArray<TagDescription<TagTypes>>
| GetResultDescriptionFn<TagTypes, ResultType, QueryArg, ErrorType, MetaType>

/** @deprecated please use `onQueryStarted` instead */
export interface QueryApi<ReducerPath extends string, Context extends {}> {
/** @deprecated please use `onQueryStarted` instead */
dispatch: ThunkDispatch<any, any, AnyAction>
/** @deprecated please use `onQueryStarted` instead */
getState(): RootState<any, any, ReducerPath>
/** @deprecated please use `onQueryStarted` instead */
extra: unknown
/** @deprecated please use `onQueryStarted` instead */
requestId: string
/** @deprecated please use `onQueryStarted` instead */
context: Context
}

export interface QueryTypes<
QueryArg,
BaseQuery extends BaseQueryFn,
Expand Down
2 changes: 1 addition & 1 deletion packages/toolkit/src/query/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export type {
} from './fetchBaseQuery'
export { retry } from './retry'
export { setupListeners } from './core/setupListeners'
export { skipSelector, skipToken } from './core/buildSelectors'
export { skipToken } from './core/buildSelectors'
export type { SkipToken } from './core/buildSelectors'
export type { CreateApi, CreateApiOptions } from './createApi'
export { buildCreateApi } from './createApi'
Expand Down
9 changes: 1 addition & 8 deletions packages/toolkit/src/query/react/buildHooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -452,14 +452,7 @@ type UseQueryStateDefaultResult<D extends QueryDefinition<any, any, any, any>> =
Pick<UseQueryStateBaseResult<D>, 'error'>
>)
>
> & {
/**
* @deprecated will be removed in the next version
* please use the `isLoading`, `isFetching`, `isSuccess`, `isError`
* and `isUninitialized` flags instead
*/
status: QueryStatus
}
>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would actually have kept this one in - the warning should discourage people, but it's there anyways and might be useful in edge cases 😅


export type MutationStateSelector<
R extends Record<string, any>,
Expand Down
1 change: 0 additions & 1 deletion packages/toolkit/src/query/tests/buildHooks.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1344,7 +1344,6 @@ describe('hooks tests', () => {
expectType<() => void>(res.abort)
expectType<() => Promise<{ name: string }>>(res.unwrap)
expectType<() => void>(res.reset)
expectType<() => void>(res.unsubscribe)

// abort the mutation immediately to force an error
res.abort()
Expand Down
40 changes: 33 additions & 7 deletions packages/toolkit/src/query/tests/cacheLifecycle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
setupApiStore,
DEFAULT_DELAY_MS,
} from './helpers'
import { QueryActionCreatorResult } from '../core/buildInitiate'

beforeAll(() => {
vi.useFakeTimers()
Expand Down Expand Up @@ -54,6 +55,7 @@ describe.each([['query'], ['mutation']] as const)(
const extended = api.injectEndpoints({
overrideExisting: true,
endpoints: (build) => ({
// Lying to TS here
injected: build[type as 'mutation']<unknown, string>({
query: () => '/success',
async onCacheEntryAdded(
Expand All @@ -74,7 +76,11 @@ describe.each([['query'], ['mutation']] as const)(
expect(onNewCacheEntry).toHaveBeenCalledWith('arg')
expect(onCleanup).not.toHaveBeenCalled()

promise.unsubscribe()
if (type === 'mutation') {
promise.reset()
} else {
;(promise as unknown as QueryActionCreatorResult<any>).unsubscribe()
}
await vi.advanceTimersByTimeAsync(DEFAULT_DELAY_MS)
if (type === 'query') {
await vi.advanceTimersByTimeAsync(59000)
Expand Down Expand Up @@ -128,7 +134,11 @@ describe.each([['query'], ['mutation']] as const)(
})
expect(onCleanup).not.toHaveBeenCalled()

promise.unsubscribe()
if (type === 'mutation') {
promise.reset()
} else {
;(promise as unknown as QueryActionCreatorResult<any>).unsubscribe()
}
await vi.advanceTimersByTimeAsync(DEFAULT_DELAY_MS)
if (type === 'query') {
await vi.advanceTimersByTimeAsync(59000)
Expand Down Expand Up @@ -166,7 +176,11 @@ describe.each([['query'], ['mutation']] as const)(
)
expect(onNewCacheEntry).toHaveBeenCalledWith('arg')

promise.unsubscribe()
if (type === 'mutation') {
promise.reset()
} else {
;(promise as unknown as QueryActionCreatorResult<any>).unsubscribe()
}
await vi.advanceTimersByTimeAsync(DEFAULT_DELAY_MS)
if (type === 'query') {
await vi.advanceTimersByTimeAsync(120000)
Expand Down Expand Up @@ -205,7 +219,11 @@ describe.each([['query'], ['mutation']] as const)(
)

expect(onNewCacheEntry).toHaveBeenCalledWith('arg')
promise.unsubscribe()
if (type === 'mutation') {
promise.reset()
} else {
;(promise as unknown as QueryActionCreatorResult<any>).unsubscribe()
}
await vi.advanceTimersByTimeAsync(DEFAULT_DELAY_MS)

if (type === 'query') {
Expand Down Expand Up @@ -253,7 +271,11 @@ describe.each([['query'], ['mutation']] as const)(

expect(onNewCacheEntry).toHaveBeenCalledWith('arg')

promise.unsubscribe()
if (type === 'mutation') {
promise.reset()
} else {
;(promise as unknown as QueryActionCreatorResult<any>).unsubscribe()
}
await vi.advanceTimersByTimeAsync(DEFAULT_DELAY_MS)
if (type === 'query') {
await vi.advanceTimersByTimeAsync(59000)
Expand Down Expand Up @@ -299,7 +321,11 @@ describe.each([['query'], ['mutation']] as const)(

expect(onNewCacheEntry).toHaveBeenCalledWith('arg')

promise.unsubscribe()
if (type === 'mutation') {
promise.reset()
} else {
;(promise as unknown as QueryActionCreatorResult<any>).unsubscribe()
}
await vi.advanceTimersByTimeAsync(DEFAULT_DELAY_MS)
if (type === 'query') {
await vi.advanceTimersByTimeAsync(59000)
Expand Down Expand Up @@ -421,7 +447,7 @@ test(`mutation: getCacheEntry`, async () => {
expect(gotFirstValue).toHaveBeenCalled()
})

promise.unsubscribe()
promise.reset()
await vi.advanceTimersByTimeAsync(DEFAULT_DELAY_MS)

expect(snapshot).toHaveBeenCalledTimes(3)
Expand Down
Loading