Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/healthy-apricots-chew.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@suspensive/react-query-4": minor
"@suspensive/react-query-5": minor
"@suspensive/react-query": minor
---

chore: update react-query dependencies to version 4.40.0 and deprecate old options
3 changes: 2 additions & 1 deletion docs/suspensive.org/src/components/BubbleChart.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
'use client'

import { ErrorBoundary, Suspense } from '@suspensive/react'
import { SuspenseQuery, queryOptions } from '@suspensive/react-query-4'
import { SuspenseQuery } from '@suspensive/react-query-4'
import {
QueryClient,
QueryClientProvider,
QueryErrorResetBoundary,
queryOptions,
} from '@tanstack/react-query'
import { ReactQueryDevtools } from '@tanstack/react-query-devtools'
import * as d3 from 'd3'
Expand Down
2 changes: 1 addition & 1 deletion packages/react-query-4/src/PrefetchQuery.test-d.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { queryOptions } from '@tanstack/react-query'
import type { ReactNode } from 'react'
import { describe, expectTypeOf, it } from 'vitest'
import { PrefetchQuery } from './PrefetchQuery'
import { queryOptions } from './queryOptions'
import { queryFn, queryKey } from './test-utils'

describe('<PrefetchQuery/>', () => {
Expand All @@ -11,7 +11,7 @@
queryKey={queryKey}
queryFn={queryFn}
//@ts-expect-error no suspense
suspense={boolean}

Check warning on line 14 in packages/react-query-4/src/PrefetchQuery.test-d.tsx

View workflow job for this annotation

GitHub Actions / Check quality (ci:eslint)

Unsafe assignment of an error typed value
/>
))()
;(() => (
Expand All @@ -19,7 +19,7 @@
queryKey={queryKey}
queryFn={queryFn}
//@ts-expect-error no useErrorBoundary
useErrorBoundary={boolean}

Check warning on line 22 in packages/react-query-4/src/PrefetchQuery.test-d.tsx

View workflow job for this annotation

GitHub Actions / Check quality (ci:eslint)

Unsafe assignment of an error typed value
/>
))()
;(() => (
Expand All @@ -27,7 +27,7 @@
queryKey={queryKey}
queryFn={queryFn}
//@ts-expect-error no enabled
enabled={boolean}

Check warning on line 30 in packages/react-query-4/src/PrefetchQuery.test-d.tsx

View workflow job for this annotation

GitHub Actions / Check quality (ci:eslint)

Unsafe assignment of an error typed value
/>
))()
;(() => (
Expand Down
4 changes: 1 addition & 3 deletions packages/react-query-4/src/SuspenseQueries.test-d.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { type UseSuspenseQueryResult, queryOptions } from '@tanstack/react-query'
import type { ReactNode } from 'react'
import { describe, expectTypeOf, it } from 'vitest'
import { queryOptions } from './queryOptions'
import { SuspenseQueries } from './SuspenseQueries'
import { queryFn, queryKey } from './test-utils'
import type { UseSuspenseQueryResult } from './useSuspenseQuery'

describe('<SuspenseQueries/>', () => {
it('type check', () => {
Expand All @@ -27,7 +26,6 @@ describe('<SuspenseQueries/>', () => {
<SuspenseQueries queries={[{ queryKey, queryFn }, queryOptions({ queryKey, queryFn })]}>
{([
query1,

query2,
// @ts-expect-error Tuple type '[UseSuspenseQueryResult<{ text: string; }, unknown>]' of length '1' has no element at index '2'.
query3,
Expand Down
2 changes: 1 addition & 1 deletion packages/react-query-4/src/SuspenseQueries.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { type SuspenseQueriesOptions, type SuspenseQueriesResults, useSuspenseQueries } from '@tanstack/react-query'
import type { ReactNode } from 'react'
import { type SuspenseQueriesOptions, type SuspenseQueriesResults, useSuspenseQueries } from './useSuspenseQueries'

/**
* We provide these components to clearly express what causes suspense at the same depth.
Expand Down
11 changes: 5 additions & 6 deletions packages/react-query-4/src/SuspenseQuery.test-d.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { type UseSuspenseQueryResult, queryOptions } from '@tanstack/react-query'
import type { ReactNode } from 'react'
import { describe, expectTypeOf, it } from 'vitest'
import { queryOptions } from './queryOptions'
import { SuspenseQuery } from './SuspenseQuery'
import { queryFn, queryKey } from './test-utils'
import type { UseSuspenseQueryResult } from './useSuspenseQuery'

describe('<SuspenseQuery/>', () => {
it('type check', () => {
Expand Down Expand Up @@ -72,7 +71,7 @@ describe('<SuspenseQuery/>', () => {
{(query) => {
expectTypeOf(query).toEqualTypeOf<UseSuspenseQueryResult<{ text: string }>>()
expectTypeOf(query.data).toEqualTypeOf<{ text: string }>()
expectTypeOf(query.status).toEqualTypeOf<'success'>()
expectTypeOf(query.status).toEqualTypeOf<'success' | 'error'>()
return <></>
}}
</SuspenseQuery>
Expand All @@ -82,7 +81,7 @@ describe('<SuspenseQuery/>', () => {
{(selectedQuery) => {
expectTypeOf(selectedQuery).toEqualTypeOf<UseSuspenseQueryResult<string>>()
expectTypeOf(selectedQuery.data).toEqualTypeOf<string>()
expectTypeOf(selectedQuery.status).toEqualTypeOf<'success'>()
expectTypeOf(selectedQuery.status).toEqualTypeOf<'error' | 'success'>()
return <></>
}}
</SuspenseQuery>
Expand All @@ -98,7 +97,7 @@ describe('<SuspenseQuery/>', () => {
{(query) => {
expectTypeOf(query).toEqualTypeOf<UseSuspenseQueryResult<{ text: string }>>()
expectTypeOf(query.data).toEqualTypeOf<{ text: string }>()
expectTypeOf(query.status).toEqualTypeOf<'success'>()
expectTypeOf(query.status).toEqualTypeOf<'error' | 'success'>()
return <></>
}}
</SuspenseQuery>
Expand All @@ -108,7 +107,7 @@ describe('<SuspenseQuery/>', () => {
{(selectedQuery) => {
expectTypeOf(selectedQuery).toEqualTypeOf<UseSuspenseQueryResult<string>>()
expectTypeOf(selectedQuery.data).toEqualTypeOf<string>()
expectTypeOf(selectedQuery.status).toEqualTypeOf<'success'>()
expectTypeOf(selectedQuery.status).toEqualTypeOf<'error' | 'success'>()
return <></>
}}
</SuspenseQuery>
Expand Down
8 changes: 6 additions & 2 deletions packages/react-query-4/src/SuspenseQuery.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import type { QueryKey } from '@tanstack/react-query'
import {
type QueryKey,
type UseSuspenseQueryOptions,
type UseSuspenseQueryResult,
useSuspenseQuery,
} from '@tanstack/react-query'
import type { ReactNode } from 'react'
import { type UseSuspenseQueryOptions, type UseSuspenseQueryResult, useSuspenseQuery } from './useSuspenseQuery'

/**
* We provide these components to clearly express what causes suspense at the same depth.
Expand Down
6 changes: 6 additions & 0 deletions packages/react-query-4/src/infiniteQueryOptions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import type { InfiniteData, QueryKey, UseInfiniteQueryOptions } from '@tanstack/react-query'
import type { OmitKeyof, RequiredKeyof } from './utility-types'

/**
* @deprecated There is no `SelectedInfiniteOptions` in \@tanstack/react-query@^4.40.0.
*/
export type SelectedInfiniteOptions<
TQueryFnData,
TError = unknown,
Expand All @@ -27,6 +30,9 @@ export type SelectedInfiniteOptions<
select: (data: InfiniteData<TQueryFnData>) => InfiniteData<TData>
}

/**
* @deprecated There is no `UnSelectedInfiniteOptions` in \@tanstack/react-query@^4.40.0.
*/
export type UnSelectedInfiniteOptions<
TQueryFnData,
TError = unknown,
Expand Down
40 changes: 25 additions & 15 deletions packages/react-query-4/src/queryOptions.test-d.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import { type UseQueryResult, useQueries, useQuery, useQueryClient } from '@tanstack/react-query'
import {
type UseQueryResult,
type UseSuspenseQueryResult,
queryOptions,
useQueries,
useQuery,
useQueryClient,
useSuspenseQueries,
useSuspenseQuery,
} from '@tanstack/react-query'
import { describe, expectTypeOf, it } from 'vitest'
import { queryOptions } from './queryOptions'
import { SuspenseQuery } from './SuspenseQuery'
import { queryKey } from './test-utils'
import { usePrefetchQuery } from './usePrefetchQuery'
import { useSuspenseQueries } from './useSuspenseQueries'
import { type UseSuspenseQueryResult, useSuspenseQuery } from './useSuspenseQuery'

const query = {
options1: () =>
Expand Down Expand Up @@ -58,26 +64,30 @@ describe('queryOptions', () => {
))()
})
it('should be used with useQueries', () => {
const [query1, query2, query3] = useQueries({
const [
query1,
query2,
// query3
] = useQueries({
queries: [
query.options1(),
{ ...query.options2() },
queryOptions({
queryKey: [...queryKey, 4] as const,
queryFn: () => Promise.resolve({ field: 'success' }),
select: (data) => {
expectTypeOf(data).toEqualTypeOf<{ field: string }>()
return data.field
},
}),
// queryOptions({
// queryKey: [...queryKey, 4] as const,
// queryFn: () => Promise.resolve({ field: 'success' }),
// select: (data) => {
// expectTypeOf(data).toEqualTypeOf<{ field: string }>()
// return data.field
// },
// }),
],
})
expectTypeOf(query1).toEqualTypeOf<UseQueryResult<{ field: string }>>()
expectTypeOf(query1.data).toEqualTypeOf<{ field: string } | undefined>()
expectTypeOf(query2).toEqualTypeOf<UseQueryResult<{ field: string }>>()
expectTypeOf(query2.data).toEqualTypeOf<{ field: string } | undefined>()
expectTypeOf(query3).toEqualTypeOf<UseQueryResult<string>>()
expectTypeOf(query3.data).toEqualTypeOf<string | undefined>()
// expectTypeOf(query3).toEqualTypeOf<UseQueryResult<string>>()
// expectTypeOf(query3.data).toEqualTypeOf<string | undefined>()
})
Comment on lines +67 to +90
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason for commenting out instead of removing it?

Copy link
Member Author

@manudeli manudeli Jul 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was problem already before

image

It's because of @tanstack/react-query v4's useQueries type fault. I'll fix it in TanStack v4

image

it('should be used with useSuspenseQueries', () => {
const [query1, query2, query3] = useSuspenseQueries({
Expand Down
41 changes: 15 additions & 26 deletions packages/react-query-4/src/queryOptions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import type { QueryKey, UseQueryOptions } from '@tanstack/react-query'
import { type QueryKey, type UseQueryOptions, queryOptions as original_queryOptions } from '@tanstack/react-query'
import type { OmitKeyof, RequiredKeyof } from './utility-types'

/**
* @deprecated There is no `SelectedQueryOptions` in \@tanstack/react-query@^4.40.0.
*/
export type SelectedQueryOptions<
TQueryFnData = unknown,
TError = unknown,
Expand Down Expand Up @@ -29,6 +32,9 @@ export type SelectedQueryOptions<
select: (data: TQueryFnData) => TData
}

/**
* @deprecated There is no `UnSelectedQueryOptions` in \@tanstack/react-query@^4.40.0.
*/
export type UnSelectedQueryOptions<
TQueryFnData = unknown,
TError = unknown,
Expand Down Expand Up @@ -58,29 +64,12 @@ export type UnSelectedQueryOptions<
}

/**
* Creates a reusable query options object that can be used across different query hooks.
* Provides better type inference and easier query key management.
*
* @see {@link https://suspensive.org/docs/react-query/queryOptions Suspensive Docs}
* This feature is officially supported in \@tanstack/react-query@^4.40.0, You can proceed with the migration.
* @deprecated Use `queryOptions` from \@tanstack/react-query@^4.40.0
* @example
* ```diff
Comment on lines +68 to +69
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @deprecated Use `queryOptions` from \@tanstack/react-query@^4.40.0
* @example
* @deprecated Use `queryOptions` from \@tanstack/react-query@^4.40.0
* @see (If a migration guide becomes available later.)
* @example

this is a suggestion

* - import { queryOptions } from '@suspensive/react-query'
* + import { queryOptions } from '@tanstack/react-query'
* ```
*/
export function queryOptions<
TQueryFnData = unknown,
TError = unknown,
TData = TQueryFnData,
TQueryKey extends QueryKey = QueryKey,
>(
options: SelectedQueryOptions<TQueryFnData, TError, TData, TQueryKey>
): SelectedQueryOptions<TQueryFnData, TError, TData, TQueryKey>

export function queryOptions<
TQueryFnData = unknown,
TError = unknown,
TData = TQueryFnData,
TQueryKey extends QueryKey = QueryKey,
>(
options: UnSelectedQueryOptions<TQueryFnData, TError, TData, TQueryKey>
): UnSelectedQueryOptions<TQueryFnData, TError, TData, TQueryKey>

export function queryOptions(options: unknown) {
return options
}
export const queryOptions = original_queryOptions
2 changes: 1 addition & 1 deletion packages/react-query-4/src/usePrefetchQuery.test-d.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { queryOptions } from './queryOptions'
import { queryOptions } from '@tanstack/react-query'
import { queryFn, queryKey } from './test-utils'
import { usePrefetchQuery } from './usePrefetchQuery'

Expand Down
10 changes: 4 additions & 6 deletions packages/react-query-4/src/useSuspenseQueries.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { type UseSuspenseQueryResult, queryOptions, useSuspenseQueries } from '@tanstack/react-query'
import { describe, expectTypeOf, it } from 'vitest'
import { queryOptions } from './queryOptions'
import { queryFn, queryKey, select } from './test-utils'
import { useSuspenseQueries } from './useSuspenseQueries'
import type { UseSuspenseQueryResult } from './useSuspenseQuery'

describe('useSuspenseQueries', () => {
it('type check', () => {
Expand Down Expand Up @@ -66,15 +64,15 @@ describe('useSuspenseQueries', () => {
})

expectTypeOf(query).toEqualTypeOf<UseSuspenseQueryResult<{ text: string }>>()
expectTypeOf(query.status).toEqualTypeOf<`success`>()
expectTypeOf(query.status).toEqualTypeOf<'error' | 'success'>()
expectTypeOf(query.data).toEqualTypeOf<{ text: string }>()

expectTypeOf(selectedQuery).toEqualTypeOf<UseSuspenseQueryResult<string>>()
expectTypeOf(selectedQuery.status).toEqualTypeOf<`success`>()
expectTypeOf(selectedQuery.status).toEqualTypeOf<'error' | 'success'>()
expectTypeOf(selectedQuery.data).toEqualTypeOf<string>()

expectTypeOf(selectedQueryByQueryOptions).toEqualTypeOf<UseSuspenseQueryResult<string>>()
expectTypeOf(selectedQueryByQueryOptions.status).toEqualTypeOf<`success`>()
expectTypeOf(selectedQueryByQueryOptions.status).toEqualTypeOf<'error' | 'success'>()
expectTypeOf(selectedQueryByQueryOptions.data).toEqualTypeOf<string>()
})
})
Loading
Loading