Skip to content

Commit

Permalink
Merge remote-tracking branch 'tanstack/alpha' into refactor/react-que…
Browse files Browse the repository at this point in the history
…ry-devtools-panels
  • Loading branch information
gpichot committed Apr 2, 2023
2 parents afe564f + 633115a commit 56df0f7
Show file tree
Hide file tree
Showing 45 changed files with 439 additions and 148 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/ci-v3.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ on:
push:
branches:
- 'v3'
env:
NX_DAEMON: false
NX_VERBOSE_LOGGING: true
NX_CLOUD_ACCESS_TOKEN: ${{ secrets.NX_CLOUD_ACCESS_TOKEN }}
jobs:
test:
name: 'Node ${{ matrix.node }}, React ${{ matrix.react }}'
Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ on:
- 'alpha'
- 'beta'
env:
NX_DAEMON: 'false'
NX_DAEMON: false
NX_VERBOSE_LOGGING: true
NX_CLOUD_ACCESS_TOKEN: ${{ secrets.NX_CLOUD_ACCESS_TOKEN }}
jobs:
test-and-publish:
if: github.repository == 'TanStack/query' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/alpha' || github.ref == 'refs/heads/beta')
Expand All @@ -37,7 +39,7 @@ jobs:
- name: Run Tests
uses: nick-fields/[email protected]
with:
command: pnpm run test:ci
command: pnpm run test:ci --base=${{ github.event.before }}
timeout_minutes: 10
max_attempts: 3
- name: Publish
Expand Down
28 changes: 23 additions & 5 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
name: pr
on: [pull_request]
env:
NX_DAEMON: 'false'
NX_DAEMON: false
NX_VERBOSE_LOGGING: true
NX_CLOUD_ACCESS_TOKEN: ${{ secrets.NX_CLOUD_ACCESS_TOKEN }}
jobs:
test:
name: 'Test'
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/[email protected]
with:
version: 7
Expand All @@ -20,7 +26,7 @@ jobs:
- name: Run Tests
uses: nick-fields/[email protected]
with:
command: pnpm test:lib
command: pnpm test:lib --base=${{ github.event.pull_request.base.sha }}
timeout_minutes: 5
max_attempts: 3
- name: Upload coverage to Codecov
Expand All @@ -30,6 +36,10 @@ jobs:
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/[email protected]
with:
version: 7
Expand All @@ -39,12 +49,16 @@ jobs:
cache: 'pnpm'
- name: Install dependencies
run: pnpm --filter "./packages/**" --filter query --prefer-offline install
- run: pnpm run test:eslint
- 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/[email protected]
with:
version: 7
Expand All @@ -54,12 +68,16 @@ jobs:
cache: 'pnpm'
- name: Install dependencies
run: pnpm --filter "./packages/**" --filter query --prefer-offline install
- run: pnpm run test:types
- run: pnpm run test:types --base=${{ github.event.pull_request.base.sha }}
format:
name: 'Format'
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/[email protected]
with:
version: 7
Expand All @@ -69,7 +87,7 @@ jobs:
cache: 'pnpm'
- name: Install dependencies
run: pnpm --filter "./packages/**" --filter query --prefer-offline install
- run: pnpm run test:format
- run: pnpm run test:format --base=${{ github.event.pull_request.base.sha }}
test-build:
name: 'Test Build'
runs-on: ubuntu-latest
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,5 @@ node_modules
.cache
dist
.idea

nx-cloud.env
11 changes: 10 additions & 1 deletion docs/react/guides/migrating-to-v5.md
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,15 @@ However, refetching all pages might lead to UI inconsistencies. Also, this optio

The v5 includes a new `maxPages` option for infinite queries to limit the number of pages to store in the query data and to refetch. This new feature handles the use cases initially identified for the `refetchPage` page feature without the related issues.

### New hydration API

The options you can pass to dehydrate have been simplified. Queries and Mutations are always dehydrated (according to the default function implementation). To change this behaviour, you can implement `shouldDehydrateQuery` or `shouldDehydrateMutation`.

```diff
- dehydrateMutations?: boolean
- dehydrateQueries?: boolean
```

### Infinite queries now need a `defaultPageParam`

Previously, we've passed `undefined` to the `queryFn` as `pageParam`, and you could assign a default value to the `pageParam` parameter in the `queryFn` function signature. This had the drawback of storing `undefined` in the `queryCache`, which is not serializable.
Expand Down Expand Up @@ -410,7 +419,7 @@ We have a new, simplified way to perform optimistic updates by leveraging the re

