@azure-net/kit 6.0.0-next.5 → 6.0.0-next.6

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.
@@ -19,5 +19,5 @@ export interface QueryController<T extends Record<string, unknown>> {
19
19
  getInitial: () => T;
20
20
  createEffect: (callback: EffectCallback, dependencies?: readonly QueryPath<T>[]) => void;
21
21
  }
22
- export declare const createQuery: <T extends Record<string, unknown>>(initialValue: T, options?: CreateQueryOptions<T>) => QueryController<T>;
22
+ export declare const createQuery: <T extends Record<string, unknown>>(initialValue: T | (() => T), options?: CreateQueryOptions<T>) => QueryController<T>;
23
23
  export {};
@@ -1,5 +1,6 @@
1
- import { replaceState } from '$app/navigation';
1
+ import { goto } from '$app/navigation';
2
2
  import { page } from '$app/state';
3
+ import { untrack } from 'svelte';
3
4
  import { createEffect } from '../effect/Effect.svelte.js';
4
5
  import { cloneStateValue } from '../shared/cloneStateValue.js';
5
6
  import { fromSearchParams, toSearchParams } from './SearchParamsSync.js';
@@ -53,14 +54,15 @@ const createDeepDependency = (read) => {
53
54
  };
54
55
  };
55
56
  export const createQuery = (initialValue, options) => {
56
- const baseInitial = cloneStateValue(initialValue);
57
+ // Capture defaults once; reset restores this snapshot rather than rerunning the initializer.
58
+ const baseInitial = untrack(() => cloneStateValue(typeof initialValue === 'function' ? initialValue() : initialValue));
57
59
  const searchParamsSync = options?.syncWithSearchParams;
58
60
  const syncSettings = typeof searchParamsSync === 'object' ? searchParamsSync : undefined;
59
61
  const syncEnabled = Boolean(searchParamsSync);
60
62
  const parseSearchParams = syncSettings?.fromSearchParams ?? (fromSearchParams);
61
63
  const serializeSearchParams = syncSettings?.toSearchParams ?? (toSearchParams);
62
64
  const parsedInitial = syncEnabled
63
- ? parseSearchParams(new URLSearchParams(page.url.searchParams.toString()), cloneStateValue(baseInitial))
65
+ ? parseSearchParams(new URLSearchParams((page.shallow?.url ?? page.url).searchParams.toString()), cloneStateValue(baseInitial))
64
66
  : undefined;
65
67
  let data = $state(parsedInitial ? { ...cloneStateValue(baseInitial), ...cloneStateValue(parsedInitial) } : cloneStateValue(baseInitial));
66
68
  const reset = () => {
@@ -94,13 +96,17 @@ export const createQuery = (initialValue, options) => {
94
96
  if (nextParams.toString() === initialParams.toString())
95
97
  return;
96
98
  }
97
- const url = new URL(page.url.href);
99
+ const currentUrl = page.shallow?.url ?? page.url;
100
+ const url = new URL(currentUrl.href);
98
101
  for (const key of managedKeys)
99
102
  url.searchParams.delete(key);
100
103
  for (const [key, value] of nextParams)
101
104
  url.searchParams.append(key, value);
102
- if (url.search !== page.url.search)
103
- replaceState(url, page.state);
105
+ if (url.search !== currentUrl.search) {
106
+ void goto(url, { state: page.state, shallow: true, replace: true, reset: false }).catch((error) => {
107
+ console.error('[createQuery] Failed to synchronize search parameters', error);
108
+ });
109
+ }
104
110
  }, [createDeepDependency(() => data)]);
105
111
  }
106
112
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@azure-net/kit",
3
- "version": "6.0.0-next.5",
3
+ "version": "6.0.0-next.6",
4
4
  "license": "MIT",
5
5
  "author": "Pixel1917",
6
6
  "description": "Universal toolkit and library collection, developed as part of the Azure-net ecosystem",