@pgxsinkit/react 0.1.40 → 0.1.46
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/create-hooks.d.ts +6 -1
- package/dist/create-hooks.d.ts.map +1 -1
- package/dist/index.js +372 -7529
- package/dist/index.js.map +1 -129
- package/package.json +3 -3
- package/skills/react/SKILL.md +1 -1
- package/src/create-hooks.tsx +27 -8
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pgxsinkit/react",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.46",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"tanstack-intent"
|
|
6
6
|
],
|
|
@@ -27,8 +27,8 @@
|
|
|
27
27
|
"build": "bun --cwd ../.. run build:public-packages"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@pgxsinkit/client": "0.1.
|
|
31
|
-
"@pgxsinkit/contracts": "0.1.
|
|
30
|
+
"@pgxsinkit/client": "0.1.46",
|
|
31
|
+
"@pgxsinkit/contracts": "0.1.46"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|
|
34
34
|
"@electric-sql/pglite": "0.5.4",
|
package/skills/react/SKILL.md
CHANGED
package/src/create-hooks.tsx
CHANGED
|
@@ -18,7 +18,12 @@ interface DrizzleSqlBuilder<TRows extends readonly unknown[]> extends PromiseLik
|
|
|
18
18
|
readonly _?: { readonly selectedFields?: SelectedFields };
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
/**
|
|
21
|
+
/**
|
|
22
|
+
* Reactive read result. `hydrating` is true from mount until every lazy relation the query reads has
|
|
23
|
+
* completed its initial catch-up (`client.groupReady`) — not merely started its stream. Rows flow while
|
|
24
|
+
* it is true (local/cached rows paint immediately; catch-up rows stream in), so render an empty state
|
|
25
|
+
* only when `!loading && !hydrating` — zero rows before that means "not loaded yet", not "empty".
|
|
26
|
+
*/
|
|
22
27
|
interface LiveRowsState<TRows> {
|
|
23
28
|
rows: TRows;
|
|
24
29
|
loading: boolean;
|
|
@@ -228,22 +233,26 @@ export function createSyncClientHooks<TRegistry extends SyncTableRegistry>() {
|
|
|
228
233
|
|
|
229
234
|
setState((prev) => ({ rows: prev.rows, loading: true, hydrating: true, error: null }));
|
|
230
235
|
|
|
231
|
-
// Scan the compiled SQL for the lazy relations the query reads (∪ `use`),
|
|
232
|
-
// THEN subscribe via the client's live-rows seam — so a query is never
|
|
233
|
-
//
|
|
234
|
-
// `pglite.live`) and the worker-attached client (seam over the bridge, ADR-0032 S2 §4).
|
|
236
|
+
// Scan the compiled SQL for the lazy relations the query reads (∪ `use`), ACTIVATE them (streams
|
|
237
|
+
// started, tripwire satisfied), THEN subscribe via the client's live-rows seam — so a query is never
|
|
238
|
+
// registered against a dormant lazy relation (ADR-0021), and the same hook drives both the in-process
|
|
239
|
+
// client (seam over `pglite.live`) and the worker-attached client (seam over the bridge, ADR-0032 S2 §4).
|
|
240
|
+
// Activation is NOT catch-up: the subscription registers immediately (local/cached rows paint, and an
|
|
241
|
+
// offline client is never blocked behind the network), while `hydrating` stays true until the
|
|
242
|
+
// subscription's `hydrated` promise resolves. The seam guarantees rows-before-signal (it refreshes the
|
|
243
|
+
// live query against the caught-up store before resolving), so clearing `hydrating` here can never
|
|
244
|
+
// present zero rows as "empty" while the catch-up rows are still in flight.
|
|
235
245
|
void contextClient
|
|
236
246
|
.prepareQuery({ sql: sql.sql, ...(useList ? { use: useList } : {}) })
|
|
237
247
|
.then(() => {
|
|
238
248
|
if (!active) return undefined;
|
|
239
|
-
setState((prev) => ({ rows: prev.rows, loading: true, hydrating: false, error: null }));
|
|
240
249
|
return contextClient
|
|
241
250
|
.subscribeLiveRows<Record<string, unknown>>(
|
|
242
251
|
{ sql: sql.sql, params: sql.params, ...(fields ? { fields } : {}), ...(useList ? { use: useList } : {}) },
|
|
243
252
|
(rows) => {
|
|
244
253
|
if (active) {
|
|
245
254
|
syncDebug("live query updated → re-render", { rows: rows.length });
|
|
246
|
-
setState({ rows: mapRows(rows), loading: false, hydrating:
|
|
255
|
+
setState((prev) => ({ rows: mapRows(rows), loading: false, hydrating: prev.hydrating, error: null }));
|
|
247
256
|
}
|
|
248
257
|
},
|
|
249
258
|
)
|
|
@@ -253,7 +262,17 @@ export function createSyncClientHooks<TRegistry extends SyncTableRegistry>() {
|
|
|
253
262
|
return undefined;
|
|
254
263
|
}
|
|
255
264
|
subscription = registered;
|
|
256
|
-
setState(
|
|
265
|
+
setState((prev) => ({
|
|
266
|
+
rows: mapRows(registered.initialRows),
|
|
267
|
+
loading: false,
|
|
268
|
+
hydrating: registered.hydrated != null ? prev.hydrating : false,
|
|
269
|
+
error: null,
|
|
270
|
+
}));
|
|
271
|
+
if (registered.hydrated) {
|
|
272
|
+
void registered.hydrated.then(() => {
|
|
273
|
+
if (active) setState((prev) => ({ ...prev, hydrating: false }));
|
|
274
|
+
});
|
|
275
|
+
}
|
|
257
276
|
return undefined;
|
|
258
277
|
});
|
|
259
278
|
})
|