You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When the query of a deferred component rejects, it falls into an infinite render loop. This is consistent and I have written a test case.
I was waiting to see if this was being caused by #8219, but it appears not. Here's the test:
it.only('should throw error if query fails with deferred value',async()=>{functionMyComponent(props: {promise: Promise<string>}){constdata=React.use(props.promise)return<>{data}</>}constkey=queryKey()letrenderCount=0functionPage(){renderCount++const[_count,setCount]=React.useState(0)constcount=React.useDeferredValue(_count)constquery=useQuery({queryKey: [key,count],queryFn: async()=>{awaitsleep(1)// succeed only on first queryif(count===0){return'test'+count}thrownewError('Error test')},retry: false,})return(<React.Suspensefallback="loading.."><buttononClick={()=>setCount((curr)=>curr+1)}>inc</button><MyComponentpromise={query.promise}/></React.Suspense>)}constrendered=renderWithClient(queryClient,<ErrorBoundaryfallbackRender={()=><div>error boundary</div>}><Page/></ErrorBoundary>,)awaitwaitFor(()=>rendered.getByText('loading..'))awaitwaitFor(()=>rendered.getByText('test0'))constconsoleMock=vi.spyOn(console,'error').mockImplementation(()=>undefined)fireEvent.click(rendered.getByText('inc'))awaitwaitFor(()=>rendered.getByText('error boundary'))consoleMock.mockRestore()// unsure what the exact render count should be, but it should be less than 10// it's 6 without `useDeferredValue`, when test passesexpect(renderCount).toBeLessThan(10)})
It currently fails waiting for the error boundary because of the infinite render. If you catch the waitFor throw, you will notice very large values for renderCount:
AssertionError: expected 5828 to be less than 10
The same issue occurs when removing useDeferredValue, and updating the count within a startTransition instead.
Describe the bug
When the query of a deferred component rejects, it falls into an infinite render loop. This is consistent and I have written a test case.
I was waiting to see if this was being caused by #8219, but it appears not. Here's the test:
It currently fails waiting for the error boundary because of the infinite render. If you catch the
waitFor
throw, you will notice very large values forrenderCount
:The same issue occurs when removing
useDeferredValue
, and updating the count within astartTransition
instead.Your minimal, reproducible example
Failing test provided
Steps to reproduce
N/A
Expected behavior
N/A
How often does this bug happen?
Every time
Screenshots or Videos
No response
Platform
OS: Windows 11
Browser: Chrome
Version: 129.0
Tanstack Query adapter
react-query
TanStack Query version
06e315c
TypeScript version
No response
Additional context
No response
The text was updated successfully, but these errors were encountered: