@@ -129,6 +129,9 @@ export function buildSelectors<
129
129
} ) {
130
130
type RootState = _RootState < Definitions , string , string >
131
131
132
+ const selectSkippedQuery = ( state : RootState ) => defaultQuerySubState
133
+ const selectSkippedMutation = ( state : RootState ) => defaultMutationSubState
134
+
132
135
return { buildQuerySelector, buildMutationSelector, selectInvalidatedBy }
133
136
134
137
function withRequestFlags < T extends { status : QueryStatus } > (
@@ -159,20 +162,18 @@ export function buildSelectors<
159
162
endpointDefinition : QueryDefinition < any , any , any , any >
160
163
) {
161
164
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 )
176
177
} ) as QueryResultSelectorFactory < any , RootState >
177
178
}
178
179
@@ -184,14 +185,15 @@ export function buildSelectors<
184
185
} else {
185
186
mutationId = id
186
187
}
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 )
195
197
} ) as MutationResultSelectorFactory < any , RootState >
196
198
}
197
199
0 commit comments