@pylonsync/react 0.3.177 → 0.3.179

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.
Files changed (2) hide show
  1. package/package.json +3 -3
  2. package/src/db.ts +19 -2
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "0.3.177",
6
+ "version": "0.3.179",
7
7
  "type": "module",
8
8
  "main": "src/index.ts",
9
9
  "types": "src/index.ts",
@@ -12,8 +12,8 @@
12
12
  "check": "tsc -p tsconfig.json --noEmit"
13
13
  },
14
14
  "dependencies": {
15
- "@pylonsync/sdk": "0.3.177",
16
- "@pylonsync/sync": "0.3.177"
15
+ "@pylonsync/sdk": "0.3.179",
16
+ "@pylonsync/sync": "0.3.179"
17
17
  },
18
18
  "peerDependencies": {
19
19
  "react": ">=19.0.0"
package/src/db.ts CHANGED
@@ -57,8 +57,20 @@ export function init(config?: Partial<SyncEngineConfig> & { baseUrl?: string })
57
57
  _started = false;
58
58
  // Keep the React-side helpers in sync — a single init() should fully
59
59
  // namespace this app's storage without a separate configureClient call.
60
+ // Match createSyncEngine's resolution: when init({ appName }) omits
61
+ // baseUrl, fall back to window.location.origin so callFn / fetchList /
62
+ // session helpers go through the same dev-server proxy as the sync
63
+ // engine. Otherwise callFn hits the hard-coded http://localhost:4321
64
+ // default and trips CORS preflights in any Vite/Next setup where the
65
+ // page origin doesn't equal the API origin.
66
+ const resolvedBaseUrl =
67
+ config?.baseUrl && config.baseUrl.length > 0
68
+ ? config.baseUrl
69
+ : typeof window !== "undefined" && window.location?.origin
70
+ ? window.location.origin
71
+ : undefined;
60
72
  configureClient({
61
- baseUrl: config?.baseUrl,
73
+ baseUrl: resolvedBaseUrl,
62
74
  appName: config?.appName,
63
75
  });
64
76
  }
@@ -248,12 +260,17 @@ export const db = {
248
260
  /**
249
261
  * Call a server-side function (query, mutation, or action).
250
262
  *
263
+ * Routes through `SyncEngine.fn` (not the free `callFn`) so the response's
264
+ * `X-Pylon-Change-Seq` header triggers a fallback pull when the WS
265
+ * broadcast for the same event hasn't landed yet — closes the gap where
266
+ * a mutation succeeds but the cached query doesn't observe the new row.
267
+ *
251
268
  * ```ts
252
269
  * const result = await db.fn("placeBid", { lotId: "x", amount: 150 });
253
270
  * ```
254
271
  */
255
272
  fn<T = unknown>(name: string, args?: Record<string, unknown>): Promise<T> {
256
- return callFn<T>(name, args);
273
+ return getSync().fn<T>(name, args);
257
274
  },
258
275
 
259
276
  /**