Skip to content

Commit e631dc3

Browse files
puneetdixit200TkDodoautofix-ci[bot]
authored
Fix devtools query rows with mutable keys (#10750)
* Fix devtools query rows with mutable keys * ci: apply automated fixes --------- Co-authored-by: puneetdixit200 <[email protected]> Co-authored-by: Dominik Dorfmeister 🔮 <[email protected]> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
1 parent ba6e7be commit e631dc3

3 files changed

Lines changed: 22 additions & 25 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+
Resolve devtools query rows from their stable query hash so mutated object query keys do not break row rendering.

packages/query-devtools/src/Devtools.tsx

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1384,54 +1384,34 @@ const QueryRow: Component<{ query: Query }> = (props) => {
13841384
const t = (light: string, dark: string) => (theme() === 'dark' ? dark : light)
13851385

13861386
const queryState = createSubscribeToQueryCacheBatcher(
1387-
(queryCache) =>
1388-
queryCache().find({
1389-
queryKey: props.query.queryKey,
1390-
})?.state,
1387+
(queryCache) => queryCache().get(props.query.queryHash)?.state,
13911388
true,
13921389
(e) => e.query.queryHash === props.query.queryHash,
13931390
)
13941391

13951392
const isDisabled = createSubscribeToQueryCacheBatcher(
13961393
(queryCache) =>
1397-
queryCache()
1398-
.find({
1399-
queryKey: props.query.queryKey,
1400-
})
1401-
?.isDisabled() ?? false,
1394+
queryCache().get(props.query.queryHash)?.isDisabled() ?? false,
14021395
true,
14031396
(e) => e.query.queryHash === props.query.queryHash,
14041397
)
14051398

14061399
const isStatic = createSubscribeToQueryCacheBatcher(
14071400
(queryCache) =>
1408-
queryCache()
1409-
.find({
1410-
queryKey: props.query.queryKey,
1411-
})
1412-
?.isStatic() ?? false,
1401+
queryCache().get(props.query.queryHash)?.isStatic() ?? false,
14131402
true,
14141403
(e) => e.query.queryHash === props.query.queryHash,
14151404
)
14161405

14171406
const isStale = createSubscribeToQueryCacheBatcher(
1418-
(queryCache) =>
1419-
queryCache()
1420-
.find({
1421-
queryKey: props.query.queryKey,
1422-
})
1423-
?.isStale() ?? false,
1407+
(queryCache) => queryCache().get(props.query.queryHash)?.isStale() ?? false,
14241408
true,
14251409
(e) => e.query.queryHash === props.query.queryHash,
14261410
)
14271411

14281412
const observers = createSubscribeToQueryCacheBatcher(
14291413
(queryCache) =>
1430-
queryCache()
1431-
.find({
1432-
queryKey: props.query.queryKey,
1433-
})
1434-
?.getObserversCount() ?? 0,
1414+
queryCache().get(props.query.queryHash)?.getObserversCount() ?? 0,
14351415
true,
14361416
(e) => e.query.queryHash === props.query.queryHash,
14371417
)

packages/query-devtools/src/__tests__/Devtools.test.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,18 @@ describe('Devtools', () => {
390390
expect(rendered.getByText('static')).toBeInTheDocument()
391391
expect(rendered.getByLabelText(/, static/)).toBeInTheDocument()
392392
})
393+
394+
it('should render a query row when an object query key is mutated in place', () => {
395+
const filters = { page: 1 }
396+
queryClient.setQueryData(['mutable-key', filters], 'x')
397+
filters.page = 2
398+
399+
const rendered = renderDevtools({ initialIsOpen: true })
400+
401+
expect(
402+
rendered.getByLabelText(/Query key \["mutable-key",\{"page":1\}\]/),
403+
).toBeInTheDocument()
404+
})
393405
})
394406

395407
describe('picture-in-picture', () => {

0 commit comments

Comments
 (0)