@tanstack/svelte-query 6.1.40 → 6.1.42

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.
@@ -1 +1 @@
1
- {"version":3,"file":"containers.svelte.d.ts","sourceRoot":"","sources":["../src/containers.svelte.ts"],"names":[],"mappings":"AAEA,KAAK,MAAM,GAAG,MAAM,IAAI,CAAA;AACxB,KAAK,UAAU,GAAG,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,GAAG,MAAM,CAAA;AAEnD,MAAM,MAAM,GAAG,CAAC,CAAC,IAAI;IAAE,OAAO,EAAE,CAAC,CAAA;CAAE,CAAA;AAEnC,qBAAa,aAAa,CAAC,CAAC,CAAE,YAAW,GAAG,CAAC,CAAC,CAAC;;gBAIjC,EAAE,EAAE,MAAM,CAAC,EAAE,WAAW,EAAE,UAAU;IAKhD,IAAI,OAAO,MAGV;CACF;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,CAAC,SAAS,EAAE,GAAG,KAAK,CAAC,OAAO,CAAC,EACxD,IAAI,EAAE,CAAC,GACN,CAAC,CAAC,EAAE,CAAC,QAAQ,EAAE,CAAC,KAAK,IAAI,CAAC,CA+E5B"}
1
+ {"version":3,"file":"containers.svelte.d.ts","sourceRoot":"","sources":["../src/containers.svelte.ts"],"names":[],"mappings":"AAEA,KAAK,MAAM,GAAG,MAAM,IAAI,CAAA;AACxB,KAAK,UAAU,GAAG,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,GAAG,MAAM,CAAA;AAEnD,MAAM,MAAM,GAAG,CAAC,CAAC,IAAI;IAAE,OAAO,EAAE,CAAC,CAAA;CAAE,CAAA;AAEnC,qBAAa,aAAa,CAAC,CAAC,CAAE,YAAW,GAAG,CAAC,CAAC,CAAC;;gBAIjC,EAAE,EAAE,MAAM,CAAC,EAAE,WAAW,EAAE,UAAU;IAKhD,IAAI,OAAO,MAGV;CACF;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,CAAC,SAAS,EAAE,GAAG,KAAK,CAAC,OAAO,CAAC,EACxD,IAAI,EAAE,CAAC,GACN,CAAC,CAAC,EAAE,CAAC,QAAQ,EAAE,CAAC,KAAK,IAAI,CAAC,CAyG5B"}
@@ -33,7 +33,20 @@ _ReactiveValue_fn = new WeakMap(), _ReactiveValue_subscribe = new WeakMap();
33
33
  export function createRawRef(init) {
34
34
  const refObj = (Array.isArray(init) ? [] : {});
35
35
  const hiddenKeys = new SvelteSet();
36
+ // Absent keys have no `$state.raw` field to subscribe to, and `length` is a
37
+ // plain array property, so reads of either are tracked through this instead.
38
+ // Without it, anything observed while the ref is empty never re-runs.
39
+ let keyVersion = $state.raw(0);
40
+ const trackKeys = () => keyVersion;
36
41
  const out = new Proxy(refObj, {
42
+ get(target, prop, receiver) {
43
+ if (hiddenKeys.has(prop) ||
44
+ !(prop in target) ||
45
+ (Array.isArray(target) && prop === 'length')) {
46
+ trackKeys();
47
+ }
48
+ return Reflect.get(target, prop, receiver);
49
+ },
37
50
  set(target, prop, value, receiver) {
38
51
  hiddenKeys.delete(prop);
39
52
  if (prop in target) {
@@ -89,6 +102,14 @@ export function createRawRef(init) {
89
102
  const existingKeys = Object.keys(out);
90
103
  const newKeys = Object.keys(newValue);
91
104
  const keysToRemove = existingKeys.filter((key) => !newKeys.includes(key));
105
+ // Arrays: delete in descending index order so each `deleteProperty` trap
106
+ // sees the slot it is removing as the current tail (length-- stays valid).
107
+ // Forward iteration would shrink the array under our feet and the next
108
+ // index would no longer be `in target`, tripping the trap.
109
+ if (Array.isArray(newValue)) {
110
+ keysToRemove.sort((a, b) => Number(b) - Number(a));
111
+ }
112
+ const keysAdded = newKeys.some((key) => !existingKeys.includes(key));
92
113
  for (const key of keysToRemove) {
93
114
  // @ts-expect-error
94
115
  delete out[key];
@@ -101,6 +122,9 @@ export function createRawRef(init) {
101
122
  // (See above)
102
123
  out[key] = brand(() => newValue[key]);
103
124
  }
125
+ if (keysAdded || keysToRemove.length > 0) {
126
+ keyVersion++;
127
+ }
104
128
  }
105
129
  // we can't pass `init` directly into the proxy because it'll never set the state fields
106
130
  // (because (prop in target) will always be true)
@@ -14,7 +14,7 @@ export function useMutationState(options = {}, queryClient) {
14
14
  const unsubscribe = mutationCache.subscribe(() => {
15
15
  const nextResult = replaceEqualDeep(result, getResult(mutationCache, options));
16
16
  if (result !== nextResult) {
17
- Object.assign(result, nextResult);
17
+ result.splice(0, result.length, ...nextResult);
18
18
  }
19
19
  });
20
20
  return unsubscribe;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/svelte-query",
3
- "version": "6.1.40",
3
+ "version": "6.1.42",
4
4
  "description": "Primitives for managing, caching and syncing asynchronous and remote data in Svelte",
5
5
  "author": "Lachlan Collins",
6
6
  "license": "MIT",
@@ -39,7 +39,7 @@
39
39
  "!src/__tests__"
40
40
  ],
41
41
  "dependencies": {
42
- "@tanstack/query-core": "5.102.1"
42
+ "@tanstack/query-core": "5.102.2"
43
43
  },
44
44
  "devDependencies": {
45
45
  "@sveltejs/package": "^2.5.8",
@@ -31,7 +31,22 @@ export function createRawRef<T extends {} | Array<unknown>>(
31
31
  ): [T, (newValue: T) => void] {
32
32
  const refObj = (Array.isArray(init) ? [] : {}) as T
33
33
  const hiddenKeys = new SvelteSet<PropertyKey>()
34
+ // Absent keys have no `$state.raw` field to subscribe to, and `length` is a
35
+ // plain array property, so reads of either are tracked through this instead.
36
+ // Without it, anything observed while the ref is empty never re-runs.
37
+ let keyVersion = $state.raw(0)
38
+ const trackKeys = () => keyVersion
34
39
  const out = new Proxy(refObj, {
40
+ get(target, prop, receiver) {
41
+ if (
42
+ hiddenKeys.has(prop) ||
43
+ !(prop in target) ||
44
+ (Array.isArray(target) && prop === 'length')
45
+ ) {
46
+ trackKeys()
47
+ }
48
+ return Reflect.get(target, prop, receiver)
49
+ },
35
50
  set(target, prop, value, receiver) {
36
51
  hiddenKeys.delete(prop)
37
52
  if (prop in target) {
@@ -88,6 +103,14 @@ export function createRawRef<T extends {} | Array<unknown>>(
88
103
  const existingKeys = Object.keys(out)
89
104
  const newKeys = Object.keys(newValue)
90
105
  const keysToRemove = existingKeys.filter((key) => !newKeys.includes(key))
106
+ // Arrays: delete in descending index order so each `deleteProperty` trap
107
+ // sees the slot it is removing as the current tail (length-- stays valid).
108
+ // Forward iteration would shrink the array under our feet and the next
109
+ // index would no longer be `in target`, tripping the trap.
110
+ if (Array.isArray(newValue)) {
111
+ keysToRemove.sort((a, b) => Number(b) - Number(a))
112
+ }
113
+ const keysAdded = newKeys.some((key) => !existingKeys.includes(key))
91
114
  for (const key of keysToRemove) {
92
115
  // @ts-expect-error
93
116
  delete out[key]
@@ -100,6 +123,9 @@ export function createRawRef<T extends {} | Array<unknown>>(
100
123
  // (See above)
101
124
  out[key] = brand(() => newValue[key])
102
125
  }
126
+ if (keysAdded || keysToRemove.length > 0) {
127
+ keyVersion++
128
+ }
103
129
  }
104
130
 
105
131
  // we can't pass `init` directly into the proxy because it'll never set the state fields
@@ -44,7 +44,7 @@ export function useMutationState<
44
44
  getResult(mutationCache, options),
45
45
  )
46
46
  if (result !== nextResult) {
47
- Object.assign(result, nextResult)
47
+ result.splice(0, result.length, ...nextResult)
48
48
  }
49
49
  })
50
50