@tanstack/query-core 4.22.4 → 4.24.2

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/query-core",
3
- "version": "4.22.4",
3
+ "version": "4.24.2",
4
4
  "description": "The framework agnostic core that powers TanStack Query",
5
5
  "author": "tannerlinsley",
6
6
  "license": "MIT",
@@ -33,7 +33,6 @@
33
33
  "test:types": "tsc",
34
34
  "test:lib": "jest --config ./jest.config.ts",
35
35
  "test:lib:dev": "pnpm run test:lib --watch",
36
- "test:lib:publish": "pnpm run test:lib --collectCoverage false",
37
36
  "build:types": "tsc --build"
38
37
  }
39
38
  }
package/src/query.ts CHANGED
@@ -173,6 +173,7 @@ export class Query<
173
173
  this.queryHash = config.queryHash
174
174
  this.initialState = config.state || getDefaultState(this.options)
175
175
  this.state = this.initialState
176
+ this.scheduleGc()
176
177
  }
177
178
 
178
179
  get meta(): QueryMeta | undefined {
@@ -883,4 +883,28 @@ describe('query', () => {
883
883
 
884
884
  expect(initialDataUpdatedAtSpy).toHaveBeenCalled()
885
885
  })
886
+
887
+ test('queries should be garbage collected even if they never fetched', async () => {
888
+ const key = queryKey()
889
+
890
+ queryClient.setQueryDefaults(key, { cacheTime: 10 })
891
+
892
+ const fn = jest.fn()
893
+
894
+ const unsubscribe = queryClient.getQueryCache().subscribe(fn)
895
+
896
+ queryClient.setQueryData(key, 'data')
897
+
898
+ await waitFor(() =>
899
+ expect(fn).toHaveBeenCalledWith(
900
+ expect.objectContaining({
901
+ type: 'removed',
902
+ }),
903
+ ),
904
+ )
905
+
906
+ expect(queryClient.getQueryCache().findAll()).toHaveLength(0)
907
+
908
+ unsubscribe()
909
+ })
886
910
  })