@@ -129,6 +129,9 @@ export function buildSelectors<
129129} ) {
130130 type RootState = _RootState < Definitions , string , string >
131131
132+ const selectSkippedQuery = ( state : RootState ) => defaultQuerySubState
133+ const selectSkippedMutation = ( state : RootState ) => defaultMutationSubState
134+
132135 return { buildQuerySelector, buildMutationSelector, selectInvalidatedBy }
133136
134137 function withRequestFlags < T extends { status : QueryStatus } > (
@@ -159,20 +162,18 @@ export function buildSelectors<
159162 endpointDefinition : QueryDefinition < any , any , any , any >
160163 ) {
161164 return ( ( queryArgs : any ) => {
162- const selectQuerySubState = createSelector (
163- selectInternalState ,
164- ( internalState ) =>
165- ( queryArgs === skipToken
166- ? undefined
167- : internalState ?. queries ?. [
168- serializeQueryArgs ( {
169- queryArgs,
170- endpointDefinition,
171- endpointName,
172- } )
173- ] ) ?? defaultQuerySubState
174- )
175- return createSelector ( selectQuerySubState , withRequestFlags )
165+ const serializedArgs = serializeQueryArgs ( {
166+ queryArgs,
167+ endpointDefinition,
168+ endpointName,
169+ } )
170+ const selectQuerySubstate = ( state : RootState ) =>
171+ selectInternalState ( state ) ?. queries ?. [ serializedArgs ] ??
172+ defaultQuerySubState
173+ const finalSelectQuerySubState =
174+ queryArgs === skipToken ? selectSkippedQuery : selectQuerySubstate
175+
176+ return createSelector ( finalSelectQuerySubState , withRequestFlags )
176177 } ) as QueryResultSelectorFactory < any , RootState >
177178 }
178179
@@ -184,14 +185,15 @@ export function buildSelectors<
184185 } else {
185186 mutationId = id
186187 }
187- const selectMutationSubstate = createSelector (
188- selectInternalState ,
189- ( internalState ) =>
190- ( mutationId === skipToken
191- ? undefined
192- : internalState ?. mutations ?. [ mutationId ] ) ?? defaultMutationSubState
193- )
194- return createSelector ( selectMutationSubstate , withRequestFlags )
188+ const selectMutationSubstate = ( state : RootState ) =>
189+ selectInternalState ( state ) ?. mutations ?. [ mutationId as string ] ??
190+ defaultMutationSubState
191+ const finalSelectMutationSubstate =
192+ mutationId === skipToken
193+ ? selectSkippedMutation
194+ : selectMutationSubstate
195+
196+ return createSelector ( finalSelectMutationSubstate , withRequestFlags )
195197 } ) as MutationResultSelectorFactory < any , RootState >
196198 }
197199
0 commit comments