Skip to content

Commit 3042860

Browse files
Raashish AggarwalTkDodo
andauthored
fix(query-devtools): handle missing query row state (#10772)
Co-authored-by: Dominik Dorfmeister 🔮 <office@dorfmeister.cc>
1 parent e631dc3 commit 3042860

4 files changed

Lines changed: 19 additions & 4 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@tanstack/query-devtools': patch
3+
---
4+
5+
Avoid crashing devtools query rows when a cached query state is temporarily unavailable.

packages/query-devtools/src/Devtools.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1418,7 +1418,7 @@ const QueryRow: Component<{ query: Query }> = (props) => {
14181418

14191419
const color = createMemo(() =>
14201420
getQueryStatusColor({
1421-
queryState: queryState()!,
1421+
queryState: queryState(),
14221422
observerCount: observers(),
14231423
isStale: isStale(),
14241424
}),

packages/query-devtools/src/__tests__/utils.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1573,6 +1573,16 @@ describe('Utils tests', () => {
15731573
).toBe('gray')
15741574
})
15751575

1576+
it('should return "gray" when the query state is unavailable', () => {
1577+
expect(
1578+
getQueryStatusColor({
1579+
queryState: undefined,
1580+
observerCount: 0,
1581+
isStale: false,
1582+
}),
1583+
).toBe('gray')
1584+
})
1585+
15761586
it('should return "purple" when fetchStatus is "paused"', () => {
15771587
expect(
15781588
getQueryStatusColor({

packages/query-devtools/src/utils.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@ export function getQueryStatusColor({
3131
observerCount,
3232
isStale,
3333
}: {
34-
queryState: Query['state']
34+
queryState: Query['state'] | undefined
3535
observerCount: number
3636
isStale: boolean
3737
}) {
38-
return queryState.fetchStatus === 'fetching'
38+
return queryState?.fetchStatus === 'fetching'
3939
? 'blue'
4040
: !observerCount
4141
? 'gray'
42-
: queryState.fetchStatus === 'paused'
42+
: queryState?.fetchStatus === 'paused'
4343
? 'purple'
4444
: isStale
4545
? 'yellow'

0 commit comments

Comments
 (0)