diff --git a/.changeset/humble-tips-try.md b/.changeset/humble-tips-try.md new file mode 100644 index 00000000000..ecc28ea0aaa --- /dev/null +++ b/.changeset/humble-tips-try.md @@ -0,0 +1,5 @@ +--- +'@tanstack/query-core': patch +--- + +Improve `partialMatchKey` performance in query-core. diff --git a/packages/query-core/src/utils.ts b/packages/query-core/src/utils.ts index b97b2cc5a33..f442ab86fdc 100644 --- a/packages/query-core/src/utils.ts +++ b/packages/query-core/src/utils.ts @@ -256,7 +256,22 @@ export function partialMatchKey(a: any, b: any): boolean { } if (a && b && typeof a === 'object' && typeof b === 'object') { - return Object.keys(b).every((key) => partialMatchKey(a[key], b[key])) + if (Array.isArray(a) && Array.isArray(b)) { + for (let i = 0; i < b.length; i++) { + if (!partialMatchKey(a[i], b[i])) { + return false + } + } + return true + } + + const bKeys = Object.keys(b) + for (const key of bKeys) { + if (!partialMatchKey(a[key], b[key])) { + return false + } + } + return true } return false