Skip to content

Commit

Permalink
Merge branch 'alpha' into feature/queryOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
TkDodo authored Apr 30, 2023
2 parents a896eeb + f74f755 commit 9c7123f
Show file tree
Hide file tree
Showing 24 changed files with 124 additions and 77 deletions.
1 change: 0 additions & 1 deletion .github/workflows/ci-v3.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ on:
- 'v3'
env:
NX_DAEMON: false
NX_VERBOSE_LOGGING: true
NX_CLOUD_ACCESS_TOKEN: ${{ secrets.NX_CLOUD_ACCESS_TOKEN }}
jobs:
test:
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ on:
- 'beta'
env:
NX_DAEMON: false
NX_VERBOSE_LOGGING: true
NX_CLOUD_ACCESS_TOKEN: ${{ secrets.NX_CLOUD_ACCESS_TOKEN }}
jobs:
test-and-publish:
Expand All @@ -31,7 +30,7 @@ jobs:
version: 7
- uses: actions/setup-node@v3
with:
node-version: 16.19.0
node-version: 18.16.0
registry-url: https://registry.npmjs.org/
cache: 'pnpm'
- name: Install dependencies
Expand Down
83 changes: 31 additions & 52 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ name: pr
on: [pull_request]
env:
NX_DAEMON: false
NX_VERBOSE_LOGGING: true
NX_CLOUD_ACCESS_TOKEN: ${{ secrets.NX_CLOUD_ACCESS_TOKEN }}
jobs:
test:
name: 'Test'
agent:
name: 'Nx Cloud Agents'
runs-on: ubuntu-latest
timeout-minutes: 20
strategy:
matrix:
agent: [1, 2, 3, 4]
steps:
- uses: actions/checkout@v3
with:
Expand All @@ -19,20 +22,14 @@ jobs:
version: 7
- uses: actions/setup-node@v3
with:
node-version: 16.19.0
node-version: 18.16.0
cache: 'pnpm'
- name: Install dependencies
run: pnpm --filter "./packages/**" --filter query --prefer-offline install
- name: Run Tests
uses: nick-fields/retry@v2.8.3
with:
command: pnpm test:lib --base=${{ github.event.pull_request.base.sha }}
timeout_minutes: 5
max_attempts: 3
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
lint:
name: 'Lint'
- name: Start Nx Agent ${{ matrix.agent }}
run: npx nx-cloud start-agent
orchestrator:
name: 'Nx Cloud Orchestrator'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand All @@ -45,30 +42,29 @@ jobs:
version: 7
- uses: actions/setup-node@v3
with:
node-version: 16.14.2
node-version: 18.16.0
cache: 'pnpm'
- name: Install dependencies
run: pnpm --filter "./packages/**" --filter query --prefer-offline install
- run: pnpm run test:eslint --base=${{ github.event.pull_request.base.sha }}
typecheck:
name: 'Typecheck'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
ref: ${{ github.head_ref }}
repository: ${{github.event.pull_request.head.repo.full_name}}
- uses: pnpm/action-setup@v2.2.4
with:
version: 7
- uses: actions/setup-node@v3
- name: Derive appropriate SHAs for base and head for `nx affected` commands
uses: nrwl/nx-set-shas@v2
- run: |
echo "BASE: ${{ env.NX_BASE }}"
echo "HEAD: ${{ env.NX_HEAD }}"
- name: Start CI Orchestrator
run: npx nx-cloud start-ci-run
- name: Run All Checks
uses: nick-fields/retry@v2.8.3
env:
BUNDLEWATCH_GITHUB_TOKEN: ${{ secrets.BUNDLEWATCH_GITHUB_TOKEN }}
with:
node-version: 16.14.2
cache: 'pnpm'
- name: Install dependencies
run: pnpm --filter "./packages/**" --filter query --prefer-offline install
- run: pnpm run test:types --base=${{ github.event.pull_request.base.sha }}
timeout_minutes: 5
max_attempts: 3
command: npx nx affected --targets=test:eslint,test:types,test:build,test:lib --base=${{ github.event.pull_request.base.sha }}
- name: Stop Agents
run: npx nx-cloud stop-all-agents
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
format:
name: 'Format'
runs-on: ubuntu-latest
Expand All @@ -83,25 +79,8 @@ jobs:
version: 7
- uses: actions/setup-node@v3
with:
node-version: 16.14.2
node-version: 18.16.0
cache: 'pnpm'
- name: Install dependencies
run: pnpm --filter "./packages/**" --filter query --prefer-offline install
- run: pnpm run test:format --base=${{ github.event.pull_request.base.sha }}
test-build:
name: 'Test Build'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2.2.4
with:
version: 7
- uses: actions/setup-node@v3
with:
node-version: 16.14.2
cache: 'pnpm'
- name: Install dependencies
run: pnpm --filter "./packages/**" --filter query --prefer-offline install
- run: pnpm run test:build
env:
BUNDLEWATCH_GITHUB_TOKEN: ${{ secrets.BUNDLEWATCH_GITHUB_TOKEN }}
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v16.19.0
v18.16.0
4 changes: 2 additions & 2 deletions docs/react/guides/migrating-to-v5.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ If you want to run it against `.js` or `.jsx` files, please use the command belo
```
npx jscodeshift ./path/to/src/ \
--extensions=js,jsx \
--transform=./node_modules/@tanstack/react-query/codemods/v5/remove-overloads/remove-overloads.js
--transform=./node_modules/@tanstack/react-query/build/codemods/v5/remove-overloads/remove-overloads.js
```

