@fluxbase/sdk-react 2026.1.22 → 2026.2.1

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
@@ -56,7 +56,7 @@ function useSignIn() {
56
56
  },
57
57
  onSuccess: (session) => {
58
58
  queryClient.setQueryData(["fluxbase", "auth", "session"], session);
59
- if ("user" in session) {
59
+ if (session && "user" in session && session.user) {
60
60
  queryClient.setQueryData(["fluxbase", "auth", "user"], session.user);
61
61
  }
62
62
  }
@@ -427,7 +427,12 @@ function useGraphQL() {
427
427
  import { useQuery as useQuery6, useMutation as useMutation4, useQueryClient as useQueryClient4 } from "@tanstack/react-query";
428
428
  function useFluxbaseQuery(buildQuery, options) {
429
429
  const client = useFluxbaseClient();
430
- const queryKey = options?.queryKey || ["fluxbase", "query", buildQuery.toString()];
430
+ if (!options?.queryKey) {
431
+ console.warn(
432
+ "[useFluxbaseQuery] No queryKey provided. This may cause cache misses. Please provide a stable queryKey in options."
433
+ );
434
+ }
435
+ const queryKey = options?.queryKey || ["fluxbase", "query", "unstable"];
431
436
  return useQuery6({
432
437
  queryKey,
433
438
  queryFn: async () => {
@@ -443,6 +448,11 @@ function useFluxbaseQuery(buildQuery, options) {
443
448
  }
444
449
  function useTable(table, buildQuery, options) {
445
450
  const client = useFluxbaseClient();
451
+ if (buildQuery && !options?.queryKey) {
452
+ console.warn(
453
+ `[useTable] Using buildQuery without a custom queryKey for table "${table}". This may cause cache misses. Provide a queryKey that includes your filter values.`
454
+ );
455
+ }
446
456
  return useFluxbaseQuery(
447
457
  (client2) => {
448
458
  const query = client2.from(table);
@@ -450,7 +460,8 @@ function useTable(table, buildQuery, options) {
450
460
  },
451
461
  {
452
462
  ...options,
453
- queryKey: options?.queryKey || ["fluxbase", "table", table, buildQuery?.toString()]
463
+ // Use table name as base key, or custom key if provided
464
+ queryKey: options?.queryKey || ["fluxbase", "table", table]
454
465
  }
455
466
  );
456
467
  }
@@ -541,6 +552,12 @@ function useRealtime(options) {
541
552
  invalidateKey,
542
553
  enabled = true
543
554
  } = options;
555
+ const callbackRef = useRef2(callback);
556
+ const invalidateKeyRef = useRef2(invalidateKey);
557
+ const autoInvalidateRef = useRef2(autoInvalidate);
558
+ callbackRef.current = callback;
559
+ invalidateKeyRef.current = invalidateKey;
560
+ autoInvalidateRef.current = autoInvalidate;
544
561
  useEffect2(() => {
545
562
  if (!enabled) {
546
563
  return;
@@ -548,12 +565,12 @@ function useRealtime(options) {
548
565
  const channel = client.realtime.channel(channelName);
549
566
  channelRef.current = channel;
550
567
  const handleChange = (payload) => {
551
- if (callback) {
552
- callback(payload);
568
+ if (callbackRef.current) {
569
+ callbackRef.current(payload);
553
570
  }
554
- if (autoInvalidate) {
571
+ if (autoInvalidateRef.current) {
555
572
  const tableName = channelName.replace(/^table:/, "");
556
- const key = invalidateKey || ["fluxbase", "table", tableName];
573
+ const key = invalidateKeyRef.current || ["fluxbase", "table", tableName];
557
574
  queryClient.invalidateQueries({ queryKey: key });
558
575
  }
559
576
  };
@@ -562,16 +579,7 @@ function useRealtime(options) {
562
579
  channel.unsubscribe();
563
580
  channelRef.current = null;
564
581
  };
565
- }, [
566
- client,
567
- channelName,
568
- event,
569
- callback,
570
- autoInvalidate,
571
- invalidateKey,
572
- queryClient,
573
- enabled
574
- ]);
582
+ }, [client, channelName, event, queryClient, enabled]);
575
583
  return {
576
584
  channel: channelRef.current
577
585
  };
@@ -752,8 +760,10 @@ function useStorageSignedUrl(bucket, path, expiresIn) {
752
760
  return data?.signedUrl || null;
753
761
  },
754
762
  enabled: !!path,
755
- staleTime: expiresIn ? expiresIn * 1e3 - 6e4 : 1e3 * 60 * 50
756
- // Refresh 1 minute before expiry
763
+ // Refresh 1 minute before expiry, but ensure staleTime is never negative
764
+ // For very short expirations (<60s), use half the expiration time
765
+ staleTime: expiresIn ? Math.max(expiresIn * 500, expiresIn * 1e3 - 6e4) : 1e3 * 60 * 50
766
+ // 50 minutes default
757
767
  });
758
768
  }
759
769
  function useStorageSignedUrlWithOptions(bucket, path, options) {
@@ -781,8 +791,10 @@ function useStorageSignedUrlWithOptions(bucket, path, options) {
781
791
  return data?.signedUrl || null;
782
792
  },
783
793
  enabled: !!path,
784
- staleTime: expiresIn ? expiresIn * 1e3 - 6e4 : 1e3 * 60 * 50
785
- // Refresh 1 minute before expiry
794
+ // Refresh 1 minute before expiry, but ensure staleTime is never negative
795
+ // For very short expirations (<60s), use half the expiration time
796
+ staleTime: expiresIn ? Math.max(expiresIn * 500, expiresIn * 1e3 - 6e4) : 1e3 * 60 * 50
797
+ // 50 minutes default
786
798
  });
787
799
  }
788
800
  function useStorageMove(bucket) {