@@ -291,15 +291,23 @@ export function buildInitiate({
291291 Object . values ( runningMutations . get ( dispatch ) || { } ) . filter ( isNotNullish )
292292 }
293293
294- function middlewareWarning ( getState : ( ) => RootState < { } , string , string > ) {
294+ function middlewareWarning ( dispatch : Dispatch ) {
295295 if ( process . env . NODE_ENV !== 'production' ) {
296296 if ( ( middlewareWarning as any ) . triggered ) return
297- const registered =
298- getState ( ) [ api . reducerPath ] ?. config ?. middlewareRegistered
299- if ( registered !== undefined ) {
300- ; ( middlewareWarning as any ) . triggered = true
301- }
302- if ( registered === false ) {
297+ const registered :
298+ | ReturnType < typeof api . internalActions . internal_probeSubscription >
299+ | boolean = dispatch (
300+ api . internalActions . internal_probeSubscription ( {
301+ queryCacheKey : 'DOES_NOT_EXIST' ,
302+ requestId : 'DUMMY_REQUEST_ID' ,
303+ } )
304+ )
305+
306+ ; ( middlewareWarning as any ) . triggered = true
307+
308+ // The RTKQ middleware _should_ always return a boolean for `probeSubscription`
309+ if ( typeof registered !== 'boolean' ) {
310+ // Otherwise, must not have been added
303311 throw new Error (
304312 `Warning: Middleware for RTK-Query API at reducerPath "${ api . reducerPath } " has not been added to the store.
305313You must add the middleware for RTK-Query to function correctly!`
@@ -346,7 +354,7 @@ You must add the middleware for RTK-Query to function correctly!`
346354 const thunkResult = dispatch ( thunk )
347355 const stateAfter = selector ( getState ( ) )
348356
349- middlewareWarning ( getState )
357+ middlewareWarning ( dispatch )
350358
351359 const { requestId, abort } = thunkResult
352360
@@ -440,7 +448,7 @@ You must add the middleware for RTK-Query to function correctly!`
440448 fixedCacheKey,
441449 } )
442450 const thunkResult = dispatch ( thunk )
443- middlewareWarning ( getState )
451+ middlewareWarning ( dispatch )
444452 const { requestId, abort, unwrap } = thunkResult
445453 const returnValuePromise = thunkResult
446454 . unwrap ( )
0 commit comments