Skip to content

Commit 77ead30

Browse files
committed
Merge remote-tracking branch 'origin/main' into alpha
# Conflicts: # .github/workflows/pr.yml # packages/query-async-storage-persister/package.json # packages/query-broadcast-client-experimental/package.json # packages/query-core/package.json # packages/query-persist-client-core/package.json # packages/query-sync-storage-persister/package.json # packages/react-query-devtools/package.json # packages/react-query-devtools/src/devtools.tsx # packages/react-query-persist-client/package.json # packages/react-query/package.json # packages/solid-query/package.json # packages/svelte-query/package.json # packages/vue-query/package.json
2 parents aebae80 + c8799df commit 77ead30

File tree

10 files changed

+99
-42
lines changed

10 files changed

+99
-42
lines changed

.github/workflows/ci-v3.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ on:
66
- 'v3'
77
env:
88
NX_DAEMON: false
9-
NX_VERBOSE_LOGGING: true
109
NX_CLOUD_ACCESS_TOKEN: ${{ secrets.NX_CLOUD_ACCESS_TOKEN }}
1110
jobs:
1211
test:

.github/workflows/ci.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ on:
1515
- 'beta'
1616
env:
1717
NX_DAEMON: false
18-
NX_VERBOSE_LOGGING: true
1918
NX_CLOUD_ACCESS_TOKEN: ${{ secrets.NX_CLOUD_ACCESS_TOKEN }}
2019
jobs:
2120
test-and-publish:

.github/workflows/pr.yml

Lines changed: 30 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,15 @@ name: pr
22
on: [pull_request]
33
env:
44
NX_DAEMON: false
5-
NX_VERBOSE_LOGGING: true
65
NX_CLOUD_ACCESS_TOKEN: ${{ secrets.NX_CLOUD_ACCESS_TOKEN }}
76
jobs:
8-
test:
9-
name: 'Test'
10-
runs-on: ubuntu-latest
11-
steps:
12-
- uses: actions/checkout@v3
13-
with:
14-
fetch-depth: 0
15-
ref: ${{ github.head_ref }}
16-
repository: ${{github.event.pull_request.head.repo.full_name}}
17-
- uses: pnpm/[email protected]
18-
with:
19-
version: 7
20-
- uses: actions/setup-node@v3
21-
with:
22-
node-version: 16.19.0
23-
cache: 'pnpm'
24-
- name: Install dependencies
25-
run: pnpm --filter "./packages/**" --filter query --prefer-offline install
26-
- name: Run Tests
27-
uses: nick-fields/[email protected]
28-
with:
29-
command: pnpm test:lib --base=${{ github.event.pull_request.base.sha }}
30-
timeout_minutes: 5
31-
max_attempts: 3
32-
- name: Upload coverage to Codecov
33-
uses: codecov/codecov-action@v3
34-
lint:
35-
name: 'Lint'
7+
agent:
8+
name: 'Nx Cloud Agents'
369
runs-on: ubuntu-latest
10+
timeout-minutes: 20
11+
strategy:
12+
matrix:
13+
agent: [1, 2, 3, 4]
3714
steps:
3815
- uses: actions/checkout@v3
3916
with:
@@ -49,9 +26,10 @@ jobs:
4926
cache: 'pnpm'
5027
- name: Install dependencies
5128
run: pnpm --filter "./packages/**" --filter query --prefer-offline install
52-
- run: pnpm run test:eslint --base=${{ github.event.pull_request.base.sha }}
53-
typecheck:
54-
name: 'Typecheck'
29+
- name: Start Nx Agent ${{ matrix.agent }}
30+
run: npx nx-cloud start-agent
31+
orchestrator:
32+
name: 'Nx Cloud Orchestrator'
5533
runs-on: ubuntu-latest
5634
steps:
5735
- uses: actions/checkout@v3
@@ -64,11 +42,29 @@ jobs:
6442
version: 7
6543
- uses: actions/setup-node@v3
6644
with:
67-
node-version: 16.14.2
45+
node-version: 16.19.0
6846
cache: 'pnpm'
6947
- name: Install dependencies
7048
run: pnpm --filter "./packages/**" --filter query --prefer-offline install
71-
- run: pnpm run test:types --base=${{ github.event.pull_request.base.sha }}
49+
- name: Derive appropriate SHAs for base and head for `nx affected` commands
50+
uses: nrwl/nx-set-shas@v2
51+
- run: |
52+
echo "BASE: ${{ env.NX_BASE }}"
53+
echo "HEAD: ${{ env.NX_HEAD }}"
54+
- name: Start CI Orchestrator
55+
run: npx nx-cloud start-ci-run
56+
- name: Run All Checks
57+
uses: nick-fields/[email protected]
58+
env:
59+
BUNDLEWATCH_GITHUB_TOKEN: ${{ secrets.BUNDLEWATCH_GITHUB_TOKEN }}
60+
with:
61+
timeout_minutes: 5
62+
max_attempts: 3
63+
command: npx nx affected --targets=test:eslint,test:types,test:build,test:lib --base=${{ github.event.pull_request.base.sha }}
64+
- name: Stop Agents
65+
run: npx nx-cloud stop-all-agents
66+
- name: Upload coverage to Codecov
67+
uses: codecov/codecov-action@v3
7268
format:
7369
name: 'Format'
7470
runs-on: ubuntu-latest

