@mohasinac/appkit 4.4.2 → 4.4.3

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.
@@ -91,7 +91,22 @@ export function useSyncManager(userId) {
91
91
  };
92
92
  // Sync once immediately on login so the server is updated right away
93
93
  sync();
94
+ // Mobile browsers throttle/suspend JS timers in a backgrounded tab, so
95
+ // the 30s interval alone can strand pending ops indefinitely if the user
96
+ // backgrounds the app (switches apps, locks the screen) before it next
97
+ // fires — the classic "added on mobile, desktop never sees it" report.
98
+ // Flush immediately whenever the tab is about to go away or hide.
99
+ const flushOnHide = () => {
100
+ if (document.visibilityState === "hidden")
101
+ void sync();
102
+ };
103
+ document.addEventListener("visibilitychange", flushOnHide);
104
+ window.addEventListener("pagehide", flushOnHide);
94
105
  const id = setInterval(sync, SYNC_INTERVAL_MS);
95
- return () => clearInterval(id);
106
+ return () => {
107
+ clearInterval(id);
108
+ document.removeEventListener("visibilitychange", flushOnHide);
109
+ window.removeEventListener("pagehide", flushOnHide);
110
+ };
96
111
  }, [userId, queryClient]);
97
112
  }
@@ -18,6 +18,9 @@ export function useCartCount(enabled = false) {
18
18
  queryKey: ["cart"],
19
19
  queryFn: () => apiClient.get(CART_ENDPOINTS.GET),
20
20
  enabled,
21
+ // See useCartQuery — cart is cross-device-synced, so an already-open tab
22
+ // must refetch on refocus instead of showing a pre-sync cached count.
23
+ refetchOnWindowFocus: true,
21
24
  });
22
25
  // "Add to cart" quick actions (listing grid, product cards) write local-
23
26
  // first — see useSyncManager — and queue an unsynced op that only reaches
@@ -6,5 +6,11 @@ export function useCartQuery(options) {
6
6
  queryFn: () => apiClient.get(options.endpoint),
7
7
  enabled: options.enabled,
8
8
  initialData: options.initialData,
9
+ // Override the app-wide refetchOnWindowFocus:false default — the cart is
10
+ // explicitly meant to be cross-device-synced (mobile add -> desktop
11
+ // sees it), so an already-open desktop tab must refetch when refocused
12
+ // rather than keep showing whatever it had cached before the mobile
13
+ // sync landed on the server.
14
+ refetchOnWindowFocus: true,
9
15
  });
10
16
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mohasinac/appkit",
3
- "version": "4.4.2",
3
+ "version": "4.4.3",
4
4
  "license": "MIT",
5
5
  "publishConfig": {
6
6
  "access": "public"