Here, we are only changing how the UI looks when the mutation is running instead of writing data directly to the cache. This works best if we only have one place where we need to show the optimistic update. For more details, have a look at the [optimistic updates documentation](../guides/optimistic-updates.md).

### Eternal list: scalable infinite query with new maxPages option
### Limited, Infinite Queries with new maxPages option

Infinite queries are great when infinite scroll or pagination are needed.
However, the more pages you fetch, the more memory you consume, and this also slows down the query refetching process as all the pages are sequentially refetched.
Expand Down
2 changes: 1 addition & 1 deletion docs/react/guides/paginated-queries.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ This experience is not optimal and unfortunately is how many tools today insist

Consider the following example where we would ideally want to increment a pageIndex (or cursor) for a query. If we were to use `useQuery`, **it would still technically work fine**, but the UI would jump in and out of the `success` and `pending` states as different queries are created and destroyed for each page or cursor. By setting `placeholderData` to `(previousData) => previousData` or `keepPreviousData` function exported from TanStack Query, we get a few new things:

- **The data from the last successful fetch available while new data is being requested, even though the query key has changed**.
- **The data from the last successful fetch is available while new data is being requested, even though the query key has changed**.
- When the new data arrives, the previous `data` is seamlessly swapped to show the new data.
- `isPlaceholderData` is made available to know what data the query is currently providing you

Expand Down
27 changes: 12 additions & 15 deletions docs/react/reference/hydration.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { dehydrate } from '@tanstack/react-query'

