@lunora/react 1.0.0-alpha.14 → 1.0.0-alpha.16

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/dist/index.mjs CHANGED
@@ -2,18 +2,18 @@
2
2
  export { AuthLoading, Authenticated, Unauthenticated } from './packem_shared/AuthLoading-DtKgZT2Z.mjs';
3
3
  export { useAuthState } from './packem_shared/useAuthState-BiGhtSCs.mjs';
4
4
  export { LunoraProvider, useLunora } from './packem_shared/LunoraProvider-D38Xp16l.mjs';
5
- export { CheckoutButton, CustomerPortalButton, useCheckout } from './packem_shared/CheckoutButton-CVSry8U1.mjs';
5
+ export { CheckoutButton, CustomerPortalButton, useCheckout } from './packem_shared/CheckoutButton-DUite8jJ.mjs';
6
6
  export { lunoraQueryOptions } from './packem_shared/lunoraQueryOptions-C3uwOTMW.mjs';
7
7
  export { default as useAuth } from './packem_shared/useAuth-CNUKtOOp.mjs';
8
8
  export { default as useConnectionStatus } from './packem_shared/useConnectionStatus-DRSY9ldm.mjs';
9
9
  export { useFlag, useFlags } from './packem_shared/useFlag-B5NFNmRD.mjs';
10
- export { default as useInfiniteQuery } from './packem_shared/useInfiniteQuery-Ck5HRuLQ.mjs';
10
+ export { default as useInfiniteQuery } from './packem_shared/useInfiniteQuery-DTYi5Rvm.mjs';
11
11
  export { useMutation } from './packem_shared/useMutation-CrvMXRsk.mjs';
12
12
  export { useMutator } from './packem_shared/useMutator-IIrLtDiM.mjs';
13
- export { usePaginatedQuery } from './packem_shared/usePaginatedQuery-UAE4P3Bd.mjs';
14
- export { hydratePreloaded, default as usePreloadedQuery } from './packem_shared/hydratePreloaded-Bwu06QLX.mjs';
13
+ export { usePaginatedQuery } from './packem_shared/usePaginatedQuery-CQeffZuZ.mjs';
14
+ export { hydratePreloaded, default as usePreloadedQuery } from './packem_shared/hydratePreloaded-cgaz74Yz.mjs';
15
15
  export { usePresence } from './packem_shared/usePresence-D7jLuxj0.mjs';
16
- export { default as useQuery } from './packem_shared/useQuery-ByRfO1D3.mjs';
16
+ export { default as useQuery } from './packem_shared/useQuery-gLcqxzly.mjs';
17
17
  export { useRateLimit } from './packem_shared/useRateLimit-DTEffQEi.mjs';
18
18
  export { useStream } from './packem_shared/useStream-BqZeZE3w.mjs';
19
19
  export { default as useSubscription } from './packem_shared/useSubscription-i78qwMed.mjs';
@@ -3,6 +3,13 @@ import { c } from 'react/compiler-runtime';
3
3
  import { useState, useCallback } from 'react';
4
4
  import { jsxDEV } from 'react/jsx-dev-runtime';
5
5
 
