@tanstack/preact-query-persist-client 5.104.0 → 5.104.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.
@@ -4,16 +4,26 @@ let _tanstack_query_persist_client_core = require("@tanstack/query-persist-clien
4
4
  let _tanstack_preact_query = require("@tanstack/preact-query");
5
5
  let preact_jsx_runtime = require("preact/jsx-runtime");
6
6
  //#region src/PersistQueryClientProvider.tsx
7
+ /**
8
+ * Provides the `QueryClient` like `QueryClientProvider`, and restores the persisted client first:
9
+ * while restoring, `useIsRestoring` returns `true` and queries wait for the restore to finish
10
+ * before subscribing. Once restored, the client is saved with the persister whenever the cache
11
+ * changes.
12
+ * @param props - The `QueryClientProvider` props, the `persistOptions`, and the `onSuccess` and
13
+ * `onError` callbacks. `onSuccess` is called once restoring finishes, even if nothing was restored
14
+ * (e.g. because the persisted client expired), and `onError` if restoring or `onSuccess` throws.
15
+ * @returns The `QueryClientProvider` wrapping the children.
16
+ */
7
17
  const PersistQueryClientProvider = ({ children, persistOptions, onSuccess, onError, ...props }) => {
8
18
  const [isRestoring, setIsRestoring] = (0, preact_hooks.useState)(true);
9
- const refs = (0, preact_hooks.useRef)({
19
+ const optionsRef = (0, preact_hooks.useRef)({
10
20
  persistOptions,
11
21
  onSuccess,
12
22
  onError
13
23
  });
14
- const didRestore = (0, preact_hooks.useRef)(false);
24
+ const didRestoreRef = (0, preact_hooks.useRef)(false);
15
25
  (0, preact_hooks.useEffect)(() => {
16
- refs.current = {
26
+ optionsRef.current = {
17
27
  persistOptions,
18
28
  onSuccess,
19
29
  onError
@@ -21,17 +31,17 @@ const PersistQueryClientProvider = ({ children, persistOptions, onSuccess, onErr
21
31
  });
22
32
  (0, preact_hooks.useEffect)(() => {
23
33
  const options = {
24
- ...refs.current.persistOptions,
34
+ ...optionsRef.current.persistOptions,
25
35
  queryClient: props.client
26
36
  };
27
- if (!didRestore.current) {
28
- didRestore.current = true;
37
+ if (!didRestoreRef.current) {
38
+ didRestoreRef.current = true;
29
39
  (0, _tanstack_query_persist_client_core.persistQueryClientRestore)(options).then(() => {
30
- var _refs$current$onSucce, _refs$current;
31
- return (_refs$current$onSucce = (_refs$current = refs.current).onSuccess) === null || _refs$current$onSucce === void 0 ? void 0 : _refs$current$onSucce.call(_refs$current);
40
+ var _optionsRef$current$o, _optionsRef$current;
41
+ return (_optionsRef$current$o = (_optionsRef$current = optionsRef.current).onSuccess) === null || _optionsRef$current$o === void 0 ? void 0 : _optionsRef$current$o.call(_optionsRef$current);
32
42
  }).catch(() => {
33
- var _refs$current$onError, _refs$current2;
34
- return (_refs$current$onError = (_refs$current2 = refs.current).onError) === null || _refs$current$onError === void 0 ? void 0 : _refs$current$onError.call(_refs$current2);
43
+ var _optionsRef$current$o2, _optionsRef$current2;
44
+ return (_optionsRef$current$o2 = (_optionsRef$current2 = optionsRef.current).onError) === null || _optionsRef$current$o2 === void 0 ? void 0 : _optionsRef$current$o2.call(_optionsRef$current2);
35
45
  }).finally(() => {
36
46
  setIsRestoring(false);
37
47
  });
@@ -1 +1 @@
1
- {"version":3,"file":"PersistQueryClientProvider.cjs","names":["useState","useRef","persistQueryClientSubscribe","QueryClientProvider","IsRestoringProvider"],"sources":["../../src/PersistQueryClientProvider.tsx"],"sourcesContent":["import { useEffect, useRef, useState } from 'preact/hooks'\nimport type { VNode } from 'preact'\n\nimport {\n persistQueryClientRestore,\n persistQueryClientSubscribe,\n} from '@tanstack/query-persist-client-core'\nimport {\n IsRestoringProvider,\n QueryClientProvider,\n} from '@tanstack/preact-query'\nimport type { PersistQueryClientOptions } from '@tanstack/query-persist-client-core'\nimport type {\n OmitKeyof,\n QueryClientProviderProps,\n} from '@tanstack/preact-query'\n\nexport type PersistQueryClientProviderProps = QueryClientProviderProps & {\n persistOptions: OmitKeyof<PersistQueryClientOptions, 'queryClient'>\n onSuccess?: () => Promise<unknown> | unknown\n onError?: () => Promise<unknown> | unknown\n}\n\nexport const PersistQueryClientProvider = ({\n children,\n persistOptions,\n onSuccess,\n onError,\n ...props\n}: PersistQueryClientProviderProps): VNode => {\n const [isRestoring, setIsRestoring] = useState(true)\n const refs = useRef({ persistOptions, onSuccess, onError })\n const didRestore = useRef(false)\n\n useEffect(() => {\n refs.current = { persistOptions, onSuccess, onError }\n })\n\n useEffect(() => {\n const options = {\n ...refs.current.persistOptions,\n queryClient: props.client,\n }\n if (!didRestore.current) {\n didRestore.current = true\n persistQueryClientRestore(options)\n .then(() => refs.current.onSuccess?.())\n .catch(() => refs.current.onError?.())\n .finally(() => {\n setIsRestoring(false)\n })\n }\n return isRestoring ? undefined : persistQueryClientSubscribe(options)\n }, [props.client, isRestoring])\n\n return (\n <QueryClientProvider {...props}>\n <IsRestoringProvider value={isRestoring}>{children}</IsRestoringProvider>\n </QueryClientProvider>\n )\n}\n"],"mappings":";;;;;;AAuBA,MAAa,8BAA8B,EACzC,UACA,gBACA,WACA,SACA,GAAG,YACyC;CAC5C,MAAM,CAAC,aAAa,mBAAA,GAAkBA,aAAAA,SAAAA,CAAS,IAAI;CACnD,MAAM,QAAA,GAAOC,aAAAA,OAAAA,CAAO;EAAE;EAAgB;EAAW;CAAQ,CAAC;CAC1D,MAAM,cAAA,GAAaA,aAAAA,OAAAA,CAAO,KAAK;CAE/B,CAAA,GAAA,aAAA,UAAA,OAAgB;EACd,KAAK,UAAU;GAAE;GAAgB;GAAW;EAAQ;CACtD,CAAC;CAED,CAAA,GAAA,aAAA,UAAA,OAAgB;EACd,MAAM,UAAU;GACd,GAAG,KAAK,QAAQ;GAChB,aAAa,MAAM;EACrB;EACA,IAAI,CAAC,WAAW,SAAS;GACvB,WAAW,UAAU;GACrB,CAAA,GAAA,oCAAA,0BAAA,CAA0B,OAAO,CAAC,CAC/B,WAAW;;IAAK,QAAA,yBAAA,gBAAA,KAAA,QAAA,CAAQ,eAAA,QAAA,0BAAA,KAAA,IAAA,KAAA,IAAA,sBAAA,KAAA,aAAY;GAAC,CAAA,CAAC,CACtC,YAAY;;IAAK,QAAA,yBAAA,iBAAA,KAAA,QAAA,CAAQ,aAAA,QAAA,0BAAA,KAAA,IAAA,KAAA,IAAA,sBAAA,KAAA,cAAU;GAAC,CAAA,CAAC,CACrC,cAAc;IACb,eAAe,KAAK;GACtB,CAAC;EACL;EACA,OAAO,cAAc,KAAA,KAAA,GAAYC,oCAAAA,4BAAAA,CAA4B,OAAO;CACtE,GAAG,CAAC,MAAM,QAAQ,WAAW,CAAC;CAE9B,OACE,iBAAA,GAAA,mBAAA,IAAA,CAACC,uBAAAA,qBAAD;EAAqB,GAAI;EACvB,UAAA,iBAAA,GAAA,mBAAA,IAAA,CAACC,uBAAAA,qBAAD;GAAqB,OAAO;GAAc;EAA8B,CAAA;CACrD,CAAA;AAEzB"}
1
+ {"version":3,"file":"PersistQueryClientProvider.cjs","names":["useState","useRef","persistQueryClientSubscribe","QueryClientProvider","IsRestoringProvider"],"sources":["../../src/PersistQueryClientProvider.tsx"],"sourcesContent":["import { useEffect, useRef, useState } from 'preact/hooks'\n\nimport {\n persistQueryClientRestore,\n persistQueryClientSubscribe,\n} from '@tanstack/query-persist-client-core'\nimport {\n IsRestoringProvider,\n QueryClientProvider,\n} from '@tanstack/preact-query'\nimport type { VNode } from 'preact'\nimport type { PersistQueryClientOptions } from '@tanstack/query-persist-client-core'\nimport type {\n OmitKeyof,\n QueryClientProviderProps,\n} from '@tanstack/preact-query'\n\n/**\n * The props of `PersistQueryClientProvider`: the props of `QueryClientProvider`, plus the\n * `persistOptions` and callbacks for when restoring succeeds or fails.\n */\nexport type PersistQueryClientProviderProps = QueryClientProviderProps & {\n persistOptions: OmitKeyof<PersistQueryClientOptions, 'queryClient'>\n onSuccess?: () => Promise<unknown> | unknown\n onError?: () => Promise<unknown> | unknown\n}\n\n/**\n * Provides the `QueryClient` like `QueryClientProvider`, and restores the persisted client first:\n * while restoring, `useIsRestoring` returns `true` and queries wait for the restore to finish\n * before subscribing. Once restored, the client is saved with the persister whenever the cache\n * changes.\n * @param props - The `QueryClientProvider` props, the `persistOptions`, and the `onSuccess` and\n * `onError` callbacks. `onSuccess` is called once restoring finishes, even if nothing was restored\n * (e.g. because the persisted client expired), and `onError` if restoring or `onSuccess` throws.\n * @returns The `QueryClientProvider` wrapping the children.\n */\nexport const PersistQueryClientProvider = ({\n children,\n persistOptions,\n onSuccess,\n onError,\n ...props\n}: PersistQueryClientProviderProps): VNode => {\n const [isRestoring, setIsRestoring] = useState(true)\n const optionsRef = useRef({ persistOptions, onSuccess, onError })\n const didRestoreRef = useRef(false)\n\n useEffect(() => {\n optionsRef.current = { persistOptions, onSuccess, onError }\n })\n\n useEffect(() => {\n const options = {\n ...optionsRef.current.persistOptions,\n queryClient: props.client,\n }\n if (!didRestoreRef.current) {\n didRestoreRef.current = true\n persistQueryClientRestore(options)\n .then(() => optionsRef.current.onSuccess?.())\n .catch(() => optionsRef.current.onError?.())\n .finally(() => {\n setIsRestoring(false)\n })\n }\n return isRestoring ? undefined : persistQueryClientSubscribe(options)\n }, [props.client, isRestoring])\n\n return (\n <QueryClientProvider {...props}>\n <IsRestoringProvider value={isRestoring}>{children}</IsRestoringProvider>\n </QueryClientProvider>\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAqCA,MAAa,8BAA8B,EACzC,UACA,gBACA,WACA,SACA,GAAG,YACyC;CAC5C,MAAM,CAAC,aAAa,mBAAA,GAAkBA,aAAAA,SAAAA,CAAS,IAAI;CACnD,MAAM,cAAA,GAAaC,aAAAA,OAAAA,CAAO;EAAE;EAAgB;EAAW;CAAQ,CAAC;CAChE,MAAM,iBAAA,GAAgBA,aAAAA,OAAAA,CAAO,KAAK;CAElC,CAAA,GAAA,aAAA,UAAA,OAAgB;EACd,WAAW,UAAU;GAAE;GAAgB;GAAW;EAAQ;CAC5D,CAAC;CAED,CAAA,GAAA,aAAA,UAAA,OAAgB;EACd,MAAM,UAAU;GACd,GAAG,WAAW,QAAQ;GACtB,aAAa,MAAM;EACrB;EACA,IAAI,CAAC,cAAc,SAAS;GAC1B,cAAc,UAAU;GACxB,CAAA,GAAA,oCAAA,0BAAA,CAA0B,OAAO,CAAC,CAC/B,WAAW;;IAAW,QAAA,yBAAA,sBAAA,WAAA,QAAA,CAAQ,eAAA,QAAA,0BAAA,KAAA,IAAA,KAAA,IAAA,sBAAA,KAAA,mBAAY;GAAC,CAAA,CAAC,CAC5C,YAAY;;IAAW,QAAA,0BAAA,uBAAA,WAAA,QAAA,CAAQ,aAAA,QAAA,2BAAA,KAAA,IAAA,KAAA,IAAA,uBAAA,KAAA,oBAAU;GAAC,CAAA,CAAC,CAC3C,cAAc;IACb,eAAe,KAAK;GACtB,CAAC;EACL;EACA,OAAO,cAAc,KAAA,KAAA,GAAYC,oCAAAA,4BAAAA,CAA4B,OAAO;CACtE,GAAG,CAAC,MAAM,QAAQ,WAAW,CAAC;CAE9B,OACE,iBAAA,GAAA,mBAAA,IAAA,CAACC,uBAAAA,qBAAD;EAAqB,GAAI;EACvB,UAAA,iBAAA,GAAA,mBAAA,IAAA,CAACC,uBAAAA,qBAAD;GAAqB,OAAO;GAAc;EAA8B,CAAA;CACrD,CAAA;AAEzB"}
@@ -2,11 +2,25 @@ import { VNode } from "preact";
2
2
  import { PersistQueryClientOptions } from "@tanstack/query-persist-client-core";
3
3
  import { OmitKeyof, QueryClientProviderProps } from "@tanstack/preact-query";
4
4
  //#region src/PersistQueryClientProvider.d.ts
5
+ /**
6
+ * The props of `PersistQueryClientProvider`: the props of `QueryClientProvider`, plus the
7
+ * `persistOptions` and callbacks for when restoring succeeds or fails.
8
+ */
5
9
  export type PersistQueryClientProviderProps = QueryClientProviderProps & {
6
10
  persistOptions: OmitKeyof<PersistQueryClientOptions, 'queryClient'>;
7
11
  onSuccess?: () => Promise<unknown> | unknown;
8
12
  onError?: () => Promise<unknown> | unknown;
9
13
  };
14
+ /**
15
+ * Provides the `QueryClient` like `QueryClientProvider`, and restores the persisted client first:
16
+ * while restoring, `useIsRestoring` returns `true` and queries wait for the restore to finish
17
+ * before subscribing. Once restored, the client is saved with the persister whenever the cache
18
+ * changes.
19
+ * @param props - The `QueryClientProvider` props, the `persistOptions`, and the `onSuccess` and
20
+ * `onError` callbacks. `onSuccess` is called once restoring finishes, even if nothing was restored
21
+ * (e.g. because the persisted client expired), and `onError` if restoring or `onSuccess` throws.
22
+ * @returns The `QueryClientProvider` wrapping the children.
23
+ */
10
24
  export declare const PersistQueryClientProvider: ({ children, persistOptions, onSuccess, onError, ...props }: PersistQueryClientProviderProps) => VNode;
11
25
  //#endregion
12
26
  //# sourceMappingURL=PersistQueryClientProvider.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"PersistQueryClientProvider.d.cts","names":[],"sources":["../../src/PersistQueryClientProvider.tsx"],"mappings":";;;;YAiBY,kCAAkC;EAC5C,gBAAgB,UAAU;EAC1B,kBAAkB;EAClB,gBAAgB;;qBAGL,+BAA8B,UAAA,gBAAA,WAAA,YAAA,SAMxC,oCAAkC"}
1
+ {"version":3,"file":"PersistQueryClientProvider.d.cts","names":[],"sources":["../../src/PersistQueryClientProvider.tsx"],"mappings":";;;;;;;;YAqBY,kCAAkC;EAC5C,gBAAgB,UAAU;EAC1B,kBAAkB;EAClB,gBAAgB;;;;;;;;;;;;qBAaL,+BAA8B,UAAA,gBAAA,WAAA,YAAA,SAMxC,oCAAkC"}
@@ -2,11 +2,25 @@ import { PersistQueryClientOptions } from "@tanstack/query-persist-client-core";
2
2
  import { OmitKeyof, QueryClientProviderProps } from "@tanstack/preact-query";
3
3
  import { VNode } from "preact";
4
4
  //#region src/PersistQueryClientProvider.d.ts
5
+ /**
6
+ * The props of `PersistQueryClientProvider`: the props of `QueryClientProvider`, plus the
7
+ * `persistOptions` and callbacks for when restoring succeeds or fails.
8
+ */
5
9
  export type PersistQueryClientProviderProps = QueryClientProviderProps & {
6
10
  persistOptions: OmitKeyof<PersistQueryClientOptions, 'queryClient'>;
7
11
  onSuccess?: () => Promise<unknown> | unknown;
8
12
  onError?: () => Promise<unknown> | unknown;
9
13
  };
14
+ /**
15
+ * Provides the `QueryClient` like `QueryClientProvider`, and restores the persisted client first:
16
+ * while restoring, `useIsRestoring` returns `true` and queries wait for the restore to finish
17
+ * before subscribing. Once restored, the client is saved with the persister whenever the cache
18
+ * changes.
19
+ * @param props - The `QueryClientProvider` props, the `persistOptions`, and the `onSuccess` and
20
+ * `onError` callbacks. `onSuccess` is called once restoring finishes, even if nothing was restored
21
+ * (e.g. because the persisted client expired), and `onError` if restoring or `onSuccess` throws.
22
+ * @returns The `QueryClientProvider` wrapping the children.
23
+ */
10
24
  export declare const PersistQueryClientProvider: ({ children, persistOptions, onSuccess, onError, ...props }: PersistQueryClientProviderProps) => VNode;
11
25
  //#endregion
12
26
  //# sourceMappingURL=PersistQueryClientProvider.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"PersistQueryClientProvider.d.ts","names":[],"sources":["../../src/PersistQueryClientProvider.tsx"],"mappings":";;;;YAiBY,kCAAkC;EAC5C,gBAAgB,UAAU;EAC1B,kBAAkB;EAClB,gBAAgB;;qBAGL,+BAA8B,UAAA,gBAAA,WAAA,YAAA,SAMxC,oCAAkC"}
1
+ {"version":3,"file":"PersistQueryClientProvider.d.ts","names":[],"sources":["../../src/PersistQueryClientProvider.tsx"],"mappings":";;;;;;;;YAqBY,kCAAkC;EAC5C,gBAAgB,UAAU;EAC1B,kBAAkB;EAClB,gBAAgB;;;;;;;;;;;;qBAaL,+BAA8B,UAAA,gBAAA,WAAA,YAAA,SAMxC,oCAAkC"}
@@ -3,16 +3,26 @@ import { persistQueryClientRestore, persistQueryClientSubscribe } from "@tanstac
3
3
  import { IsRestoringProvider, QueryClientProvider } from "@tanstack/preact-query";
4
4
  import { jsx } from "preact/jsx-runtime";
5
5
  //#region src/PersistQueryClientProvider.tsx
6
+ /**
7
+ * Provides the `QueryClient` like `QueryClientProvider`, and restores the persisted client first:
8
+ * while restoring, `useIsRestoring` returns `true` and queries wait for the restore to finish
9
+ * before subscribing. Once restored, the client is saved with the persister whenever the cache
10
+ * changes.
11
+ * @param props - The `QueryClientProvider` props, the `persistOptions`, and the `onSuccess` and
12
+ * `onError` callbacks. `onSuccess` is called once restoring finishes, even if nothing was restored
13
+ * (e.g. because the persisted client expired), and `onError` if restoring or `onSuccess` throws.
14
+ * @returns The `QueryClientProvider` wrapping the children.
15
+ */
6
16
  const PersistQueryClientProvider = ({ children, persistOptions, onSuccess, onError, ...props }) => {
7
17
  const [isRestoring, setIsRestoring] = useState(true);
8
- const refs = useRef({
18
+ const optionsRef = useRef({
9
19
  persistOptions,
10
20
  onSuccess,
11
21
  onError
12
22
  });
13
- const didRestore = useRef(false);
23
+ const didRestoreRef = useRef(false);
14
24
  useEffect(() => {
15
- refs.current = {
25
+ optionsRef.current = {
16
26
  persistOptions,
17
27
  onSuccess,
18
28
  onError
@@ -20,17 +30,17 @@ const PersistQueryClientProvider = ({ children, persistOptions, onSuccess, onErr
20
30
  });
21
31
  useEffect(() => {
22
32
  const options = {
23
- ...refs.current.persistOptions,
33
+ ...optionsRef.current.persistOptions,
24
34
  queryClient: props.client
25
35
  };
26
- if (!didRestore.current) {
27
- didRestore.current = true;
36
+ if (!didRestoreRef.current) {
37
+ didRestoreRef.current = true;
28
38
  persistQueryClientRestore(options).then(() => {
29
- var _refs$current$onSucce, _refs$current;
30
- return (_refs$current$onSucce = (_refs$current = refs.current).onSuccess) === null || _refs$current$onSucce === void 0 ? void 0 : _refs$current$onSucce.call(_refs$current);
39
+ var _optionsRef$current$o, _optionsRef$current;
40
+ return (_optionsRef$current$o = (_optionsRef$current = optionsRef.current).onSuccess) === null || _optionsRef$current$o === void 0 ? void 0 : _optionsRef$current$o.call(_optionsRef$current);
31
41
  }).catch(() => {
32
- var _refs$current$onError, _refs$current2;
33
- return (_refs$current$onError = (_refs$current2 = refs.current).onError) === null || _refs$current$onError === void 0 ? void 0 : _refs$current$onError.call(_refs$current2);
42
+ var _optionsRef$current$o2, _optionsRef$current2;
43
+ return (_optionsRef$current$o2 = (_optionsRef$current2 = optionsRef.current).onError) === null || _optionsRef$current$o2 === void 0 ? void 0 : _optionsRef$current$o2.call(_optionsRef$current2);
34
44
  }).finally(() => {
35
45
  setIsRestoring(false);
36
46
  });
@@ -1 +1 @@
1
- {"version":3,"file":"PersistQueryClientProvider.js","names":[],"sources":["../../src/PersistQueryClientProvider.tsx"],"sourcesContent":["import { useEffect, useRef, useState } from 'preact/hooks'\nimport type { VNode } from 'preact'\n\nimport {\n persistQueryClientRestore,\n persistQueryClientSubscribe,\n} from '@tanstack/query-persist-client-core'\nimport {\n IsRestoringProvider,\n QueryClientProvider,\n} from '@tanstack/preact-query'\nimport type { PersistQueryClientOptions } from '@tanstack/query-persist-client-core'\nimport type {\n OmitKeyof,\n QueryClientProviderProps,\n} from '@tanstack/preact-query'\n\nexport type PersistQueryClientProviderProps = QueryClientProviderProps & {\n persistOptions: OmitKeyof<PersistQueryClientOptions, 'queryClient'>\n onSuccess?: () => Promise<unknown> | unknown\n onError?: () => Promise<unknown> | unknown\n}\n\nexport const PersistQueryClientProvider = ({\n children,\n persistOptions,\n onSuccess,\n onError,\n ...props\n}: PersistQueryClientProviderProps): VNode => {\n const [isRestoring, setIsRestoring] = useState(true)\n const refs = useRef({ persistOptions, onSuccess, onError })\n const didRestore = useRef(false)\n\n useEffect(() => {\n refs.current = { persistOptions, onSuccess, onError }\n })\n\n useEffect(() => {\n const options = {\n ...refs.current.persistOptions,\n queryClient: props.client,\n }\n if (!didRestore.current) {\n didRestore.current = true\n persistQueryClientRestore(options)\n .then(() => refs.current.onSuccess?.())\n .catch(() => refs.current.onError?.())\n .finally(() => {\n setIsRestoring(false)\n })\n }\n return isRestoring ? undefined : persistQueryClientSubscribe(options)\n }, [props.client, isRestoring])\n\n return (\n <QueryClientProvider {...props}>\n <IsRestoringProvider value={isRestoring}>{children}</IsRestoringProvider>\n </QueryClientProvider>\n )\n}\n"],"mappings":";;;;;AAuBA,MAAa,8BAA8B,EACzC,UACA,gBACA,WACA,SACA,GAAG,YACyC;CAC5C,MAAM,CAAC,aAAa,kBAAkB,SAAS,IAAI;CACnD,MAAM,OAAO,OAAO;EAAE;EAAgB;EAAW;CAAQ,CAAC;CAC1D,MAAM,aAAa,OAAO,KAAK;CAE/B,gBAAgB;EACd,KAAK,UAAU;GAAE;GAAgB;GAAW;EAAQ;CACtD,CAAC;CAED,gBAAgB;EACd,MAAM,UAAU;GACd,GAAG,KAAK,QAAQ;GAChB,aAAa,MAAM;EACrB;EACA,IAAI,CAAC,WAAW,SAAS;GACvB,WAAW,UAAU;GACrB,0BAA0B,OAAO,CAAC,CAC/B,WAAW;;IAAK,QAAA,yBAAA,gBAAA,KAAA,QAAA,CAAQ,eAAA,QAAA,0BAAA,KAAA,IAAA,KAAA,IAAA,sBAAA,KAAA,aAAY;GAAC,CAAA,CAAC,CACtC,YAAY;;IAAK,QAAA,yBAAA,iBAAA,KAAA,QAAA,CAAQ,aAAA,QAAA,0BAAA,KAAA,IAAA,KAAA,IAAA,sBAAA,KAAA,cAAU;GAAC,CAAA,CAAC,CACrC,cAAc;IACb,eAAe,KAAK;GACtB,CAAC;EACL;EACA,OAAO,cAAc,KAAA,IAAY,4BAA4B,OAAO;CACtE,GAAG,CAAC,MAAM,QAAQ,WAAW,CAAC;CAE9B,OACE,oBAAC,qBAAD;EAAqB,GAAI;EACvB,UAAA,oBAAC,qBAAD;GAAqB,OAAO;GAAc;EAA8B,CAAA;CACrD,CAAA;AAEzB"}
1
+ {"version":3,"file":"PersistQueryClientProvider.js","names":[],"sources":["../../src/PersistQueryClientProvider.tsx"],"sourcesContent":["import { useEffect, useRef, useState } from 'preact/hooks'\n\nimport {\n persistQueryClientRestore,\n persistQueryClientSubscribe,\n} from '@tanstack/query-persist-client-core'\nimport {\n IsRestoringProvider,\n QueryClientProvider,\n} from '@tanstack/preact-query'\nimport type { VNode } from 'preact'\nimport type { PersistQueryClientOptions } from '@tanstack/query-persist-client-core'\nimport type {\n OmitKeyof,\n QueryClientProviderProps,\n} from '@tanstack/preact-query'\n\n/**\n * The props of `PersistQueryClientProvider`: the props of `QueryClientProvider`, plus the\n * `persistOptions` and callbacks for when restoring succeeds or fails.\n */\nexport type PersistQueryClientProviderProps = QueryClientProviderProps & {\n persistOptions: OmitKeyof<PersistQueryClientOptions, 'queryClient'>\n onSuccess?: () => Promise<unknown> | unknown\n onError?: () => Promise<unknown> | unknown\n}\n\n/**\n * Provides the `QueryClient` like `QueryClientProvider`, and restores the persisted client first:\n * while restoring, `useIsRestoring` returns `true` and queries wait for the restore to finish\n * before subscribing. Once restored, the client is saved with the persister whenever the cache\n * changes.\n * @param props - The `QueryClientProvider` props, the `persistOptions`, and the `onSuccess` and\n * `onError` callbacks. `onSuccess` is called once restoring finishes, even if nothing was restored\n * (e.g. because the persisted client expired), and `onError` if restoring or `onSuccess` throws.\n * @returns The `QueryClientProvider` wrapping the children.\n */\nexport const PersistQueryClientProvider = ({\n children,\n persistOptions,\n onSuccess,\n onError,\n ...props\n}: PersistQueryClientProviderProps): VNode => {\n const [isRestoring, setIsRestoring] = useState(true)\n const optionsRef = useRef({ persistOptions, onSuccess, onError })\n const didRestoreRef = useRef(false)\n\n useEffect(() => {\n optionsRef.current = { persistOptions, onSuccess, onError }\n })\n\n useEffect(() => {\n const options = {\n ...optionsRef.current.persistOptions,\n queryClient: props.client,\n }\n if (!didRestoreRef.current) {\n didRestoreRef.current = true\n persistQueryClientRestore(options)\n .then(() => optionsRef.current.onSuccess?.())\n .catch(() => optionsRef.current.onError?.())\n .finally(() => {\n setIsRestoring(false)\n })\n }\n return isRestoring ? undefined : persistQueryClientSubscribe(options)\n }, [props.client, isRestoring])\n\n return (\n <QueryClientProvider {...props}>\n <IsRestoringProvider value={isRestoring}>{children}</IsRestoringProvider>\n </QueryClientProvider>\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;AAqCA,MAAa,8BAA8B,EACzC,UACA,gBACA,WACA,SACA,GAAG,YACyC;CAC5C,MAAM,CAAC,aAAa,kBAAkB,SAAS,IAAI;CACnD,MAAM,aAAa,OAAO;EAAE;EAAgB;EAAW;CAAQ,CAAC;CAChE,MAAM,gBAAgB,OAAO,KAAK;CAElC,gBAAgB;EACd,WAAW,UAAU;GAAE;GAAgB;GAAW;EAAQ;CAC5D,CAAC;CAED,gBAAgB;EACd,MAAM,UAAU;GACd,GAAG,WAAW,QAAQ;GACtB,aAAa,MAAM;EACrB;EACA,IAAI,CAAC,cAAc,SAAS;GAC1B,cAAc,UAAU;GACxB,0BAA0B,OAAO,CAAC,CAC/B,WAAW;;IAAW,QAAA,yBAAA,sBAAA,WAAA,QAAA,CAAQ,eAAA,QAAA,0BAAA,KAAA,IAAA,KAAA,IAAA,sBAAA,KAAA,mBAAY;GAAC,CAAA,CAAC,CAC5C,YAAY;;IAAW,QAAA,0BAAA,uBAAA,WAAA,QAAA,CAAQ,aAAA,QAAA,2BAAA,KAAA,IAAA,KAAA,IAAA,uBAAA,KAAA,oBAAU;GAAC,CAAA,CAAC,CAC3C,cAAc;IACb,eAAe,KAAK;GACtB,CAAC;EACL;EACA,OAAO,cAAc,KAAA,IAAY,4BAA4B,OAAO;CACtE,GAAG,CAAC,MAAM,QAAQ,WAAW,CAAC;CAE9B,OACE,oBAAC,qBAAD;EAAqB,GAAI;EACvB,UAAA,oBAAC,qBAAD;GAAqB,OAAO;GAAc;EAA8B,CAAA;CACrD,CAAA;AAEzB"}
@@ -4,16 +4,26 @@ let _tanstack_query_persist_client_core = require("@tanstack/query-persist-clien
4
4
  let _tanstack_preact_query = require("@tanstack/preact-query");
5
5
  let preact_jsx_runtime = require("preact/jsx-runtime");
6
6
  //#region src/PersistQueryClientProvider.tsx
7
+ /**
8
+ * Provides the `QueryClient` like `QueryClientProvider`, and restores the persisted client first:
9
+ * while restoring, `useIsRestoring` returns `true` and queries wait for the restore to finish
10
+ * before subscribing. Once restored, the client is saved with the persister whenever the cache
11
+ * changes.
12
+ * @param props - The `QueryClientProvider` props, the `persistOptions`, and the `onSuccess` and
13
+ * `onError` callbacks. `onSuccess` is called once restoring finishes, even if nothing was restored
14
+ * (e.g. because the persisted client expired), and `onError` if restoring or `onSuccess` throws.
15
+ * @returns The `QueryClientProvider` wrapping the children.
16
+ */
7
17
  const PersistQueryClientProvider = ({ children, persistOptions, onSuccess, onError, ...props }) => {
8
18
  const [isRestoring, setIsRestoring] = (0, preact_hooks.useState)(true);
9
- const refs = (0, preact_hooks.useRef)({
19
+ const optionsRef = (0, preact_hooks.useRef)({
10
20
  persistOptions,
11
21
  onSuccess,
12
22
  onError
13
23
  });
14
- const didRestore = (0, preact_hooks.useRef)(false);
24
+ const didRestoreRef = (0, preact_hooks.useRef)(false);
15
25
  (0, preact_hooks.useEffect)(() => {
16
- refs.current = {
26
+ optionsRef.current = {
17
27
  persistOptions,
18
28
  onSuccess,
19
29
  onError
@@ -21,12 +31,12 @@ const PersistQueryClientProvider = ({ children, persistOptions, onSuccess, onErr
21
31
  });
22
32
  (0, preact_hooks.useEffect)(() => {
23
33
  const options = {
24
- ...refs.current.persistOptions,
34
+ ...optionsRef.current.persistOptions,
25
35
  queryClient: props.client
26
36
  };
27
- if (!didRestore.current) {
28
- didRestore.current = true;
29
- (0, _tanstack_query_persist_client_core.persistQueryClientRestore)(options).then(() => refs.current.onSuccess?.()).catch(() => refs.current.onError?.()).finally(() => {
37
+ if (!didRestoreRef.current) {
38
+ didRestoreRef.current = true;
39
+ (0, _tanstack_query_persist_client_core.persistQueryClientRestore)(options).then(() => optionsRef.current.onSuccess?.()).catch(() => optionsRef.current.onError?.()).finally(() => {
30
40
  setIsRestoring(false);
31
41
  });
32
42
  }
@@ -1 +1 @@
1
- {"version":3,"file":"PersistQueryClientProvider.cjs","names":["useState","useRef","persistQueryClientSubscribe","QueryClientProvider","IsRestoringProvider"],"sources":["../../src/PersistQueryClientProvider.tsx"],"sourcesContent":["import { useEffect, useRef, useState } from 'preact/hooks'\nimport type { VNode } from 'preact'\n\nimport {\n persistQueryClientRestore,\n persistQueryClientSubscribe,\n} from '@tanstack/query-persist-client-core'\nimport {\n IsRestoringProvider,\n QueryClientProvider,\n} from '@tanstack/preact-query'\nimport type { PersistQueryClientOptions } from '@tanstack/query-persist-client-core'\nimport type {\n OmitKeyof,\n QueryClientProviderProps,\n} from '@tanstack/preact-query'\n\nexport type PersistQueryClientProviderProps = QueryClientProviderProps & {\n persistOptions: OmitKeyof<PersistQueryClientOptions, 'queryClient'>\n onSuccess?: () => Promise<unknown> | unknown\n onError?: () => Promise<unknown> | unknown\n}\n\nexport const PersistQueryClientProvider = ({\n children,\n persistOptions,\n onSuccess,\n onError,\n ...props\n}: PersistQueryClientProviderProps): VNode => {\n const [isRestoring, setIsRestoring] = useState(true)\n const refs = useRef({ persistOptions, onSuccess, onError })\n const didRestore = useRef(false)\n\n useEffect(() => {\n refs.current = { persistOptions, onSuccess, onError }\n })\n\n useEffect(() => {\n const options = {\n ...refs.current.persistOptions,\n queryClient: props.client,\n }\n if (!didRestore.current) {\n didRestore.current = true\n persistQueryClientRestore(options)\n .then(() => refs.current.onSuccess?.())\n .catch(() => refs.current.onError?.())\n .finally(() => {\n setIsRestoring(false)\n })\n }\n return isRestoring ? undefined : persistQueryClientSubscribe(options)\n }, [props.client, isRestoring])\n\n return (\n <QueryClientProvider {...props}>\n <IsRestoringProvider value={isRestoring}>{children}</IsRestoringProvider>\n </QueryClientProvider>\n )\n}\n"],"mappings":";;;;;;AAuBA,MAAa,8BAA8B,EACzC,UACA,gBACA,WACA,SACA,GAAG,YACyC;CAC5C,MAAM,CAAC,aAAa,mBAAA,GAAkBA,aAAAA,SAAAA,CAAS,IAAI;CACnD,MAAM,QAAA,GAAOC,aAAAA,OAAAA,CAAO;EAAE;EAAgB;EAAW;CAAQ,CAAC;CAC1D,MAAM,cAAA,GAAaA,aAAAA,OAAAA,CAAO,KAAK;CAE/B,CAAA,GAAA,aAAA,UAAA,OAAgB;EACd,KAAK,UAAU;GAAE;GAAgB;GAAW;EAAQ;CACtD,CAAC;CAED,CAAA,GAAA,aAAA,UAAA,OAAgB;EACd,MAAM,UAAU;GACd,GAAG,KAAK,QAAQ;GAChB,aAAa,MAAM;EACrB;EACA,IAAI,CAAC,WAAW,SAAS;GACvB,WAAW,UAAU;GACrB,CAAA,GAAA,oCAAA,0BAAA,CAA0B,OAAO,CAAC,CAC/B,WAAW,KAAK,QAAQ,YAAY,CAAC,CAAC,CACtC,YAAY,KAAK,QAAQ,UAAU,CAAC,CAAC,CACrC,cAAc;IACb,eAAe,KAAK;GACtB,CAAC;EACL;EACA,OAAO,cAAc,KAAA,KAAA,GAAYC,oCAAAA,4BAAAA,CAA4B,OAAO;CACtE,GAAG,CAAC,MAAM,QAAQ,WAAW,CAAC;CAE9B,OACE,iBAAA,GAAA,mBAAA,IAAA,CAACC,uBAAAA,qBAAD;EAAqB,GAAI;EACvB,UAAA,iBAAA,GAAA,mBAAA,IAAA,CAACC,uBAAAA,qBAAD;GAAqB,OAAO;GAAc;EAA8B,CAAA;CACrD,CAAA;AAEzB"}
1
+ {"version":3,"file":"PersistQueryClientProvider.cjs","names":["useState","useRef","persistQueryClientSubscribe","QueryClientProvider","IsRestoringProvider"],"sources":["../../src/PersistQueryClientProvider.tsx"],"sourcesContent":["import { useEffect, useRef, useState } from 'preact/hooks'\n\nimport {\n persistQueryClientRestore,\n persistQueryClientSubscribe,\n} from '@tanstack/query-persist-client-core'\nimport {\n IsRestoringProvider,\n QueryClientProvider,\n} from '@tanstack/preact-query'\nimport type { VNode } from 'preact'\nimport type { PersistQueryClientOptions } from '@tanstack/query-persist-client-core'\nimport type {\n OmitKeyof,\n QueryClientProviderProps,\n} from '@tanstack/preact-query'\n\n/**\n * The props of `PersistQueryClientProvider`: the props of `QueryClientProvider`, plus the\n * `persistOptions` and callbacks for when restoring succeeds or fails.\n */\nexport type PersistQueryClientProviderProps = QueryClientProviderProps & {\n persistOptions: OmitKeyof<PersistQueryClientOptions, 'queryClient'>\n onSuccess?: () => Promise<unknown> | unknown\n onError?: () => Promise<unknown> | unknown\n}\n\n/**\n * Provides the `QueryClient` like `QueryClientProvider`, and restores the persisted client first:\n * while restoring, `useIsRestoring` returns `true` and queries wait for the restore to finish\n * before subscribing. Once restored, the client is saved with the persister whenever the cache\n * changes.\n * @param props - The `QueryClientProvider` props, the `persistOptions`, and the `onSuccess` and\n * `onError` callbacks. `onSuccess` is called once restoring finishes, even if nothing was restored\n * (e.g. because the persisted client expired), and `onError` if restoring or `onSuccess` throws.\n * @returns The `QueryClientProvider` wrapping the children.\n */\nexport const PersistQueryClientProvider = ({\n children,\n persistOptions,\n onSuccess,\n onError,\n ...props\n}: PersistQueryClientProviderProps): VNode => {\n const [isRestoring, setIsRestoring] = useState(true)\n const optionsRef = useRef({ persistOptions, onSuccess, onError })\n const didRestoreRef = useRef(false)\n\n useEffect(() => {\n optionsRef.current = { persistOptions, onSuccess, onError }\n })\n\n useEffect(() => {\n const options = {\n ...optionsRef.current.persistOptions,\n queryClient: props.client,\n }\n if (!didRestoreRef.current) {\n didRestoreRef.current = true\n persistQueryClientRestore(options)\n .then(() => optionsRef.current.onSuccess?.())\n .catch(() => optionsRef.current.onError?.())\n .finally(() => {\n setIsRestoring(false)\n })\n }\n return isRestoring ? undefined : persistQueryClientSubscribe(options)\n }, [props.client, isRestoring])\n\n return (\n <QueryClientProvider {...props}>\n <IsRestoringProvider value={isRestoring}>{children}</IsRestoringProvider>\n </QueryClientProvider>\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAqCA,MAAa,8BAA8B,EACzC,UACA,gBACA,WACA,SACA,GAAG,YACyC;CAC5C,MAAM,CAAC,aAAa,mBAAA,GAAkBA,aAAAA,SAAAA,CAAS,IAAI;CACnD,MAAM,cAAA,GAAaC,aAAAA,OAAAA,CAAO;EAAE;EAAgB;EAAW;CAAQ,CAAC;CAChE,MAAM,iBAAA,GAAgBA,aAAAA,OAAAA,CAAO,KAAK;CAElC,CAAA,GAAA,aAAA,UAAA,OAAgB;EACd,WAAW,UAAU;GAAE;GAAgB;GAAW;EAAQ;CAC5D,CAAC;CAED,CAAA,GAAA,aAAA,UAAA,OAAgB;EACd,MAAM,UAAU;GACd,GAAG,WAAW,QAAQ;GACtB,aAAa,MAAM;EACrB;EACA,IAAI,CAAC,cAAc,SAAS;GAC1B,cAAc,UAAU;GACxB,CAAA,GAAA,oCAAA,0BAAA,CAA0B,OAAO,CAAC,CAC/B,WAAW,WAAW,QAAQ,YAAY,CAAC,CAAC,CAC5C,YAAY,WAAW,QAAQ,UAAU,CAAC,CAAC,CAC3C,cAAc;IACb,eAAe,KAAK;GACtB,CAAC;EACL;EACA,OAAO,cAAc,KAAA,KAAA,GAAYC,oCAAAA,4BAAAA,CAA4B,OAAO;CACtE,GAAG,CAAC,MAAM,QAAQ,WAAW,CAAC;CAE9B,OACE,iBAAA,GAAA,mBAAA,IAAA,CAACC,uBAAAA,qBAAD;EAAqB,GAAI;EACvB,UAAA,iBAAA,GAAA,mBAAA,IAAA,CAACC,uBAAAA,qBAAD;GAAqB,OAAO;GAAc;EAA8B,CAAA;CACrD,CAAA;AAEzB"}
@@ -2,11 +2,25 @@ import { VNode } from "preact";
2
2
  import { PersistQueryClientOptions } from "@tanstack/query-persist-client-core";
3
3
  import { OmitKeyof, QueryClientProviderProps } from "@tanstack/preact-query";
4
4
  //#region src/PersistQueryClientProvider.d.ts
5
+ /**
6
+ * The props of `PersistQueryClientProvider`: the props of `QueryClientProvider`, plus the
7
+ * `persistOptions` and callbacks for when restoring succeeds or fails.
8
+ */
5
9
  export type PersistQueryClientProviderProps = QueryClientProviderProps & {
6
10
  persistOptions: OmitKeyof<PersistQueryClientOptions, 'queryClient'>;
7
11
  onSuccess?: () => Promise<unknown> | unknown;
8
12
  onError?: () => Promise<unknown> | unknown;
9
13
  };
14
+ /**
15
+ * Provides the `QueryClient` like `QueryClientProvider`, and restores the persisted client first:
16
+ * while restoring, `useIsRestoring` returns `true` and queries wait for the restore to finish
17
+ * before subscribing. Once restored, the client is saved with the persister whenever the cache
18
+ * changes.
19
+ * @param props - The `QueryClientProvider` props, the `persistOptions`, and the `onSuccess` and
20
+ * `onError` callbacks. `onSuccess` is called once restoring finishes, even if nothing was restored
21
+ * (e.g. because the persisted client expired), and `onError` if restoring or `onSuccess` throws.
22
+ * @returns The `QueryClientProvider` wrapping the children.
23
+ */
10
24
  export declare const PersistQueryClientProvider: ({ children, persistOptions, onSuccess, onError, ...props }: PersistQueryClientProviderProps) => VNode;
11
25
  //#endregion
12
26
  //# sourceMappingURL=PersistQueryClientProvider.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"PersistQueryClientProvider.d.cts","names":[],"sources":["../../src/PersistQueryClientProvider.tsx"],"mappings":";;;;YAiBY,kCAAkC;EAC5C,gBAAgB,UAAU;EAC1B,kBAAkB;EAClB,gBAAgB;;qBAGL,+BAA8B,UAAA,gBAAA,WAAA,YAAA,SAMxC,oCAAkC"}
1
+ {"version":3,"file":"PersistQueryClientProvider.d.cts","names":[],"sources":["../../src/PersistQueryClientProvider.tsx"],"mappings":";;;;;;;;YAqBY,kCAAkC;EAC5C,gBAAgB,UAAU;EAC1B,kBAAkB;EAClB,gBAAgB;;;;;;;;;;;;qBAaL,+BAA8B,UAAA,gBAAA,WAAA,YAAA,SAMxC,oCAAkC"}
@@ -2,11 +2,25 @@ import { PersistQueryClientOptions } from "@tanstack/query-persist-client-core";
2
2
  import { OmitKeyof, QueryClientProviderProps } from "@tanstack/preact-query";
3
3
  import { VNode } from "preact";
4
4
  //#region src/PersistQueryClientProvider.d.ts
5
+ /**
6
+ * The props of `PersistQueryClientProvider`: the props of `QueryClientProvider`, plus the
7
+ * `persistOptions` and callbacks for when restoring succeeds or fails.
8
+ */
5
9
  export type PersistQueryClientProviderProps = QueryClientProviderProps & {
6
10
  persistOptions: OmitKeyof<PersistQueryClientOptions, 'queryClient'>;
7
11
  onSuccess?: () => Promise<unknown> | unknown;
8
12
  onError?: () => Promise<unknown> | unknown;
9
13
  };
14
+ /**
15
+ * Provides the `QueryClient` like `QueryClientProvider`, and restores the persisted client first:
16
+ * while restoring, `useIsRestoring` returns `true` and queries wait for the restore to finish
17
+ * before subscribing. Once restored, the client is saved with the persister whenever the cache
18
+ * changes.
19
+ * @param props - The `QueryClientProvider` props, the `persistOptions`, and the `onSuccess` and
20
+ * `onError` callbacks. `onSuccess` is called once restoring finishes, even if nothing was restored
21
+ * (e.g. because the persisted client expired), and `onError` if restoring or `onSuccess` throws.
22
+ * @returns The `QueryClientProvider` wrapping the children.
23
+ */
10
24
  export declare const PersistQueryClientProvider: ({ children, persistOptions, onSuccess, onError, ...props }: PersistQueryClientProviderProps) => VNode;
11
25
  //#endregion
12
26
  //# sourceMappingURL=PersistQueryClientProvider.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"PersistQueryClientProvider.d.ts","names":[],"sources":["../../src/PersistQueryClientProvider.tsx"],"mappings":";;;;YAiBY,kCAAkC;EAC5C,gBAAgB,UAAU;EAC1B,kBAAkB;EAClB,gBAAgB;;qBAGL,+BAA8B,UAAA,gBAAA,WAAA,YAAA,SAMxC,oCAAkC"}
1
+ {"version":3,"file":"PersistQueryClientProvider.d.ts","names":[],"sources":["../../src/PersistQueryClientProvider.tsx"],"mappings":";;;;;;;;YAqBY,kCAAkC;EAC5C,gBAAgB,UAAU;EAC1B,kBAAkB;EAClB,gBAAgB;;;;;;;;;;;;qBAaL,+BAA8B,UAAA,gBAAA,WAAA,YAAA,SAMxC,oCAAkC"}
@@ -3,16 +3,26 @@ import { persistQueryClientRestore, persistQueryClientSubscribe } from "@tanstac
3
3
  import { IsRestoringProvider, QueryClientProvider } from "@tanstack/preact-query";
4
4
  import { jsx } from "preact/jsx-runtime";
5
5
  //#region src/PersistQueryClientProvider.tsx
6
+ /**
7
+ * Provides the `QueryClient` like `QueryClientProvider`, and restores the persisted client first:
8
+ * while restoring, `useIsRestoring` returns `true` and queries wait for the restore to finish
9
+ * before subscribing. Once restored, the client is saved with the persister whenever the cache
10
+ * changes.
11
+ * @param props - The `QueryClientProvider` props, the `persistOptions`, and the `onSuccess` and
12
+ * `onError` callbacks. `onSuccess` is called once restoring finishes, even if nothing was restored
13
+ * (e.g. because the persisted client expired), and `onError` if restoring or `onSuccess` throws.
14
+ * @returns The `QueryClientProvider` wrapping the children.
15
+ */
6
16
  const PersistQueryClientProvider = ({ children, persistOptions, onSuccess, onError, ...props }) => {
7
17
  const [isRestoring, setIsRestoring] = useState(true);
8
- const refs = useRef({
18
+ const optionsRef = useRef({
9
19
  persistOptions,
10
20
  onSuccess,
11
21
  onError
12
22
  });
13
- const didRestore = useRef(false);
23
+ const didRestoreRef = useRef(false);
14
24
  useEffect(() => {
15
- refs.current = {
25
+ optionsRef.current = {
16
26
  persistOptions,
17
27
  onSuccess,
18
28
  onError
@@ -20,12 +30,12 @@ const PersistQueryClientProvider = ({ children, persistOptions, onSuccess, onErr
20
30
  });
21
31
  useEffect(() => {
22
32
  const options = {
23
- ...refs.current.persistOptions,
33
+ ...optionsRef.current.persistOptions,
24
34
  queryClient: props.client
25
35
  };
26
- if (!didRestore.current) {
27
- didRestore.current = true;
28
- persistQueryClientRestore(options).then(() => refs.current.onSuccess?.()).catch(() => refs.current.onError?.()).finally(() => {
36
+ if (!didRestoreRef.current) {
37
+ didRestoreRef.current = true;
38
+ persistQueryClientRestore(options).then(() => optionsRef.current.onSuccess?.()).catch(() => optionsRef.current.onError?.()).finally(() => {
29
39
  setIsRestoring(false);
30
40
  });
31
41
  }
@@ -1 +1 @@
1
- {"version":3,"file":"PersistQueryClientProvider.js","names":[],"sources":["../../src/PersistQueryClientProvider.tsx"],"sourcesContent":["import { useEffect, useRef, useState } from 'preact/hooks'\nimport type { VNode } from 'preact'\n\nimport {\n persistQueryClientRestore,\n persistQueryClientSubscribe,\n} from '@tanstack/query-persist-client-core'\nimport {\n IsRestoringProvider,\n QueryClientProvider,\n} from '@tanstack/preact-query'\nimport type { PersistQueryClientOptions } from '@tanstack/query-persist-client-core'\nimport type {\n OmitKeyof,\n QueryClientProviderProps,\n} from '@tanstack/preact-query'\n\nexport type PersistQueryClientProviderProps = QueryClientProviderProps & {\n persistOptions: OmitKeyof<PersistQueryClientOptions, 'queryClient'>\n onSuccess?: () => Promise<unknown> | unknown\n onError?: () => Promise<unknown> | unknown\n}\n\nexport const PersistQueryClientProvider = ({\n children,\n persistOptions,\n onSuccess,\n onError,\n ...props\n}: PersistQueryClientProviderProps): VNode => {\n const [isRestoring, setIsRestoring] = useState(true)\n const refs = useRef({ persistOptions, onSuccess, onError })\n const didRestore = useRef(false)\n\n useEffect(() => {\n refs.current = { persistOptions, onSuccess, onError }\n })\n\n useEffect(() => {\n const options = {\n ...refs.current.persistOptions,\n queryClient: props.client,\n }\n if (!didRestore.current) {\n didRestore.current = true\n persistQueryClientRestore(options)\n .then(() => refs.current.onSuccess?.())\n .catch(() => refs.current.onError?.())\n .finally(() => {\n setIsRestoring(false)\n })\n }\n return isRestoring ? undefined : persistQueryClientSubscribe(options)\n }, [props.client, isRestoring])\n\n return (\n <QueryClientProvider {...props}>\n <IsRestoringProvider value={isRestoring}>{children}</IsRestoringProvider>\n </QueryClientProvider>\n )\n}\n"],"mappings":";;;;;AAuBA,MAAa,8BAA8B,EACzC,UACA,gBACA,WACA,SACA,GAAG,YACyC;CAC5C,MAAM,CAAC,aAAa,kBAAkB,SAAS,IAAI;CACnD,MAAM,OAAO,OAAO;EAAE;EAAgB;EAAW;CAAQ,CAAC;CAC1D,MAAM,aAAa,OAAO,KAAK;CAE/B,gBAAgB;EACd,KAAK,UAAU;GAAE;GAAgB;GAAW;EAAQ;CACtD,CAAC;CAED,gBAAgB;EACd,MAAM,UAAU;GACd,GAAG,KAAK,QAAQ;GAChB,aAAa,MAAM;EACrB;EACA,IAAI,CAAC,WAAW,SAAS;GACvB,WAAW,UAAU;GACrB,0BAA0B,OAAO,CAAC,CAC/B,WAAW,KAAK,QAAQ,YAAY,CAAC,CAAC,CACtC,YAAY,KAAK,QAAQ,UAAU,CAAC,CAAC,CACrC,cAAc;IACb,eAAe,KAAK;GACtB,CAAC;EACL;EACA,OAAO,cAAc,KAAA,IAAY,4BAA4B,OAAO;CACtE,GAAG,CAAC,MAAM,QAAQ,WAAW,CAAC;CAE9B,OACE,oBAAC,qBAAD;EAAqB,GAAI;EACvB,UAAA,oBAAC,qBAAD;GAAqB,OAAO;GAAc;EAA8B,CAAA;CACrD,CAAA;AAEzB"}
1
+ {"version":3,"file":"PersistQueryClientProvider.js","names":[],"sources":["../../src/PersistQueryClientProvider.tsx"],"sourcesContent":["import { useEffect, useRef, useState } from 'preact/hooks'\n\nimport {\n persistQueryClientRestore,\n persistQueryClientSubscribe,\n} from '@tanstack/query-persist-client-core'\nimport {\n IsRestoringProvider,\n QueryClientProvider,\n} from '@tanstack/preact-query'\nimport type { VNode } from 'preact'\nimport type { PersistQueryClientOptions } from '@tanstack/query-persist-client-core'\nimport type {\n OmitKeyof,\n QueryClientProviderProps,\n} from '@tanstack/preact-query'\n\n/**\n * The props of `PersistQueryClientProvider`: the props of `QueryClientProvider`, plus the\n * `persistOptions` and callbacks for when restoring succeeds or fails.\n */\nexport type PersistQueryClientProviderProps = QueryClientProviderProps & {\n persistOptions: OmitKeyof<PersistQueryClientOptions, 'queryClient'>\n onSuccess?: () => Promise<unknown> | unknown\n onError?: () => Promise<unknown> | unknown\n}\n\n/**\n * Provides the `QueryClient` like `QueryClientProvider`, and restores the persisted client first:\n * while restoring, `useIsRestoring` returns `true` and queries wait for the restore to finish\n * before subscribing. Once restored, the client is saved with the persister whenever the cache\n * changes.\n * @param props - The `QueryClientProvider` props, the `persistOptions`, and the `onSuccess` and\n * `onError` callbacks. `onSuccess` is called once restoring finishes, even if nothing was restored\n * (e.g. because the persisted client expired), and `onError` if restoring or `onSuccess` throws.\n * @returns The `QueryClientProvider` wrapping the children.\n */\nexport const PersistQueryClientProvider = ({\n children,\n persistOptions,\n onSuccess,\n onError,\n ...props\n}: PersistQueryClientProviderProps): VNode => {\n const [isRestoring, setIsRestoring] = useState(true)\n const optionsRef = useRef({ persistOptions, onSuccess, onError })\n const didRestoreRef = useRef(false)\n\n useEffect(() => {\n optionsRef.current = { persistOptions, onSuccess, onError }\n })\n\n useEffect(() => {\n const options = {\n ...optionsRef.current.persistOptions,\n queryClient: props.client,\n }\n if (!didRestoreRef.current) {\n didRestoreRef.current = true\n persistQueryClientRestore(options)\n .then(() => optionsRef.current.onSuccess?.())\n .catch(() => optionsRef.current.onError?.())\n .finally(() => {\n setIsRestoring(false)\n })\n }\n return isRestoring ? undefined : persistQueryClientSubscribe(options)\n }, [props.client, isRestoring])\n\n return (\n <QueryClientProvider {...props}>\n <IsRestoringProvider value={isRestoring}>{children}</IsRestoringProvider>\n </QueryClientProvider>\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;AAqCA,MAAa,8BAA8B,EACzC,UACA,gBACA,WACA,SACA,GAAG,YACyC;CAC5C,MAAM,CAAC,aAAa,kBAAkB,SAAS,IAAI;CACnD,MAAM,aAAa,OAAO;EAAE;EAAgB;EAAW;CAAQ,CAAC;CAChE,MAAM,gBAAgB,OAAO,KAAK;CAElC,gBAAgB;EACd,WAAW,UAAU;GAAE;GAAgB;GAAW;EAAQ;CAC5D,CAAC;CAED,gBAAgB;EACd,MAAM,UAAU;GACd,GAAG,WAAW,QAAQ;GACtB,aAAa,MAAM;EACrB;EACA,IAAI,CAAC,cAAc,SAAS;GAC1B,cAAc,UAAU;GACxB,0BAA0B,OAAO,CAAC,CAC/B,WAAW,WAAW,QAAQ,YAAY,CAAC,CAAC,CAC5C,YAAY,WAAW,QAAQ,UAAU,CAAC,CAAC,CAC3C,cAAc;IACb,eAAe,KAAK;GACtB,CAAC;EACL;EACA,OAAO,cAAc,KAAA,IAAY,4BAA4B,OAAO;CACtE,GAAG,CAAC,MAAM,QAAQ,WAAW,CAAC;CAE9B,OACE,oBAAC,qBAAD;EAAqB,GAAI;EACvB,UAAA,oBAAC,qBAAD;GAAqB,OAAO;GAAc;EAA8B,CAAA;CACrD,CAAA;AAEzB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/preact-query-persist-client",
3
- "version": "5.104.0",
3
+ "version": "5.104.2",
4
4
  "description": "Preact bindings to work with persisters in TanStack/preact-query",
5
5
  "author": "tannerlinsley",
6
6
  "license": "MIT",
@@ -39,34 +39,31 @@
39
39
  "!src/__tests__"
40
40
  ],
41
41
  "dependencies": {
42
- "@tanstack/query-persist-client-core": "5.104.0"
42
+ "@tanstack/query-persist-client-core": "5.104.2"
43
43
  },
44
44
  "devDependencies": {
45
45
  "@preact/preset-vite": "^2.10.6",
46
- "@tanstack/preact-query": "5.104.0",
46
+ "@tanstack/preact-query": "5.104.2",
47
47
  "@tanstack/query-test-utils": "0.0.0",
48
48
  "@testing-library/preact": "^3.2.4",
49
- "eslint-config-preact": "^2.0.0",
50
- "npm-run-all2": "^9.0.3",
51
- "preact": "^10.29.8",
52
- "typescript": "6.0.3",
53
- "typescript-eslint": "^8.54.0"
49
+ "preact": "^11.0.1",
50
+ "typescript": "6.0.3"
54
51
  },
55
52
  "peerDependencies": {
56
- "@tanstack/preact-query": "^5.104.0",
57
- "preact": "^10.0.0"
53
+ "@tanstack/preact-query": "^5.104.2",
54
+ "preact": "^10.0.0 || ^11.0.0-0"
58
55
  },
59
56
  "scripts": {
60
57
  "clean": "premove ./build ./coverage ./dist-ts ./.cache/test-types",
61
58
  "compile": "tsc --project tsconfig.json",
62
- "test:eslint": "eslint --concurrency=auto ./src",
59
+ "test:oxlint": "oxlint ./src",
63
60
  "test:types": "npm-run-all --serial test:types:*",
64
- "test:types:ts56": "node ../../node_modules/typescript56/lib/tsc.js --project tsconfig.legacy.json --outDir .cache/test-types/ts56 --tsBuildInfoFile .cache/test-types/ts56.tsbuildinfo",
65
61
  "test:types:ts57": "node ../../node_modules/typescript57/lib/tsc.js --project tsconfig.legacy.json --outDir .cache/test-types/ts57 --tsBuildInfoFile .cache/test-types/ts57.tsbuildinfo",
66
62
  "test:types:ts58": "node ../../node_modules/typescript58/lib/tsc.js --project tsconfig.legacy.json --outDir .cache/test-types/ts58 --tsBuildInfoFile .cache/test-types/ts58.tsbuildinfo",
67
63
  "test:types:ts59": "node ../../node_modules/typescript59/lib/tsc.js --project tsconfig.legacy.json --outDir .cache/test-types/ts59 --tsBuildInfoFile .cache/test-types/ts59.tsbuildinfo",
68
64
  "test:types:tscurrent": "tsc --project tsconfig.json --outDir .cache/test-types/tscurrent --tsBuildInfoFile .cache/test-types/tscurrent.tsbuildinfo",
69
- "test:types:ts70": "node ../../node_modules/typescript70/lib/tsc.js --project tsconfig.json --outDir .cache/test-types/ts70 --tsBuildInfoFile .cache/test-types/ts70.tsbuildinfo",
65
+ "test:types:ts70": "node ../../node_modules/typescript70/lib/tsc.js --project tsconfig.legacy.json --outDir .cache/test-types/ts70 --tsBuildInfoFile .cache/test-types/ts70.tsbuildinfo",
66
+ "test:types:ts71": "node ../../node_modules/typescript71/lib/tsc.js --project tsconfig.legacy.json --outDir .cache/test-types/ts71 --tsBuildInfoFile .cache/test-types/ts71.tsbuildinfo",
70
67
  "test:lib": "vitest --retry=3",
71
68
  "test:lib:dev": "pnpm run test:lib --watch",
72
69
  "test:build": "publint --strict && attw --pack",
@@ -1,5 +1,4 @@
1
1
  import { useEffect, useRef, useState } from 'preact/hooks'
2
- import type { VNode } from 'preact'
3
2
 
4
3
  import {
5
4
  persistQueryClientRestore,
@@ -9,18 +8,33 @@ import {
9
8
  IsRestoringProvider,
10
9
  QueryClientProvider,
11
10
  } from '@tanstack/preact-query'
11
+ import type { VNode } from 'preact'
12
12
  import type { PersistQueryClientOptions } from '@tanstack/query-persist-client-core'
13
13
  import type {
14
14
  OmitKeyof,
15
15
  QueryClientProviderProps,
16
16
  } from '@tanstack/preact-query'
17
17
 
18
+ /**
19
+ * The props of `PersistQueryClientProvider`: the props of `QueryClientProvider`, plus the
20
+ * `persistOptions` and callbacks for when restoring succeeds or fails.
21
+ */
18
22
  export type PersistQueryClientProviderProps = QueryClientProviderProps & {
19
23
  persistOptions: OmitKeyof<PersistQueryClientOptions, 'queryClient'>
20
24
  onSuccess?: () => Promise<unknown> | unknown
21
25
  onError?: () => Promise<unknown> | unknown
22
26
  }
23
27
 
28
+ /**
29
+ * Provides the `QueryClient` like `QueryClientProvider`, and restores the persisted client first:
30
+ * while restoring, `useIsRestoring` returns `true` and queries wait for the restore to finish
31
+ * before subscribing. Once restored, the client is saved with the persister whenever the cache
32
+ * changes.
33
+ * @param props - The `QueryClientProvider` props, the `persistOptions`, and the `onSuccess` and
34
+ * `onError` callbacks. `onSuccess` is called once restoring finishes, even if nothing was restored
35
+ * (e.g. because the persisted client expired), and `onError` if restoring or `onSuccess` throws.
36
+ * @returns The `QueryClientProvider` wrapping the children.
37
+ */
24
38
  export const PersistQueryClientProvider = ({
25
39
  children,
26
40
  persistOptions,
@@ -29,23 +43,23 @@ export const PersistQueryClientProvider = ({
29
43
  ...props
30
44
  }: PersistQueryClientProviderProps): VNode => {
31
45
  const [isRestoring, setIsRestoring] = useState(true)
32
- const refs = useRef({ persistOptions, onSuccess, onError })
33
- const didRestore = useRef(false)
46
+ const optionsRef = useRef({ persistOptions, onSuccess, onError })
47
+ const didRestoreRef = useRef(false)
34
48
 
35
49
  useEffect(() => {
36
- refs.current = { persistOptions, onSuccess, onError }
50
+ optionsRef.current = { persistOptions, onSuccess, onError }
37
51
  })
38
52
 
39
53
  useEffect(() => {
40
54
  const options = {
41
- ...refs.current.persistOptions,
55
+ ...optionsRef.current.persistOptions,
42
56
  queryClient: props.client,
43
57
  }
44
- if (!didRestore.current) {
45
- didRestore.current = true
58
+ if (!didRestoreRef.current) {
59
+ didRestoreRef.current = true
46
60
  persistQueryClientRestore(options)
47
- .then(() => refs.current.onSuccess?.())
48
- .catch(() => refs.current.onError?.())
61
+ .then(() => optionsRef.current.onSuccess?.())
62
+ .catch(() => optionsRef.current.onError?.())
49
63
  .finally(() => {
50
64
  setIsRestoring(false)
51
65
  })