Skip to content
Source
Sign inSign up
TanStack/query

`useQueries` sometimes throws uncaught exception when `queries` length increases #9971

Send to my agent
Closednwrahnema(GitHub profile, opens in a new tab) opened this issue 2 comments

Describe the bug

When the number of queries passed to useQueries increases, useQueries can sometimes throw an exception.

When debugging the code, I found that this was due to trackResult receiving a result array that is shorter than matches thus making observerResult undefined:

Uncaught TypeError: Cannot convert undefined or null to object
    at Object.keys (<anonymous>)
    at _a9.trackResult (queryObserver.ts:273:12)
    at queriesObserver.ts:192:26
    at Array.map (<anonymous>)
    at _a10.trackResult_fn (queriesObserver.ts:189:20)
    at _a10.notify_fn2 (queriesObserver.ts:264:26)
    at _a10.onUpdate_fn (queriesObserver.ts:257:7)
    at queriesObserver.ts:141:11
    at queryObserver.ts:736:11
    at Set.forEach (<anonymous>)
    at queryObserver.ts:735:24
    at Object.batch (notifyManager.ts:52:18)
    at _a9.notify_fn (queryObserver.ts:732:19)
    at _a9.updateResult (queryObserver.ts:701:5)
    at _a9.setOptions (queryObserver.ts:198:10)
    at queriesObserver.ts:112:24
    at Array.forEach (<anonymous>)
    at queriesObserver.ts:111:26
    at Object.batch (notifyManager.ts:52:18)
    at _a10.setQueries (queriesObserver.ts:104:19)
    at useQueries.ts:282:14
    at commitHookEffectListMount (react-dom.development.js:23150:26)
    at commitPassiveMountOnFiber (react-dom.development.js:24926:13)
    at commitPassiveMountEffects_complete (react-dom.development.js:24891:9)
    at commitPassiveMountEffects_begin (react-dom.development.js:24878:7)
    at commitPassiveMountEffects (react-dom.development.js:24866:3)
    at flushPassiveEffectsImpl (react-dom.development.js:27039:3)
    at flushPassiveEffects (react-dom.development.js:26984:14)
    at performSyncWorkOnRoot (react-dom.development.js:26076:3)
    at flushSyncCallbacks (react-dom.development.js:12042:22)
    at commitRootImpl (react-dom.development.js:26959:3)
    at commitRoot (react-dom.development.js:26682:5)
    at finishConcurrentRender (react-dom.development.js:25981:9)
    at performConcurrentWorkOnRoot (react-dom.development.js:25809:7)
    at workLoop (scheduler.development.js:266:34)
    at flushWork (scheduler.development.js:239:14)
    at MessagePort.performWorkUntilDeadline (scheduler.development.js:533:21)

In version 5.69.2 I get this error, and in 5.90.11 I get Uncaught TypeError: Cannot create proxy with a non-object as target or handler

Unfortunately, I have been unable to create a reproducible example outside of my work environment - however I was able to binary search the release history to find that this bug was introduced in v5.69.2 making it very likely it's this commit. Sorry for the unhelpfulness but I hope maybe there's something obvious there you're able to find.

Your minimal, reproducible example

N/A

Steps to reproduce

Use useQueries and increment the number of queries while some queries are in progress

Expected behavior

I would expect no exception to be thrown

How often does this bug happen?

Often

Screenshots or Videos

No response

Platform

  • OS: macOS
  • Browser: Chrome
  • Version: 143.0.7499.110

Tanstack Query adapter

react-query

TanStack Query version

v5.69.2 and v5.90.11

TypeScript version

v5.5.4

Additional context

No response

  1. 📝 CodeRabbit Plan Mode

    Generate an implementation plan and prompts that you can use with your favorite coding agent.

    • Create Plan
    Examples

    TanStack/query#9576 - fix(core): do not reject promise right away - only when promise gets used [merged] TanStack/query#9592 - fix(query-core): ensure combine re-executes after cache restoration with memoized combine [merged] TanStack/query#9639 - fix(query-core, react-query): infinite re-renders in useQueries [merged] TanStack/query#9772 - fix(core): observing "promise" needs to implicitly observe "data" [merged] TanStack/query#9886 - fix: Prevent infinite render loops when useSuspenseQueries has duplicate queryKeys [merged]

    👤 Suggested Assignees


    🧪 Issue enrichment is currently in early access.

    To disable automatic issue enrichment, add the following to your .coderabbit.yaml:

    issue_enrichment:
      auto_enrich:
        enabled: false
  2. TkDodo closed this

Sign in to join this conversation.