diff --git a/docs/src/pages/guides/migrating-to-react-query-4.md b/docs/src/pages/guides/migrating-to-react-query-4.md index c3ec75d6cb..a60331b915 100644 --- a/docs/src/pages/guides/migrating-to-react-query-4.md +++ b/docs/src/pages/guides/migrating-to-react-query-4.md @@ -93,3 +93,20 @@ For the same reason, those have also been combined: ``` This flag defaults to `active` because `refetchActive` defaulted to `true`. This means we also need a way to tell `invalidateQueries` to not refetch at all, which is why a fourth option (`none`) is also allowed here. + +### The `src/react` directory was renamed to `src/reactjs` + +Previously, react-query had a directory named `react` which imported from the `react` module. This could cause problems with some Jest configurations, resulting in errors when running tests like: + +``` +TypeError: Cannot read property 'createContext' of undefined +``` + +With the renamed directory this no longer is an issue. + +If you were importing anything from `'react-query/react'` directly in your project (as opposed to just `'react-query'`), then you need to update your imports: + +```diff +- import { QueryClientProvider } from 'react-query/react'; ++ import { QueryClientProvider } from 'react-query/reactjs'; +``` diff --git a/package.json b/package.json index 560a5dcec6..6207edf8ec 100644 --- a/package.json +++ b/package.json @@ -16,13 +16,13 @@ "module": "es/index.js", "sideEffects": [ "es/index.js", - "es/react/index.js", - "es/react/setBatchUpdatesFn.js", - "es/react/setLogger.js", + "es/reactjs/index.js", + "es/reactjs/setBatchUpdatesFn.js", + "es/reactjs/setLogger.js", "lib/index.js", - "lib/react/index.js", - "lib/react/setBatchUpdatesFn.js", - "lib/react/setLogger.js" + "lib/reactjs/index.js", + "lib/reactjs/setBatchUpdatesFn.js", + "lib/reactjs/setLogger.js" ], "scripts": { "test": "is-ci \"test:ci\" \"test:dev\"", @@ -60,7 +60,7 @@ "createAsyncStoragePersistor-experimental", "broadcastQueryClient-experimental", "lib", - "react", + "reactjs", "scripts", "types" ], @@ -81,7 +81,11 @@ } }, "typesVersions": { - "<4.1": { "types/*": ["types/ts3.8/*"] } + "<4.1": { + "types/*": [ + "types/ts3.8/*" + ] + } }, "devDependencies": { "@babel/cli": "^7.11.6", diff --git a/react/package.json b/react/package.json deleted file mode 100644 index 02f74bc64a..0000000000 --- a/react/package.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "internal": true, - "main": "../lib/react/index.js", - "module": "../es/react/index.js", - "types": "../types/react/index.d.ts" -} diff --git a/reactjs/package.json b/reactjs/package.json new file mode 100644 index 0000000000..8d0e431ae3 --- /dev/null +++ b/reactjs/package.json @@ -0,0 +1,6 @@ +{ + "internal": true, + "main": "../lib/reactjs/index.js", + "module": "../es/reactjs/index.js", + "types": "../types/reactjs/index.d.ts" +} diff --git a/src/core/tests/hydration.test.tsx b/src/core/tests/hydration.test.tsx index 2de31d1132..cc7ae08a80 100644 --- a/src/core/tests/hydration.test.tsx +++ b/src/core/tests/hydration.test.tsx @@ -1,4 +1,4 @@ -import { mockNavigatorOnLine, sleep } from '../../react/tests/utils' +import { mockNavigatorOnLine, sleep } from '../../reactjs/tests/utils' import { QueryCache } from '../queryCache' import { QueryClient } from '../queryClient' import { dehydrate, hydrate } from '../hydration' diff --git a/src/core/tests/infiniteQueryBehavior.test.tsx b/src/core/tests/infiniteQueryBehavior.test.tsx index 92d5c6c9f9..8ab5389936 100644 --- a/src/core/tests/infiniteQueryBehavior.test.tsx +++ b/src/core/tests/infiniteQueryBehavior.test.tsx @@ -1,5 +1,5 @@ import { waitFor } from '@testing-library/react' -import { queryKey, mockConsoleError } from '../../react/tests/utils' +import { queryKey, mockConsoleError } from '../../reactjs/tests/utils' import { QueryClient, InfiniteQueryObserver, diff --git a/src/core/tests/infiniteQueryObserver.test.tsx b/src/core/tests/infiniteQueryObserver.test.tsx index e0fff2a28b..27094fe615 100644 --- a/src/core/tests/infiniteQueryObserver.test.tsx +++ b/src/core/tests/infiniteQueryObserver.test.tsx @@ -1,4 +1,4 @@ -import { sleep, queryKey } from '../../react/tests/utils' +import { sleep, queryKey } from '../../reactjs/tests/utils' import { QueryClient, InfiniteQueryObserver } from '../..' describe('InfiniteQueryObserver', () => { diff --git a/src/core/tests/mutationCache.test.tsx b/src/core/tests/mutationCache.test.tsx index 425c438907..2e701427ed 100644 --- a/src/core/tests/mutationCache.test.tsx +++ b/src/core/tests/mutationCache.test.tsx @@ -1,4 +1,4 @@ -import { queryKey, mockConsoleError } from '../../react/tests/utils' +import { queryKey, mockConsoleError } from '../../reactjs/tests/utils' import { MutationCache, QueryClient } from '../..' describe('mutationCache', () => { diff --git a/src/core/tests/mutationObserver.test.tsx b/src/core/tests/mutationObserver.test.tsx index 68521fb4fa..c1f577f936 100644 --- a/src/core/tests/mutationObserver.test.tsx +++ b/src/core/tests/mutationObserver.test.tsx @@ -1,5 +1,5 @@ import { waitFor } from '@testing-library/react' -import { sleep } from '../../react/tests/utils' +import { sleep } from '../../reactjs/tests/utils' import { QueryClient, MutationObserver } from '../..' describe('mutationObserver', () => { diff --git a/src/core/tests/mutations.test.tsx b/src/core/tests/mutations.test.tsx index f606ee6028..ad189c5189 100644 --- a/src/core/tests/mutations.test.tsx +++ b/src/core/tests/mutations.test.tsx @@ -1,5 +1,5 @@ import { QueryClient } from '../..' -import { mockConsoleError, queryKey, sleep } from '../../react/tests/utils' +import { mockConsoleError, queryKey, sleep } from '../../reactjs/tests/utils' import { MutationState } from '../mutation' import { MutationObserver } from '../mutationObserver' diff --git a/src/core/tests/queriesObserver.test.tsx b/src/core/tests/queriesObserver.test.tsx index 9b0a7535e9..f890d9be28 100644 --- a/src/core/tests/queriesObserver.test.tsx +++ b/src/core/tests/queriesObserver.test.tsx @@ -1,5 +1,5 @@ import { waitFor } from '@testing-library/react' -import { sleep, queryKey } from '../../react/tests/utils' +import { sleep, queryKey } from '../../reactjs/tests/utils' import { QueryClient, QueriesObserver, diff --git a/src/core/tests/query.test.tsx b/src/core/tests/query.test.tsx index 583799cfb3..5bd06adf2d 100644 --- a/src/core/tests/query.test.tsx +++ b/src/core/tests/query.test.tsx @@ -3,7 +3,7 @@ import { queryKey, mockVisibilityState, mockConsoleError, -} from '../../react/tests/utils' +} from '../../reactjs/tests/utils' import { QueryCache, QueryClient, diff --git a/src/core/tests/queryCache.test.tsx b/src/core/tests/queryCache.test.tsx index 4a17d2d0a0..edff7dfff3 100644 --- a/src/core/tests/queryCache.test.tsx +++ b/src/core/tests/queryCache.test.tsx @@ -1,4 +1,4 @@ -import { sleep, queryKey, mockConsoleError } from '../../react/tests/utils' +import { sleep, queryKey, mockConsoleError } from '../../reactjs/tests/utils' import { QueryCache, QueryClient } from '../..' import { Query } from '.././query' diff --git a/src/core/tests/queryClient.test.tsx b/src/core/tests/queryClient.test.tsx index 47f0cd7f07..16fe2936f7 100644 --- a/src/core/tests/queryClient.test.tsx +++ b/src/core/tests/queryClient.test.tsx @@ -1,4 +1,4 @@ -import { sleep, queryKey, mockConsoleError } from '../../react/tests/utils' +import { sleep, queryKey, mockConsoleError } from '../../reactjs/tests/utils' import { InfiniteQueryObserver, QueryCache, diff --git a/src/core/tests/queryObserver.test.tsx b/src/core/tests/queryObserver.test.tsx index aea4dbc46a..31fb1ea27b 100644 --- a/src/core/tests/queryObserver.test.tsx +++ b/src/core/tests/queryObserver.test.tsx @@ -3,7 +3,7 @@ import { queryKey, mockConsoleError, expectType, -} from '../../react/tests/utils' +} from '../../reactjs/tests/utils' import { QueryClient, QueryObserver, diff --git a/src/core/tests/utils.test.tsx b/src/core/tests/utils.test.tsx index 2c907c6e95..13fda6b217 100644 --- a/src/core/tests/utils.test.tsx +++ b/src/core/tests/utils.test.tsx @@ -7,7 +7,7 @@ import { scheduleMicrotask, } from '../utils' import { QueryClient, QueryCache, setLogger, Logger } from '../..' -import { queryKey } from '../../react/tests/utils' +import { queryKey } from '../../reactjs/tests/utils' import { Mutation } from '../mutation' import { waitFor } from '@testing-library/dom' diff --git a/src/createWebStoragePersistor-experimental/tests/storageIsFull.test.ts b/src/createWebStoragePersistor-experimental/tests/storageIsFull.test.ts index 2b19a1d45b..328884d4d1 100644 --- a/src/createWebStoragePersistor-experimental/tests/storageIsFull.test.ts +++ b/src/createWebStoragePersistor-experimental/tests/storageIsFull.test.ts @@ -1,5 +1,5 @@ import { dehydrate, MutationCache, QueryCache, QueryClient } from '../../core' -import { sleep } from '../../react/tests/utils' +import { sleep } from '../../reactjs/tests/utils' import { createWebStoragePersistor } from '../index' function getMockStorage(limitSize?: number) { diff --git a/src/hydration/index.ts b/src/hydration/index.ts new file mode 100644 index 0000000000..9a53924dea --- /dev/null +++ b/src/hydration/index.ts @@ -0,0 +1,15 @@ +// This package once contained these functions, but they have now been moved +// into the core and react packages. +// They are re-exported here to avoid a breaking change, but this package +// should be considered deprecated and removed in a future major version. +export { dehydrate, hydrate, useHydrate, Hydrate } from 'react-query' + +// Types +export type { + DehydrateOptions, + DehydratedState, + HydrateOptions, + ShouldDehydrateMutationFunction, + ShouldDehydrateQueryFunction, +} from '../core/hydration' +export type { HydrateProps } from '../reactjs/Hydrate' diff --git a/src/index.ts b/src/index.ts index 5a7d84f690..9fe661089c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,2 +1,2 @@ export * from './core' -export * from './react' +export * from './reactjs' diff --git a/src/react/Hydrate.tsx b/src/reactjs/Hydrate.tsx similarity index 100% rename from src/react/Hydrate.tsx rename to src/reactjs/Hydrate.tsx diff --git a/src/react/QueryClientProvider.tsx b/src/reactjs/QueryClientProvider.tsx similarity index 100% rename from src/react/QueryClientProvider.tsx rename to src/reactjs/QueryClientProvider.tsx diff --git a/src/react/QueryErrorResetBoundary.tsx b/src/reactjs/QueryErrorResetBoundary.tsx similarity index 100% rename from src/react/QueryErrorResetBoundary.tsx rename to src/reactjs/QueryErrorResetBoundary.tsx diff --git a/src/react/index.ts b/src/reactjs/index.ts similarity index 100% rename from src/react/index.ts rename to src/reactjs/index.ts diff --git a/src/react/logger.native.ts b/src/reactjs/logger.native.ts similarity index 100% rename from src/react/logger.native.ts rename to src/reactjs/logger.native.ts diff --git a/src/react/logger.ts b/src/reactjs/logger.ts similarity index 100% rename from src/react/logger.ts rename to src/reactjs/logger.ts diff --git a/src/react/reactBatchedUpdates.native.ts b/src/reactjs/reactBatchedUpdates.native.ts similarity index 100% rename from src/react/reactBatchedUpdates.native.ts rename to src/reactjs/reactBatchedUpdates.native.ts diff --git a/src/react/reactBatchedUpdates.ts b/src/reactjs/reactBatchedUpdates.ts similarity index 100% rename from src/react/reactBatchedUpdates.ts rename to src/reactjs/reactBatchedUpdates.ts diff --git a/src/react/setBatchUpdatesFn.ts b/src/reactjs/setBatchUpdatesFn.ts similarity index 100% rename from src/react/setBatchUpdatesFn.ts rename to src/reactjs/setBatchUpdatesFn.ts diff --git a/src/react/setLogger.ts b/src/reactjs/setLogger.ts similarity index 100% rename from src/react/setLogger.ts rename to src/reactjs/setLogger.ts diff --git a/src/react/tests/Hydrate.test.tsx b/src/reactjs/tests/Hydrate.test.tsx similarity index 100% rename from src/react/tests/Hydrate.test.tsx rename to src/reactjs/tests/Hydrate.test.tsx diff --git a/src/react/tests/QueryClientProvider.test.tsx b/src/reactjs/tests/QueryClientProvider.test.tsx similarity index 100% rename from src/react/tests/QueryClientProvider.test.tsx rename to src/reactjs/tests/QueryClientProvider.test.tsx diff --git a/src/react/tests/QueryResetErrorBoundary.test.tsx b/src/reactjs/tests/QueryResetErrorBoundary.test.tsx similarity index 100% rename from src/react/tests/QueryResetErrorBoundary.test.tsx rename to src/reactjs/tests/QueryResetErrorBoundary.test.tsx diff --git a/src/react/tests/logger.native.test.tsx b/src/reactjs/tests/logger.native.test.tsx similarity index 100% rename from src/react/tests/logger.native.test.tsx rename to src/reactjs/tests/logger.native.test.tsx diff --git a/src/react/tests/ssr-hydration.test.tsx b/src/reactjs/tests/ssr-hydration.test.tsx similarity index 100% rename from src/react/tests/ssr-hydration.test.tsx rename to src/reactjs/tests/ssr-hydration.test.tsx diff --git a/src/react/tests/ssr.test.tsx b/src/reactjs/tests/ssr.test.tsx similarity index 100% rename from src/react/tests/ssr.test.tsx rename to src/reactjs/tests/ssr.test.tsx diff --git a/src/react/tests/suspense.test.tsx b/src/reactjs/tests/suspense.test.tsx similarity index 100% rename from src/react/tests/suspense.test.tsx rename to src/reactjs/tests/suspense.test.tsx diff --git a/src/react/tests/useInfiniteQuery.test.tsx b/src/reactjs/tests/useInfiniteQuery.test.tsx similarity index 100% rename from src/react/tests/useInfiniteQuery.test.tsx rename to src/reactjs/tests/useInfiniteQuery.test.tsx diff --git a/src/react/tests/useIsFetching.test.tsx b/src/reactjs/tests/useIsFetching.test.tsx similarity index 100% rename from src/react/tests/useIsFetching.test.tsx rename to src/reactjs/tests/useIsFetching.test.tsx diff --git a/src/react/tests/useIsMutating.test.tsx b/src/reactjs/tests/useIsMutating.test.tsx similarity index 100% rename from src/react/tests/useIsMutating.test.tsx rename to src/reactjs/tests/useIsMutating.test.tsx diff --git a/src/react/tests/useMutation.test.tsx b/src/reactjs/tests/useMutation.test.tsx similarity index 100% rename from src/react/tests/useMutation.test.tsx rename to src/reactjs/tests/useMutation.test.tsx diff --git a/src/react/tests/useQueries.test.tsx b/src/reactjs/tests/useQueries.test.tsx similarity index 100% rename from src/react/tests/useQueries.test.tsx rename to src/reactjs/tests/useQueries.test.tsx diff --git a/src/react/tests/useQuery.test.tsx b/src/reactjs/tests/useQuery.test.tsx similarity index 100% rename from src/react/tests/useQuery.test.tsx rename to src/reactjs/tests/useQuery.test.tsx diff --git a/src/react/tests/utils.tsx b/src/reactjs/tests/utils.tsx similarity index 100% rename from src/react/tests/utils.tsx rename to src/reactjs/tests/utils.tsx diff --git a/src/react/types.ts b/src/reactjs/types.ts similarity index 100% rename from src/react/types.ts rename to src/reactjs/types.ts diff --git a/src/react/useBaseQuery.ts b/src/reactjs/useBaseQuery.ts similarity index 100% rename from src/react/useBaseQuery.ts rename to src/reactjs/useBaseQuery.ts diff --git a/src/react/useInfiniteQuery.ts b/src/reactjs/useInfiniteQuery.ts similarity index 100% rename from src/react/useInfiniteQuery.ts rename to src/reactjs/useInfiniteQuery.ts diff --git a/src/react/useIsFetching.ts b/src/reactjs/useIsFetching.ts similarity index 100% rename from src/react/useIsFetching.ts rename to src/reactjs/useIsFetching.ts diff --git a/src/react/useIsMutating.ts b/src/reactjs/useIsMutating.ts similarity index 100% rename from src/react/useIsMutating.ts rename to src/reactjs/useIsMutating.ts diff --git a/src/react/useMutation.ts b/src/reactjs/useMutation.ts similarity index 100% rename from src/react/useMutation.ts rename to src/reactjs/useMutation.ts diff --git a/src/react/useQueries.ts b/src/reactjs/useQueries.ts similarity index 100% rename from src/react/useQueries.ts rename to src/reactjs/useQueries.ts diff --git a/src/react/useQuery.ts b/src/reactjs/useQuery.ts similarity index 100% rename from src/react/useQuery.ts rename to src/reactjs/useQuery.ts diff --git a/src/react/utils.ts b/src/reactjs/utils.ts similarity index 100% rename from src/react/utils.ts rename to src/reactjs/utils.ts diff --git a/src/ts3.8/useQueries.ts b/src/ts3.8/useQueries.ts index b710556d35..a143b5359f 100644 --- a/src/ts3.8/useQueries.ts +++ b/src/ts3.8/useQueries.ts @@ -1,4 +1,4 @@ -import { UseQueryOptions, UseQueryResult } from '../react/types' +import { UseQueryOptions, UseQueryResult } from '../reactjs/types' /** * Backwards-compatible definition for TS < 4.1