@toapi/react 1.2.2 → 1.2.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.
@@ -1 +1 @@
1
- {"version":3,"file":"use-query.d.ts","sourceRoot":"","sources":["../src/use-query.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,KAAK,iBAAiB,CAAC,CAAC,IAAI,OAAO,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC;AAEvD,UAAU,OAAO;IACf,eAAe,CAAC,EAAE,OAAO,KAAK,CAAC,eAAe,CAAC;CAChD;AAID,wBAAgB,QAAQ,CAAC,CAAC,EACxB,KAAK,EAAE,iBAAiB,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,iBAAiB,CAAC,CAAC,CAAC,CAAC,EAC1D,EAAE,eAAuC,EAAE,GAAE,OAAY,KAkB1D"}
1
+ {"version":3,"file":"use-query.d.ts","sourceRoot":"","sources":["../src/use-query.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,KAAK,iBAAiB,CAAC,CAAC,IAAI,OAAO,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC;AAEvD,UAAU,OAAO;IACf,eAAe,CAAC,EAAE,OAAO,KAAK,CAAC,eAAe,CAAC;CAChD;AAED,wBAAgB,QAAQ,CAAC,CAAC,EACxB,KAAK,EAAE,iBAAiB,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,iBAAiB,CAAC,CAAC,CAAC,CAAC,EAC1D,EAAE,eAAuC,EAAE,GAAE,OAAY,KAkC1D"}
package/dist/use-query.js CHANGED
@@ -1,15 +1,28 @@
1
1
  import * as React from "react";
2
- const noValue = Symbol("ReactTApi:noValue");
3
2
  export function useQuery(query, { startTransition = React.startTransition } = {}) {
4
3
  const observable = React.useMemo(typeof query === "function" ? query : () => query, [query]);
5
- const [data, setData] = React.useState(noValue);
4
+ // The value is kept together with the observable it was loaded for.
5
+ // Revalidation pushes a new promise for the *same* query, so the stored
6
+ // value stays valid; a different query invalidates it and we fall back to
7
+ // `use`, which suspends instead of rendering the previous query's data.
8
+ const [state, setState] = React.useState(null);
6
9
  React.useEffect(() => {
10
+ let active = true;
7
11
  const unsubscribe = observable.subscribe((next) => {
8
12
  startTransition(async () => {
9
- setData(await next);
13
+ const value = await next;
14
+ // A late update from a subscription we have already left behind must
15
+ // not overwrite the current one.
16
+ if (active)
17
+ setState({ source: observable, value });
10
18
  });
11
19
  });
12
- return unsubscribe;
20
+ return () => {
21
+ active = false;
22
+ unsubscribe();
23
+ };
13
24
  }, [observable]);
14
- return data === noValue ? React.use(observable) : data;
25
+ return state !== null && state.source === observable
26
+ ? state.value
27
+ : React.use(observable);
15
28
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@toapi/react",
3
- "version": "1.2.2",
3
+ "version": "1.2.3",
4
4
  "author": {
5
5
  "name": "Michel Smola",
6
6
  "email": "michel.smola@farbenmeer.de"
@@ -18,7 +18,7 @@
18
18
  "dist"
19
19
  ],
20
20
  "dependencies": {
21
- "@toapi/common": "^1.2.2"
21
+ "@toapi/common": "^1.2.3"
22
22
  },
23
23
  "devDependencies": {
24
24
  "@happy-dom/global-registrator": "^20.0.0",
@@ -30,8 +30,8 @@
30
30
  "react": "^19.1.1",
31
31
  "vitest": "^4.0.16",
32
32
  "zod": "^4.1.5",
33
- "@toapi/client": "^1.2.2",
34
- "@toapi/server": "^1.2.2"
33
+ "@toapi/client": "^1.2.3",
34
+ "@toapi/server": "^1.2.3"
35
35
  },
36
36
  "peerDependencies": {
37
37
  "react": "^19.1.1",