Skip to content

Commit 269ecf0

Browse files
authored
Merge pull request #377 from oasisprotocol/lw/fix-fragile-queries
Fix fragile react queries
2 parents ee3bf0c + c390df9 commit 269ecf0

File tree

5 files changed

+32
-13
lines changed

5 files changed

+32
-13
lines changed

.changelog/377.trivial.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix fragile react queries

src/components/AppsList/index.tsx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,21 @@ export const AppsList: FC<AppsListProps> = ({ emptyState, type }) => {
1919
// Fallback is needed to render Explore page content without wallet connection
2020
const network = useNetwork(type === 'dashboard' ? undefined : 'mainnet')
2121

22-
const { data, fetchNextPage, hasNextPage, isFetchingNextPage, isLoading, isFetched } = useInfiniteQuery({
23-
queryKey: [...getGetRuntimeRoflAppsQueryKey(network, 'sapphire'), type],
24-
queryFn: async ({ pageParam = 0 }) => {
25-
const result = await GetRuntimeRoflApps(network, 'sapphire', {
22+
const appsQueryParams = (pageParam = 0) =>
23+
[
24+
network,
25+
'sapphire',
26+
{
2627
limit: pageLimit,
2728
offset: pageParam,
2829
admin: type === 'dashboard' ? address : undefined,
2930
sort_by: type === 'dashboard' ? 'created_at_desc' : undefined,
30-
})
31+
},
32+
] satisfies Parameters<typeof GetRuntimeRoflApps>
33+
const { data, fetchNextPage, hasNextPage, isFetchingNextPage, isLoading, isFetched } = useInfiniteQuery({
34+
queryKey: ['infinite', ...getGetRuntimeRoflAppsQueryKey(...appsQueryParams())],
35+
queryFn: async ({ pageParam = 0 }) => {
36+
const result = await GetRuntimeRoflApps(...appsQueryParams(pageParam))
3137
return result
3238
},
3339
initialPageParam: 0,

src/pages/Dashboard/Machines/index.tsx

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { useInfiniteQuery } from '@tanstack/react-query'
55
import { useInView } from 'react-intersection-observer'
66
import { useAccount } from 'wagmi'
77
import { useNetwork } from '../../../hooks/useNetwork'
8-
import { getGetRuntimeRoflAppsQueryKey, GetRuntimeRoflmarketInstances } from '../../../nexus/api'
8+
import { getGetRuntimeRoflmarketInstancesQueryKey, GetRuntimeRoflmarketInstances } from '../../../nexus/api'
99
import { MachineCard } from '../../../components/MachineCard'
1010

1111
const pageLimit = 9
@@ -15,14 +15,20 @@ export const Machines: FC = () => {
1515
const { ref, inView } = useInView()
1616
const network = useNetwork()
1717

18-
const { data, fetchNextPage, hasNextPage, isFetchingNextPage, isLoading, isFetched } = useInfiniteQuery({
19-
queryKey: [...getGetRuntimeRoflAppsQueryKey(network, 'sapphire')],
20-
queryFn: async ({ pageParam = 0 }) => {
21-
const result = await GetRuntimeRoflmarketInstances(network, 'sapphire', {
18+
const machinesQueryParams = (pageParam = 0) =>
19+
[
20+
network,
21+
'sapphire',
22+
{
2223
limit: pageLimit,
2324
offset: pageParam,
2425
admin: address,
25-
})
26+
},
27+
] satisfies Parameters<typeof GetRuntimeRoflmarketInstances>
28+
const { data, fetchNextPage, hasNextPage, isFetchingNextPage, isLoading, isFetched } = useInfiniteQuery({
29+
queryKey: ['infinite', ...getGetRuntimeRoflmarketInstancesQueryKey(...machinesQueryParams())],
30+
queryFn: async ({ pageParam = 0 }) => {
31+
const result = await GetRuntimeRoflmarketInstances(...machinesQueryParams(pageParam))
2632
return result
2733
},
2834
initialPageParam: 0,

src/pages/Dashboard/MachinesDetails/index.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ export const MachinesDetails: FC = () => {
2929
'sapphire',
3030
provider!,
3131
id!,
32+
{
33+
// @ts-expect-error Incorrect type demands queryKey
34+
query: {
35+
refetchInterval: 10_000, // Most useful when waiting for net.oasis.scheduler.rak
36+
},
37+
},
3238
)
3339
const { data, isLoading, isFetched } = roflMachinesQuery
3440
const machine = data?.data

src/pages/Dashboard/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ export const Dashboard: FC = () => {
2727
sort_by: 'created_at_desc',
2828
},
2929
{
30+
// @ts-expect-error Incorrect type demands queryKey
3031
query: {
31-
queryKey: ['roflAppsPolling', network, address],
3232
refetchInterval: refetchInterval,
3333
},
3434
},
@@ -43,8 +43,8 @@ export const Dashboard: FC = () => {
4343
admin: address,
4444
},
4545
{
46+
// @ts-expect-error Incorrect type demands queryKey
4647
query: {
47-
queryKey: ['roflmachinePolling', network, address],
4848
refetchInterval: refetchInterval,
4949
},
5050
},

0 commit comments

Comments
 (0)