Skip to content
Source
Sign inSign up
TanStack/query

refactor(query-core): simplify mutation scope lookup #12686

MergedTkDodomerged 1 commit intoquery-v6 fromrefs/pull/12686/headmerged by TkDodo View on GitHub

Showing 2 changed files with 20 additions and 33 deletions.

x
0 of 2 viewed, 2 left
5 additions and 0 deletions.changeset/simpler-mutation-scope-lookup.mdAdded
View file
@@ -0,0 +1,5 @@
+---
+'@tanstack/query-core': patch
+---
+​
+Simplify mutation scope lookup and removal to reduce bundle size.
15 additions and 33 deletionspackages/query-core/src/mutationCache.tsModified
View file
@@ -127,7 +127,7 @@
export class MutationCache extends Subscribable<MutationCacheListener> {
#mutations: Set<Mutation<any, any, any, any>>
- #scopes: Map<string, Array<Mutation<any, any, any, any>>>
+ #scopes: Map<string | undefined, Array<Mutation<any, any, any, any>>>
#mutationId: number
​
constructor(public config: MutationCacheConfig = {}) {
@@ -179,15 +179,12 @@
if (this.#mutations.delete(mutation)) {
mutation.destroy()
const scope = scopeFor(mutation)
- if (typeof scope === 'string') {
- const scopedMutations = this.#scopes.get(scope)
- if (scopedMutations) {
- if (scopedMutations.length > 1) {
- const index = scopedMutations.indexOf(mutation)
- if (index !== -1) {
- scopedMutations.splice(index, 1)
- }