If you want to run it against `.ts` or `.tsx` files, please use the command below:
Expand All @@ -117,7 +117,7 @@ If you want to run it against `.ts` or `.tsx` files, please use the command belo
npx jscodeshift ./path/to/src/ \
--extensions=ts,tsx \
--parser=tsx \
--transform=./node_modules/@tanstack/react-query/codemods/v5/remove-overloads/remove-overloads.js
--transform=./node_modules/@tanstack/react-query/build/codemods/v5/remove-overloads/remove-overloads.js
```

Please note in the case of `TypeScript` you need to use `tsx` as the parser; otherwise, the codemod won't be applied properly!
Expand Down
4 changes: 2 additions & 2 deletions docs/react/plugins/createSyncStoragePersister.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ import { compress, decompress } from 'lz-string';
const queryClient = new QueryClient({ defaultOptions: { queries: { staleTime: Infinity } } });

persistQueryClient({
queryClient: connectionsQueryClient,
persistor: createSyncStoragePersister({
queryClient: queryClient,
persister: createSyncStoragePersister({
storage: window.localStorage,
serialize: data => compress(JSON.stringify(data)),
deserialize: data => JSON.parse(decompress(data)),
Expand Down
1 change: 0 additions & 1 deletion docs/react/reference/useQuery.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ const {
isPlaceholderData,
isRefetchError,
isRefetching,
isInitialLoading,
isStale,
isSuccess,
refetch,
Expand Down
4 changes: 3 additions & 1 deletion nx.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"test:lib",
"test:eslint",
"test:types",
"test:build",
"build:types",
"build",
"rollup"
Expand All @@ -27,7 +28,8 @@
"{workspaceRoot}/rollup.config.js",
"{workspaceRoot}/rollup.config.ts",
"{workspaceRoot}/tsconfig.json",
"{workspaceRoot}/tsconfig.base.json"
"{workspaceRoot}/tsconfig.base.json",
"{workspaceRoot}/package.json"
],
"globalNonBuildAffectingConfig": ["{workspaceRoot}/.eslintrc"],
"default": [
Expand Down
2 changes: 1 addition & 1 deletion packages/query-async-storage-persister/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tanstack/query-async-storage-persister",
"version": "5.0.0-alpha.23",
"version": "5.0.0-alpha.24",
"description": "A persister for asynchronous storages, to be used with TanStack/Query",
"author": "tannerlinsley",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/query-broadcast-client-experimental/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tanstack/query-broadcast-client-experimental",
"version": "5.0.0-alpha.23",
"version": "5.0.0-alpha.24",
"description": "An experimental plugin to for broadcasting the state of your queryClient between browser tabs/windows",
"author": "tannerlinsley",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/query-core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tanstack/query-core",
"version": "5.0.0-alpha.23",
"version": "5.0.0-alpha.24",
"description": "The framework agnostic core that powers TanStack Query",
"author": "tannerlinsley",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/query-core/src/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ export class Query<
`Query data cannot be undefined. Please make sure to return a value other than undefined from your query function. Affected query key: ${this.queryHash}`,
)
}
onError(new Error('undefined') as any)
onError(new Error(`${this.queryHash} data is undefined`) as any)
return
}

Expand Down
2 changes: 1 addition & 1 deletion packages/query-core/src/tests/query.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,7 @@ describe('query', () => {

await sleep(10)

const error = new Error('undefined')
const error = new Error(`${JSON.stringify(key)} data is undefined`)

expect(observerResult).toMatchObject({
isError: true,
Expand Down
2 changes: 1 addition & 1 deletion packages/query-persist-client-core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tanstack/query-persist-client-core",
"version": "5.0.0-alpha.23",
"version": "5.0.0-alpha.24",
"description": "Set of utilities for interacting with persisters, which can save your queryClient for later use",
"author": "tannerlinsley",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/query-sync-storage-persister/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tanstack/query-sync-storage-persister",
"version": "5.0.0-alpha.23",
"version": "5.0.0-alpha.24",
"description": "A persister for synchronous storages, to be used with TanStack/Query",
"author": "tannerlinsley",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/react-query-devtools/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tanstack/react-query-devtools",
"version": "5.0.0-alpha.23",
"version": "5.0.0-alpha.24",
"description": "Developer tools to interact with and visualize the TanStack/react-query cache",
"author": "tannerlinsley",
"license": "MIT",
Expand Down
10 changes: 9 additions & 1 deletion packages/react-query-devtools/src/CachePanel/ActiveQuery.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ const ActiveQuery = ({

const restoreQueryAfterLoadingOrError = () => {
activeQuery.fetch(
(activeQuery.state.fetchMeta as any).__previousQueryOptions,
(activeQuery.state.fetchMeta as any)?.__previousQueryOptions,
{
// Make sure this fetch will cancel the previous one
cancelRefetch: true,
Expand Down Expand Up @@ -252,6 +252,14 @@ const ActiveQuery = ({
<Button
type="button"
onClick={() => {
// Return early if the query is already restoring
if (
activeQuery.state.fetchStatus === 'fetching' &&
typeof (activeQuery.state.fetchMeta as any)
?.__previousQueryOptions === 'undefined'
) {
return
}
if (activeQuery.state.data === undefined) {
restoreQueryAfterLoadingOrError()
} else {
Expand Down
55 changes: 55 additions & 0 deletions packages/react-query-devtools/src/__tests__/devtools.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1081,4 +1081,59 @@ describe('ReactQueryDevtools', () => {
expect(screen.getByText('No error, success')).toBeInTheDocument()
})
})

it('should not refetch when already restoring a query', async () => {
const { queryClient } = createQueryClient()

let count = 0
let resolvePromise: (value: unknown) => void = () => undefined

function App() {
const { data } = useQuery({
queryKey: ['key'],
queryFn: () => {
count++

// Resolve the promise immediately when
// the query is fetched for the first time
if (count === 1) {
return Promise.resolve('test')
}

return new Promise((resolve) => {
// Do not resolve immediately and store the
// resolve function to resolve the promise later
resolvePromise = resolve
})
},
})

return (
<div>
<h1>{typeof data === 'string' ? data : 'No data'}</h1>
</div>
)
}

renderWithClient(queryClient, <App />, {
initialIsOpen: true,
})

const loadingButton = await screen.findByRole('button', {
name: 'Trigger loading',
})
fireEvent.click(loadingButton)

await waitFor(() => {
expect(screen.getByText('Restore loading')).toBeInTheDocument()
})

// Click the restore loading button twice and only resolve query promise
// after the second click.
fireEvent.click(screen.getByRole('button', { name: /restore loading/i }))
fireEvent.click(screen.getByRole('button', { name: /restore loading/i }))
resolvePromise('test')

expect(count).toBe(2)
})
})
2 changes: 1 addition & 1 deletion packages/react-query-persist-client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tanstack/react-query-persist-client",
"version": "5.0.0-alpha.23",
"version": "5.0.0-alpha.24",
"description": "React bindings to work with persisters in TanStack/react-query",
"author": "tannerlinsley",
"license": "MIT",
Expand Down
9 changes: 7 additions & 2 deletions packages/react-query/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tanstack/react-query",
"version": "5.0.0-alpha.23",
"version": "5.0.0-alpha.24",
"description": "Hooks for managing, caching and syncing asynchronous and remote data in React",
"author": "tannerlinsley",
"license": "MIT",
Expand Down Expand Up @@ -28,12 +28,17 @@
"test:types": "tsc",
"test:lib": "vitest run --coverage",
"test:lib:dev": "pnpm run test:lib --watch",
"build": "mkdir -p ./build && cp -R ../codemods/src ./build/codemods",
"build:types": "tsc --build"
},
"files": [
"build/lib/*",
"build/umd/*",
"src"
"src",
"build/codemods",
"!build/codemods/jest.config.js",
"!build/codemods/**/__testfixtures__",
"!build/codemods/**/__tests__"
],
"devDependencies": {
"@types/react": "^18.0.14",
Expand Down
2 changes: 1 addition & 1 deletion packages/solid-query/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tanstack/solid-query",
"version": "5.0.0-alpha.23",
"version": "5.0.0-alpha.24",
"description": "Primitives for managing, caching and syncing asynchronous and remote data in Solid",
"author": "tannerlinsley",
"license": "MIT",
Expand Down
Loading

0 comments on commit 9c7123f

Please sign in to comment.