@umituz/react-native-subscription 2.37.30 → 2.37.31

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umituz/react-native-subscription",
3
- "version": "2.37.30",
3
+ "version": "2.37.31",
4
4
  "description": "Complete subscription management with RevenueCat, paywall UI, and credits system for React Native apps",
5
5
  "main": "./src/index.ts",
6
6
  "types": "./src/index.ts",
@@ -17,6 +17,11 @@ export function useFeatureGate(params: UseFeatureGateParams): UseFeatureGateResu
17
17
 
18
18
  const pendingActionRef = useRef<(() => void | Promise<void>) | null>(null);
19
19
  const prevCreditBalanceRef = useRef(creditBalance);
20
+ // Separate ref to track previous subscription state for canExecutePurchaseAction.
21
+ // NOTE: Must NOT use hasSubscriptionRef from useSyncedRefs here because useSyncedRefs
22
+ // effects run BEFORE this effect (React runs effects in definition order), so
23
+ // hasSubscriptionRef.current would already be the NEW value when we check it.
24
+ const prevHasSubscriptionRef = useRef(hasSubscription);
20
25
  const isWaitingForPurchaseRef = useRef(false);
21
26
  const isWaitingForAuthCreditsRef = useRef(false);
22
27
 
@@ -50,13 +55,14 @@ export function useFeatureGate(params: UseFeatureGateParams): UseFeatureGateResu
50
55
  }, [isCreditsLoaded, creditBalance, hasSubscription, requiredCredits, onShowPaywallRef, requiredCreditsRef]);
51
56
 
52
57
  useEffect(() => {
53
-
58
+ // Use prevHasSubscriptionRef (updated AFTER check) not hasSubscriptionRef from useSyncedRefs
59
+ // (which is already updated to new value before this effect runs - race condition fix)
54
60
  const shouldExecute = canExecutePurchaseAction(
55
61
  isWaitingForPurchaseRef.current,
56
62
  creditBalance,
57
63
  prevCreditBalanceRef.current ?? 0,
58
64
  hasSubscription,
59
- hasSubscriptionRef.current,
65
+ prevHasSubscriptionRef.current,
60
66
  !!pendingActionRef.current
61
67
  );
62
68
 
@@ -67,9 +73,10 @@ export function useFeatureGate(params: UseFeatureGateParams): UseFeatureGateResu
67
73
  action();
68
74
  }
69
75
 
76
+ // Update AFTER check so next render has correct "prev" values
70
77
  prevCreditBalanceRef.current = creditBalance;
71
- // hasSubscriptionRef is already synced by useSyncedRefs, no need to update manually
72
- // eslint-disable-next-line react-hooks/exhaustive-deps
78
+ prevHasSubscriptionRef.current = hasSubscription;
79
+
73
80
  }, [creditBalance, hasSubscription]);
74
81
 
75
82
  const requireFeature = useCallback(