@dxos/react-client 0.8.1-staging.5be625a → 0.8.1-staging.97aedb1

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":"useQueue.d.ts","sourceRoot":"","sources":["../../../../src/echo/useQueue.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAE/C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,EAAE,KAAK,GAAG,EAAE,MAAM,YAAY,CAAC;AAMtC,MAAM,MAAM,eAAe,GAAG;IAC5B,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF;;GAEG;AAIH,eAAO,MAAM,QAAQ,GAAI,CAAC,SAAS,cAAc,aACpC,GAAG,YACL,eAAe,KACvB,KAAK,CAAC,CAAC,CAAC,GAAG,SAgCb,CAAC"}
1
+ {"version":3,"file":"useQueue.d.ts","sourceRoot":"","sources":["../../../../src/echo/useQueue.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAE/C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,EAAE,KAAK,GAAG,EAAE,MAAM,YAAY,CAAC;AAMtC,MAAM,MAAM,eAAe,GAAG;IAC5B,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF;;GAEG;AAKH,eAAO,MAAM,QAAQ,GAAI,CAAC,SAAS,cAAc,aACpC,GAAG,YACL,eAAe,KACvB,KAAK,CAAC,CAAC,CAAC,GAAG,SA2Cb,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dxos/react-client",
3
- "version": "0.8.1-staging.5be625a",
3
+ "version": "0.8.1-staging.97aedb1",
4
4
  "description": "React client API",
5
5
  "homepage": "https://dxos.org",
6
6
  "bugs": "https://github.com/dxos/dxos/issues",
@@ -78,40 +78,40 @@
78
78
  },
79
79
  "dependencies": {
80
80
  "react-error-boundary": "^4.0.13",
81
- "@dxos/async": "0.8.1-staging.5be625a",
82
- "@dxos/codec-protobuf": "0.8.1-staging.5be625a",
83
- "@dxos/client": "0.8.1-staging.5be625a",
84
- "@dxos/config": "0.8.1-staging.5be625a",
85
- "@dxos/echo-schema": "0.8.1-staging.5be625a",
86
- "@dxos/echo-signals": "0.8.1-staging.5be625a",
87
- "@dxos/log": "0.8.1-staging.5be625a",
88
- "@dxos/node-std": "0.8.1-staging.5be625a",
89
- "@dxos/debug": "0.8.1-staging.5be625a",
90
- "@dxos/invariant": "0.8.1-staging.5be625a",
91
- "@dxos/protocols": "0.8.1-staging.5be625a",
92
- "@dxos/react-hooks": "0.8.1-staging.5be625a",
93
- "@dxos/util": "0.8.1-staging.5be625a"
81
+ "@dxos/async": "0.8.1-staging.97aedb1",
82
+ "@dxos/client": "0.8.1-staging.97aedb1",
83
+ "@dxos/codec-protobuf": "0.8.1-staging.97aedb1",
84
+ "@dxos/config": "0.8.1-staging.97aedb1",
85
+ "@dxos/debug": "0.8.1-staging.97aedb1",
86
+ "@dxos/echo-schema": "0.8.1-staging.97aedb1",
87
+ "@dxos/echo-signals": "0.8.1-staging.97aedb1",
88
+ "@dxos/invariant": "0.8.1-staging.97aedb1",
89
+ "@dxos/node-std": "0.8.1-staging.97aedb1",
90
+ "@dxos/log": "0.8.1-staging.97aedb1",
91
+ "@dxos/protocols": "0.8.1-staging.97aedb1",
92
+ "@dxos/util": "0.8.1-staging.97aedb1",
93
+ "@dxos/react-hooks": "0.8.1-staging.97aedb1"
94
94
  },
95
95
  "devDependencies": {
96
96
  "@types/react": "~18.2.0",
97
97
  "@types/react-dom": "~18.2.0",
98
98
  "react": "~18.2.0",
99
99
  "react-dom": "~18.2.0",
100
- "@dxos/random": "0.8.1-staging.5be625a",
101
- "@dxos/react-ui-theme": "0.8.1-staging.5be625a",
102
- "@dxos/react-ui-syntax-highlighter": "0.8.1-staging.5be625a",
103
- "@dxos/storybook-utils": "0.8.1-staging.5be625a",
104
- "@dxos/react-ui": "0.8.1-staging.5be625a",
105
- "@dxos/test-utils": "0.8.1-staging.5be625a"
100
+ "@dxos/random": "0.8.1-staging.97aedb1",
101
+ "@dxos/react-ui": "0.8.1-staging.97aedb1",
102
+ "@dxos/react-ui-syntax-highlighter": "0.8.1-staging.97aedb1",
103
+ "@dxos/react-ui-theme": "0.8.1-staging.97aedb1",
104
+ "@dxos/storybook-utils": "0.8.1-staging.97aedb1",
105
+ "@dxos/test-utils": "0.8.1-staging.97aedb1"
106
106
  },
107
107
  "peerDependencies": {
108
108
  "react": "~18.2.0",
109
109
  "react-dom": "~18.2.0"
110
110
  },
111
111
  "optionalDependencies": {
112
- "@dxos/random": "0.8.1-staging.5be625a",
113
- "@dxos/react-ui": "0.8.1-staging.5be625a",
114
- "@dxos/react-ui-theme": "0.8.1-staging.5be625a"
112
+ "@dxos/random": "0.8.1-staging.97aedb1",
113
+ "@dxos/react-ui": "0.8.1-staging.97aedb1",
114
+ "@dxos/react-ui-theme": "0.8.1-staging.97aedb1"
115
115
  },
116
116
  "publishConfig": {
117
117
  "access": "public"
@@ -9,9 +9,9 @@ import {
9
9
  type Echo,
10
10
  type FilterSource,
11
11
  Filter,
12
- type ReactiveEchoObject,
13
12
  type Query,
14
13
  type QueryOptions,
14
+ type ReactiveEchoObject,
15
15
  type Space,
16
16
  } from '@dxos/client/echo';
17
17
 
@@ -2,7 +2,7 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- import { useEffect, useMemo } from 'react';
5
+ import { useEffect, useMemo, useRef } from 'react';
6
6
 
7
7
  import type { Queue } from '@dxos/client/echo';
8
8
  import { raise } from '@dxos/debug';
@@ -23,18 +23,19 @@ export type UseQueueOptions = {
23
23
  // TODO(burdon): Replace polling with socket?
24
24
  // TODO(dmaretskyi): Move into client package.
25
25
  // TODO(dmaretskyi): Consider passing the space into the hook to support queue DXNs without space id.
26
+ // TODO(ZaymonFC): If queue is unchanged returned object should be refferentially stable on poll.
26
27
  export const useQueue = <T extends BaseEchoObject>(
27
28
  queueDxn?: DXN,
28
29
  options: UseQueueOptions = {},
29
30
  ): Queue<T> | undefined => {
30
31
  const client = useClient();
32
+ const mountedRef = useRef(true);
33
+
31
34
  const queue = useMemo<Queue<T> | undefined>(() => {
32
35
  if (!queueDxn) {
33
36
  return undefined;
34
37
  }
35
-
36
38
  const { spaceId } = queueDxn.asQueueDXN() ?? raise(new TypeError('Invalid queue DXN'));
37
-
38
39
  return client.spaces.get(spaceId)?.queues.get<T>(queueDxn);
39
40
  }, [client, queueDxn?.toString()]);
40
41
 
@@ -44,17 +45,28 @@ export const useQueue = <T extends BaseEchoObject>(
44
45
 
45
46
  useEffect(() => {
46
47
  let timeout: NodeJS.Timeout;
47
- if (options.pollInterval) {
48
- const poll = () => {
49
- void queue?.refresh().finally(() => {
48
+ mountedRef.current = true;
49
+
50
+ const poll = () => {
51
+ if (!mountedRef.current) {
52
+ return;
53
+ }
54
+
55
+ void queue?.refresh().finally(() => {
56
+ if (mountedRef.current && options.pollInterval) {
50
57
  timeout = setTimeout(poll, Math.max(options.pollInterval ?? 0, MIN_POLL_INTERVAL));
51
- });
52
- };
58
+ }
59
+ });
60
+ };
53
61
 
62
+ if (options.pollInterval) {
54
63
  poll();
55
64
  }
56
65
 
57
- return () => clearTimeout(timeout);
66
+ return () => {
67
+ mountedRef.current = false;
68
+ clearTimeout(timeout);
69
+ };
58
70
  }, [queue, options.pollInterval]);
59
71
 
60
72
  return queue;