6
+ const safeRedirectHref = (url) => {
7
+ const parsed = new URL(url, globalThis.location.href);
8
+ if (parsed.protocol !== "https:" && parsed.protocol !== "http:") {
9
+ throw new Error(`refusing to redirect to a non-http(s) URL: ${parsed.protocol}`);
10
+ }
11
+ return parsed.href;
12
+ };
6
13
  const useCheckout = (trigger) => {
7
14
  const [pending, setPending] = useState(false);
8
15
  const [error, setError] = useState(void 0);
@@ -11,10 +18,7 @@ const useCheckout = (trigger) => {
11
18
  setError(void 0);
12
19
  try {
13
20
  const target = await trigger();
14
- const {
15
- url
16
- } = target;
17
- globalThis.location.assign(url);
21
+ globalThis.location.assign(safeRedirectHref(target.url));
18
22
  } catch (error_) {
19
23
  const normalized = error_ instanceof Error ? error_ : new Error(String(error_));
20
24
  setError(normalized);
@@ -1,11 +1,13 @@
1
1
  'use client';
2
+ import { c } from 'react/compiler-runtime';
2
3
  import { useQueryClient, useQuery } from '@tanstack/react-query';
3
- import { useMemo, useEffect } from 'react';
4
+ import { useEffect } from 'react';
4
5
  import { g as getSubscriptionRegistry } from './cache-BFlsXmup.mjs';
5
6
  import { useLunora } from './LunoraProvider-D38Xp16l.mjs';
6
- import { l as lunoraQueryKey, s as serializeQueryKey } from './query-key-BmCbgidV.mjs';
7
+ import { s as serializeQueryKey, l as lunoraQueryKey } from './query-key-BmCbgidV.mjs';
7
8
 
8
9
  const usePreloadedQuery = function(preloaded) {
10
+ const $ = c(4);
9
11
  const client = useLunora();
10
12
  const queryClient = useQueryClient();
11
13
  const {
@@ -14,18 +16,13 @@ const usePreloadedQuery = function(preloaded) {
14
16
  shardKey,
15
17
  value
16
18
  } = preloaded;
17
- const functionRef = useMemo(() => {
18
- return {
19
- __lunoraRef: functionPath
20
- };
21
- }, [functionPath]);
22
- const queryKey = useMemo(() => lunoraQueryKey(functionRef, args, shardKey), [functionRef.__lunoraRef, JSON.stringify(args), shardKey]);
19
+ const functionRef = {
20
+ __lunoraRef: functionPath
21
+ };
22
+ const queryKey = lunoraQueryKey(functionRef, args, shardKey);
23
23
  const {
24
24
  data
25
25
  } = useQuery({
26
- // Seed the cache with the server value so the first paint doesn't
27
- // re-fetch. TanStack treats `initialData` as fresh — the WS push from
28
- // the registry is what supplies subsequent updates.
29
26
  initialData: value,
30
27
  queryFn: () => client.query(functionRef, args, {
31
28
  shardKey
@@ -33,10 +30,21 @@ const usePreloadedQuery = function(preloaded) {
33
30
  queryKey,
34
31
  staleTime: Number.POSITIVE_INFINITY
35
32
  });
33
+ const t0 = serializeQueryKey(queryKey);
34
+ let t1;
35
+ if ($[0] !== client || $[1] !== queryClient || $[2] !== t0) {
36
+ t1 = [client, queryClient, t0];
37
+ $[0] = client;
38
+ $[1] = queryClient;
39
+ $[2] = t0;
40
+ $[3] = t1;
41
+ } else {
42
+ t1 = $[3];
43
+ }
36
44
  useEffect(() => {
37
45
  const registry = getSubscriptionRegistry(client);
38
46
  return registry.attach(queryClient, queryKey, functionRef, args, shardKey);
39
- }, [client, queryClient, serializeQueryKey(queryKey)]);
47
+ }, t1);
40
48
  return data ?? value;
41
49
  };
42
50
  const hydratePreloaded = function(preloaded) {
@@ -108,12 +108,16 @@ const usePaginatedCore = function(function_, args, options) {
108
108
  detaches.set(hash_0, registry.attach(queryClient, entry.key, desired.fn, entry.args, desired.shardKey));
109
109
  }
110
110
  }, [client, queryClient, pageKeysHash, skipped]);
111
- useEffect(() => () => {
112
- for (const detach_2 of detachesRef.current.values()) {
113
- detach_2();
114
- }
115
- detachesRef.current.clear();
116
- }, []);
111
+ useEffect(
112
+ () => () => {
113
+ for (const detach_2 of detachesRef.current.values()) {
114
+ detach_2();
115
+ }
116
+ detachesRef.current.clear();
117
+ },
118
+ // react-doctor-disable-next-line react-doctor/exhaustive-deps -- intentional: unmount-only cleanup. `detachesRef` is a stable ref, so the empty dep array is correct — the teardown must run once on unmount, not every render.
119
+ []
120
+ );
117
121
  useEffect(() => {
118
122
  const cache = queryClient.getQueryCache();
119
123
  const unsubscribe = cache.subscribe((event) => {
@@ -1,7 +1,7 @@
1
1
  'use client';
2
2
  import { c } from 'react/compiler-runtime';
3
3
  import { useRef, useEffect } from 'react';
4
- import { u as usePaginatedCore } from './use-paginated-core-COGbvB0R.mjs';
4
+ import { u as usePaginatedCore } from './use-paginated-core-DTh_UVIg.mjs';
5
5
 
6
6
  const useInfiniteQuery = (function_, args, options) => {
7
7
  const $ = c(15);
@@ -1,6 +1,6 @@
1
1
  'use client';
2
2
  import { c } from 'react/compiler-runtime';
3
- import { u as usePaginatedCore } from './use-paginated-core-COGbvB0R.mjs';
3
+ import { u as usePaginatedCore } from './use-paginated-core-DTh_UVIg.mjs';
4
4
 
5
5
  const usePaginatedQuery = (function_, args, options) => {
6
6
  const $ = c(7);
@@ -1,12 +1,14 @@
1
1
  'use client';
2
+ import { c } from 'react/compiler-runtime';
2
3
  import { useQueryClient, useQuery as useQuery$1 } from '@tanstack/react-query';
3
- import { useMemo, useEffect } from 'react';
4
+ import { useEffect } from 'react';
4
5
  import { g as getSubscriptionRegistry } from './cache-BFlsXmup.mjs';
5
6
  import { useLunora } from './LunoraProvider-D38Xp16l.mjs';
6
- import { l as lunoraQueryKey, s as serializeQueryKey } from './query-key-BmCbgidV.mjs';
7
- import { s as stableStringify } from './stable-key-CGp4e2Ux.mjs';
7
+ import { s as serializeQueryKey, l as lunoraQueryKey } from './query-key-BmCbgidV.mjs';
8
8
 
9
- const useQuery = (function_, args, options = {}) => {
9
+ const useQuery = (function_, args, t0) => {
10
+ const $ = c(5);
11
+ const options = t0 === void 0 ? {} : t0;
10
12
  const client = useLunora();
11
13
  const queryClient = useQueryClient();
12
14
  const {
@@ -14,7 +16,7 @@ const useQuery = (function_, args, options = {}) => {
14
16
  } = options;
15
17
  const skipped = args === "skip";
16
18
  const argsRecord = skipped ? {} : args;
17
- const queryKey = useMemo(() => lunoraQueryKey(function_, argsRecord, shardKey), [function_.__lunoraRef, stableStringify(argsRecord), shardKey]);
19
+ const queryKey = lunoraQueryKey(function_, argsRecord, shardKey);
18
20
  const {
19
21
  data
20
22
  } = useQuery$1({
@@ -23,20 +25,30 @@ const useQuery = (function_, args, options = {}) => {
23
25
  shardKey
24
26
  }),
25
27
  queryKey,
26
- // Lunora is push-driven: once the initial fetch resolves, the WS owns
27
- // freshness. Staleness only matters when the subscription is missing,
28
- // and the registry handles that with a polling fallback.
29
28
  staleTime: Number.POSITIVE_INFINITY
30
29
  });
30
+ const t1 = serializeQueryKey(queryKey);
31
+ let t2;
32
+ if ($[0] !== client || $[1] !== queryClient || $[2] !== skipped || $[3] !== t1) {
33
+ t2 = [client, queryClient, t1, skipped];
34
+ $[0] = client;
35
+ $[1] = queryClient;
36
+ $[2] = skipped;
37
+ $[3] = t1;
38
+ $[4] = t2;
39
+ } else {
40
+ t2 = $[4];
41
+ }
31
42
  useEffect(() => {
32
43
  if (skipped) {
33
- return () => {
34
- };
44
+ return _temp;
35
45
  }
36
46
  const registry = getSubscriptionRegistry(client);
37
47
  return registry.attach(queryClient, queryKey, function_, argsRecord, shardKey);
38
- }, [client, queryClient, serializeQueryKey(queryKey), skipped]);
48
+ }, t2);
39
49
  return data;
40
50
  };
51
+ function _temp() {
52
+ }
41
53
 
42
54
  export { useQuery as default };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lunora/react",
3
- "version": "1.0.0-alpha.14",
3
+ "version": "1.0.0-alpha.16",
4
4
  "description": "React hooks for Lunora: useQuery, useMutation, useSubscription, and useAuth",
5
5
  "keywords": [
6
6
  "cloudflare",
@@ -49,7 +49,7 @@
49
49
  "access": "public"
50
50
  },
51
51
  "dependencies": {
52
- "@lunora/client": "1.0.0-alpha.12",
52
+ "@lunora/client": "1.0.0-alpha.14",
53
53
  "@lunora/ratelimit": "1.0.0-alpha.3"
54
54
  },
55
55
  "peerDependencies": {