@tanstack/react-query-devtools 4.29.5 → 4.29.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/react-query-devtools",
3
- "version": "4.29.5",
3
+ "version": "4.29.7",
4
4
  "description": "Developer tools to interact with and visualize the TanStack/react-query cache",
5
5
  "author": "tannerlinsley",
6
6
  "license": "MIT",
@@ -46,7 +46,7 @@
46
46
  "react-dom": "^18.2.0",
47
47
  "react-dom-17": "npm:react-dom@^17.0.2",
48
48
  "react-error-boundary": "^3.1.4",
49
- "@tanstack/react-query": "4.29.5"
49
+ "@tanstack/react-query": "4.29.7"
50
50
  },
51
51
  "dependencies": {
52
52
  "@tanstack/match-sorter-utils": "^8.7.0",
@@ -56,7 +56,7 @@
56
56
  "peerDependencies": {
57
57
  "react": "^16.8.0 || ^17.0.0 || ^18.0.0",
58
58
  "react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0",
59
- "@tanstack/react-query": "4.29.5"
59
+ "@tanstack/react-query": "4.29.7"
60
60
  },
61
61
  "scripts": {
62
62
  "clean": "rimraf ./build",
@@ -1091,4 +1091,56 @@ describe('ReactQueryDevtools', () => {
1091
1091
  expect(screen.getByText('No error, success')).toBeInTheDocument()
1092
1092
  })
1093
1093
  })
1094
+
1095
+ it('should not refetch when already restoring a query', async () => {
1096
+ const { queryClient } = createQueryClient()
1097
+
1098
+ let count = 0
1099
+ let resolvePromise: (value: unknown) => void = () => undefined
1100
+
1101
+ function App() {
1102
+ const { data } = useQuery(['key'], () => {
1103
+ count++
1104
+
1105
+ // Resolve the promise immediately when
1106
+ // the query is fetched for the first time
1107
+ if (count === 1) {
1108
+ return Promise.resolve('test')
1109
+ }
1110
+
1111
+ return new Promise((resolve) => {
1112
+ // Do not resolve immediately and store the
1113
+ // resolve function to resolve the promise later
1114
+ resolvePromise = resolve
1115
+ })
1116
+ })
1117
+
1118
+ return (
1119
+ <div>
1120
+ <h1>{typeof data === 'string' ? data : 'No data'}</h1>
1121
+ </div>
1122
+ )
1123
+ }
1124
+
1125
+ renderWithClient(queryClient, <App />, {
1126
+ initialIsOpen: true,
1127
+ })
1128
+
1129
+ const loadingButton = await screen.findByRole('button', {
1130
+ name: 'Trigger loading',
1131
+ })
1132
+ fireEvent.click(loadingButton)
1133
+
1134
+ await waitFor(() => {
1135
+ expect(screen.getByText('Restore loading')).toBeInTheDocument()
1136
+ })
1137
+
1138
+ // Click the restore loading button twice and only resolve query promise
1139
+ // after the second click.
1140
+ fireEvent.click(screen.getByRole('button', { name: /restore loading/i }))
1141
+ fireEvent.click(screen.getByRole('button', { name: /restore loading/i }))
1142
+ resolvePromise('test')
1143
+
1144
+ expect(count).toBe(2)
1145
+ })
1094
1146
  })
package/src/devtools.tsx CHANGED
@@ -1035,6 +1035,15 @@ const ActiveQuery = ({
1035
1035
  <Button
1036
1036
  type="button"
1037
1037
  onClick={() => {
1038
+ // Return early if the query is already restoring
1039
+ if (
1040
+ activeQuery.state.fetchStatus === 'fetching' &&
1041
+ typeof activeQuery.state.fetchMeta?.__previousQueryOptions ===
1042
+ 'undefined'
1043
+ ) {
1044
+ return
1045
+ }
1046
+
1038
1047
  if (activeQuery.state.data === undefined) {
1039
1048
  restoreQueryAfterLoadingOrError()
1040
1049
  } else {