@@ -291,15 +291,23 @@ export function buildInitiate({
291
291
Object . values ( runningMutations . get ( dispatch ) || { } ) . filter ( isNotNullish )
292
292
}
293
293
294
- function middlewareWarning ( getState : ( ) => RootState < { } , string , string > ) {
294
+ function middlewareWarning ( dispatch : Dispatch ) {
295
295
if ( process . env . NODE_ENV !== 'production' ) {
296
296
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
303
311
throw new Error (
304
312
`Warning: Middleware for RTK-Query API at reducerPath "${ api . reducerPath } " has not been added to the store.
305
313
You 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!`
346
354
const thunkResult = dispatch ( thunk )
347
355
const stateAfter = selector ( getState ( ) )
348
356
349
- middlewareWarning ( getState )
357
+ middlewareWarning ( dispatch )
350
358
351
359
const { requestId, abort } = thunkResult
352
360
@@ -440,7 +448,7 @@ You must add the middleware for RTK-Query to function correctly!`
440
448
fixedCacheKey,
441
449
} )
442
450
const thunkResult = dispatch ( thunk )
443
- middlewareWarning ( getState )
451
+ middlewareWarning ( dispatch )
444
452
const { requestId, abort, unwrap } = thunkResult
445
453
const returnValuePromise = thunkResult
446
454
. unwrap ( )
0 commit comments