const dehydratedState = dehydrate(queryClient, {
shouldDehydrateQuery,
shouldDehydrateMutation,
})
```

Expand All @@ -22,24 +23,20 @@ const dehydratedState = dehydrate(queryClient, {
- The `queryClient` that should be dehydrated
- `options: DehydrateOptions`
- Optional
- `dehydrateMutations: boolean`
- Optional
- Whether or not to dehydrate mutations.
- `dehydrateQueries: boolean`
- Optional
- Whether or not to dehydrate queries.
- `shouldDehydrateMutation: (mutation: Mutation) => boolean`
- Optional
- This function is called for each mutation in the cache
- Return `true` to include this mutation in dehydration, or `false` otherwise
- The default version only includes paused mutations
- If you would like to extend the function while retaining the previous behavior, import and execute `defaultShouldDehydrateMutation` as part of the return statement
- `shouldDehydrateQuery: (query: Query) => boolean`
- Whether to dehydrate mutations.
- The function is called for each mutation in the cache
- Return `true` to include this mutation in dehydration, or `false` otherwise
- Defaults to only including paused mutations
- If you would like to extend the function while retaining the default behavior, import and execute `defaultShouldDehydrateMutation` as part of the return statement
- `shouldDehydrateQuery: boolean | (query: Query) => boolean`
- Optional
- This function is called for each query in the cache
- Return `true` to include this query in dehydration, or `false` otherwise
- The default version only includes successful queries, do `shouldDehydrateQuery: () => true` to include all queries
- If you would like to extend the function while retaining the previous behavior, import and execute `defaultShouldDehydrateQuery` as part of the return statement
- Whether to dehydrate queries.
- The function, it is called for each query in the cache
- Return `true` to include this query in dehydration, or `false` otherwise
- Defaults to only including successful queries
- If you would like to extend the function while retaining the default behavior, import and execute `defaultShouldDehydrateQuery` as part of the return statement

**Returns**

Expand Down
2 changes: 1 addition & 1 deletion docs/react/reference/useQueries.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ The `useQueries` hook accepts an options object with a **queries** key whose val
**Returns**

The `useQueries` hook returns an array with all the query results.
The `useQueries` hook returns an array with all the query results. The order returned is the same as the input order.
20 changes: 13 additions & 7 deletions nx.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
{
"tasksRunnerOptions": {
"default": {
"runner": "nx/tasks-runners/default",
"runner": "@nrwl/nx-cloud",
"options": {
"cacheableOperations": [
"test:lib",
"test:eslint",
"test:types",
"build:types",
"test:format",
"test:build",
"build"
]
"build",
"rollup"
],
"accessToken": "ZDdkNDA4MGEtYjNmYi00MWI4LWE1N2QtYTdlNmYxMGJlZWM2fHJlYWQ="
}
}
},
Expand Down Expand Up @@ -52,12 +52,18 @@
"inputs": ["default", "^public"]
},
"test:types": {
"outputs": ["{projectRoot}/build"],
"outputs": [
"{projectRoot}/build/**/*.d.ts",
"{projectRoot}/build/.tsbuildinfo"
],
"inputs": ["default", "^public"],
"dependsOn": ["^test:types"]
},
"build:types": {
"outputs": ["{projectRoot}/build"],
"outputs": [
"{projectRoot}/build/**/*.d.ts",
"{projectRoot}/build/.tsbuildinfo"
],
"inputs": ["default", "^public"],
"dependsOn": ["^build:types"]
},
Expand Down
20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
"preinstall": "node -e \"if(process.env.CI == 'true') {console.log('Skipping preinstall...'); process.exit(1)}\" || npx -y only-allow pnpm",
"install:csb": "pnpm install --frozen-lockfile",
"test": "pnpm run test:ci",
"test:ci": "nx run-many --targets=test:lib,test:types,test:eslint,test:format --parallel=5",
"test:eslint": "nx run-many --target=test:eslint --parallel=5",
"test:format": "nx test:format root",
"test:lib": "nx run-many --target=test:lib --parallel=5",
"test:ci": "nx affected --targets=test:lib,test:types,test:eslint,test:format --parallel=5",
"test:eslint": "nx affected --target=test:eslint --parallel=5",
"test:format": "pnpm run prettier --check",
"test:lib": "nx affected --target=test:lib --parallel=5",
"test:lib:dev": "pnpm --filter \"./packages/**\" run test:lib:dev",
"test:build": "nx test:build root",
"test:types": "nx run-many --target=test:types --parallel=5",
"build": "nx build root",
"build:types": "nx run-many --target=build:types --parallel=5",
"test:build": "nx run-many --target=test:build --projects=root",
"test:types": "nx affected --target=test:types --parallel=5",
"build": "nx run-many --target=build --projects=root",
"build:types": "nx affected --target=build:types --parallel=5",
"watch": "concurrently --kill-others \"rollup --config rollup.config.js -w\" \"pnpm run build:types --watch\"",
"dev": "pnpm run watch",
"prettier": "prettier --plugin-search-dir . \"{packages,examples}/**/src/**/*.{md,js,jsx,ts,tsx,json,vue,svelte}\"",
Expand All @@ -35,7 +35,7 @@
"@babel/preset-react": "^7.18.6",
"@babel/preset-typescript": "^7.18.6",
"@commitlint/parse": "^17.4.2",
"@faker-js/faker": "^7.6.0",
"@nrwl/nx-cloud": "^15.3.1",
"@rollup/plugin-babel": "^6.0.3",
"@rollup/plugin-commonjs": "24.0.1",
"@rollup/plugin-node-resolve": "^15.0.1",
Expand All @@ -56,7 +56,6 @@
"@vitest/coverage-istanbul": "^0.27.1",
"axios": "^1.3.2",
"babel-eslint": "^10.1.0",
"babel-plugin-transform-async-to-promises": "^0.8.18",
"babel-preset-solid": "^1.6.10",
"bundlewatch": "^0.3.3",
"chalk": "^4.1.2",
Expand Down Expand Up @@ -87,6 +86,7 @@
"react-dom": "^18.2.0",
"rimraf": "^4.1.2",
"rollup": "^3.15.0",
"rollup-plugin-preserve-directives": "0.1.0",
"rollup-plugin-size": "^0.2.2",
"rollup-plugin-terser": "^7.0.2",
"rollup-plugin-visualizer": "^5.9.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin-query/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tanstack/eslint-plugin-query",
"version": "5.0.0-alpha.6",
"version": "5.0.0-alpha.13",
"description": "ESLint plugin for TanStack Query",
"author": "Eliya Cohen",
"license": "MIT",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,20 @@ export const rule = createRule({

const sourceCode = context.getSourceCode()
const queryKeyValue = queryKeyNode
const reactComponent = ASTUtils.getReactComponentOrHookAncestor(context)
const refs = ASTUtils.getExternalRefs({
scopeManager,
sourceCode,
node: queryFn.value,
}).filter((ref) => {
return (
reactComponent === undefined ||
ASTUtils.isDeclaredInNode({
scopeManager,
functionNode: reactComponent,
reference: ref,
})
)
})

const relevantRefs = refs.filter((ref) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,30 @@ ruleTester.run('exhaustive-deps', rule, {
});
`,
},
{
name: 'should ignore constants defined out of scope (react component)',
code: `
const CONST_VAL = 1
function MyComponent() {
useQuery({
queryKey: ["foo"],
queryFn: () => CONST_VAL
});
}
`,
},
{
name: 'should ignore constants defined out of scope (react hook)',
code: `
const CONST_VAL = 1
function useHook() {
useQuery({
queryKey: ["foo"],
queryFn: () => CONST_VAL
});
}
`,
},
],
invalid: [
{
Expand Down
Loading

0 comments on commit 56df0f7

Please sign in to comment.