docs/react/plugins/createSyncStoragePersister.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,8 @@ import { compress, decompress } from 'lz-string';
128128
const queryClient = new QueryClient({ defaultOptions: { queries: { staleTime: Infinity } } });
129129

130130
persistQueryClient({
131-
queryClient: connectionsQueryClient,
132-
persistor: createSyncStoragePersister({
131+
queryClient: queryClient,
132+
persister: createSyncStoragePersister({
133133
storage: window.localStorage,
134134
serialize: data => compress(JSON.stringify(data)),
135135
deserialize: data => JSON.parse(decompress(data)),

nx.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"test:lib",
88
"test:eslint",
99
"test:types",
10+
"test:build",
1011
"build:types",
1112
"build",
1213
"rollup"
@@ -27,7 +28,8 @@
2728
"{workspaceRoot}/rollup.config.js",
2829
"{workspaceRoot}/rollup.config.ts",
2930
"{workspaceRoot}/tsconfig.json",
30-
"{workspaceRoot}/tsconfig.base.json"
31+
"{workspaceRoot}/tsconfig.base.json",
32+
"{workspaceRoot}/package.json"
3133
],
3234
"globalNonBuildAffectingConfig": ["{workspaceRoot}/.eslintrc"],
3335
"default": [

packages/query-core/src/query.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ export class Query<
464464
`Query data cannot be undefined. Please make sure to return a value other than undefined from your query function. Affected query key: ${this.queryHash}`,
465465
)
466466
}
467-
onError(new Error('undefined') as any)
467+
onError(new Error(`${this.queryHash} data is undefined`) as any)
468468
return
469469
}
470470

packages/query-core/src/tests/query.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -788,7 +788,7 @@ describe('query', () => {
788788

789789
await sleep(10)
790790

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

793793
expect(observerResult).toMatchObject({
794794
isError: true,

packages/react-query-devtools/src/CachePanel/ActiveQuery.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ const ActiveQuery = ({
101101

102102
const restoreQueryAfterLoadingOrError = () => {
103103
activeQuery.fetch(
104-
(activeQuery.state.fetchMeta as any).__previousQueryOptions,
104+
(activeQuery.state.fetchMeta as any)?.__previousQueryOptions,
105105
{
106106
// Make sure this fetch will cancel the previous one
107107
cancelRefetch: true,
@@ -252,6 +252,14 @@ const ActiveQuery = ({
252252
<Button
253253
type="button"
254254
onClick={() => {
255+
// Return early if the query is already restoring
256+
if (
257+
activeQuery.state.fetchStatus === 'fetching' &&
258+
typeof (activeQuery.state.fetchMeta as any)
259+
?.__previousQueryOptions === 'undefined'
260+
) {
261+
return
262+
}
255263
if (activeQuery.state.data === undefined) {
256264
restoreQueryAfterLoadingOrError()
257265
} else {

packages/react-query-devtools/src/__tests__/devtools.test.tsx

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,4 +1081,56 @@ describe('ReactQueryDevtools', () => {
10811081
expect(screen.getByText('No error, success')).toBeInTheDocument()
10821082
})
10831083
})
1084+
1085+
it('should not refetch when already restoring a query', async () => {
1086+
const { queryClient } = createQueryClient()
1087+
1088+
let count = 0
1089+
let resolvePromise: (value: unknown) => void = () => undefined
1090+
1091+
function App() {
1092+
const { data } = useQuery(['key'], () => {
1093+
count++
1094+
1095+
// Resolve the promise immediately when
1096+
// the query is fetched for the first time
1097+
if (count === 1) {
1098+
return Promise.resolve('test')
1099+
}
1100+
1101+
return new Promise((resolve) => {
1102+
// Do not resolve immediately and store the
1103+
// resolve function to resolve the promise later
1104+
resolvePromise = resolve
1105+
})
1106+
})
1107+
1108+
return (
1109+
<div>
1110+
<h1>{typeof data === 'string' ? data : 'No data'}</h1>
1111+
</div>
1112+
)
1113+
}
1114+
1115+
renderWithClient(queryClient, <App />, {
1116+
initialIsOpen: true,
1117+
})
1118+
1119+
const loadingButton = await screen.findByRole('button', {
1120+
name: 'Trigger loading',
1121+
})
1122+
fireEvent.click(loadingButton)
1123+
1124+
await waitFor(() => {
1125+
expect(screen.getByText('Restore loading')).toBeInTheDocument()
1126+
})
1127+
1128+
// Click the restore loading button twice and only resolve query promise
1129+
// after the second click.
1130+
fireEvent.click(screen.getByRole('button', { name: /restore loading/i }))
1131+
fireEvent.click(screen.getByRole('button', { name: /restore loading/i }))
1132+
resolvePromise('test')
1133+
1134+
expect(count).toBe(2)
1135+
})
10841136
})

tsconfig.base.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"strictNullChecks": true,
1616
"jsx": "react",
1717
"declaration": true,
18+
"declarationMap": true,
1819
"emitDeclarationOnly": true,
1920
"esModuleInterop": true,
2021
"skipLibCheck": true,

0 commit comments

Comments
 (0)