@xh/hoist 73.0.0-SNAPSHOT.1746826691467 → 73.0.0-SNAPSHOT.1746829743606

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/CHANGELOG.md CHANGED
@@ -36,6 +36,9 @@
36
36
  * Fixed drag-and-drop usability issues with the mobile `ColChooser`.
37
37
  * Made `GridModel.defaultGroupSortFn` null-safe and improved type signature.
38
38
  * Disable `dashCanvasAddViewButton` if there are no `menuItems` to show.
39
+ * Improvements to `@bindable` and `@persist` to handle lifecycle-related bugs. Note that previously
40
+ `@bindable` would work even if `makeObservable()` was not called, but this is no longer the case.
41
+ Please ensure that `makeObservable()` is called in your model's constructor when using `@bindable`.
39
42
 
40
43
  ### ⚙️ Typescript API Adjustments
41
44
 
@@ -55,7 +58,10 @@
55
58
  * ⚠️ NOTE that a misconfigured build - where the client version is not set to the same value
56
59
  as the server - would result in a false positive for an upgrade. The two should always match.
57
60
  * Calls to `Promise.track()` that are rejected with an exception will be tracked with new
58
- severity level of `TrackSeverity.ERROR`
61
+ severity level of `TrackSeverity.ERROR`.
62
+ * Improved client `WebSocketService` heartbeat to check that it has been receiving inbound messages
63
+ from the server, not just successfully sending outbound heartbeats.
64
+ * Improved client `WebSocketService` to throttle its reconnect attempts.
59
65
 
60
66
  ## v72.5.1 - 2025-04-15
61
67
 
@@ -6,4 +6,4 @@ export declare function makeObservable(target: any, annotations?: AnnotationsMap
6
6
  /**
7
7
  * An enhanced version of the native mobx isObservableProp
8
8
  */
9
- export declare function isObservableProp(target: any, propertyKey: PropertyKey): any;
9
+ export declare function isObservableProp(target: any, propertyKey: PropertyKey): boolean;
@@ -25,6 +25,12 @@ import { HoistService, PlainObject } from '@xh/hoist/core';
25
25
  export declare class WebSocketService extends HoistService {
26
26
  static instance: WebSocketService;
27
27
  readonly HEARTBEAT_TOPIC = "xhHeartbeat";
28
+ /** Check connection and send a new heartbeat (which should be promptly ack'd) every 10s. */
29
+ readonly HEARTBEAT_INTERVAL: number;
30
+ /** If no heartbeat ack (or other msg) received for past 30s, assume we are disconnected. */
31
+ readonly HEARTBEAT_ACK_TIMEOUT: number;
32
+ /** Wait a well-defined interval before trying to reconnect again. */
33
+ readonly HEARTBEAT_RECONNECT_INTERVAL: number;
28
34
  readonly REG_SUCCESS_TOPIC = "xhRegistrationSuccess";
29
35
  readonly FORCE_APP_SUSPEND_TOPIC = "xhForceAppSuspend";
30
36
  readonly REQ_CLIENT_HEALTH_RPT_TOPIC = "xhRequestClientHealthReport";
@@ -43,6 +49,7 @@ export declare class WebSocketService extends HoistService {
43
49
  private _timer;
44
50
  private _socket;
45
51
  private _subsByTopic;
52
+ private _lastHeartbeatReconnectAttempt;
46
53
  constructor();
47
54
  initAsync(): Promise<void>;
48
55
  /**
@@ -57,7 +64,6 @@ export declare class WebSocketService extends HoistService {
57
64
  subscribe(topic: string, fn: (msg: WebSocketMessage) => any): WebSocketSubscription;
58
65
  /**
59
66
  * Cancel a subscription for a given topic/handler.
60
- *
61
67
  * @param subscription - WebSocketSubscription returned when the subscription was established.
62
68
  */
63
69
  unsubscribe(subscription: WebSocketSubscription): void;
@@ -109,6 +115,9 @@ export interface WebSocketTelemetry {
109
115
  connError?: WebSocketEventTelemetry;
110
116
  msgReceived?: WebSocketEventTelemetry;
111
117
  msgSent?: WebSocketEventTelemetry;
118
+ heartbeatReceived?: WebSocketEventTelemetry;
119
+ heartbeatSent?: WebSocketEventTelemetry;
120
+ heartbeatFailed?: WebSocketEventTelemetry;
112
121
  heartbeatReconnectAttempt?: WebSocketEventTelemetry;
113
122
  instanceChangeReconnectAttempt?: WebSocketEventTelemetry;
114
123
  };
@@ -4,6 +4,8 @@
4
4
  *
5
5
  * Copyright © 2025 Extremely Heavy Industries Inc.
6
6
  */
7
+ import {wait} from '@xh/hoist/promise';
8
+ import {observable} from 'mobx';
7
9
  import {logError, throwIf} from '../utils/js';
8
10
  import {HoistBaseClass, PersistableState, PersistenceProvider, PersistOptions} from './';
9
11
 
@@ -71,38 +73,38 @@ function createPersistDescriptor(
71
73
  );
72
74
  return descriptor;
73
75
  }
74
- const codeValue = descriptor.initializer;
75
- let hasInitialized = false,
76
- ret;
77
- const initializer = function () {
78
- // Initializer can be called multiple times when stacking decorators.
79
- if (hasInitialized) return ret;
76
+ const codeValue = descriptor.initializer,
77
+ initializer = function () {
78
+ // codeValue undefined if no initial in-code value provided, otherwise call to get initial value.
79
+ let ret = codeValue?.call(this);
80
80
 
81
- // codeValue undefined if no initial in-code value provided, otherwise call to get initial value.
82
- ret = codeValue?.call(this);
83
-
84
- const persistOptions = {
85
- path: property,
86
- ...PersistenceProvider.mergePersistOptions(this.persistWith, options)
87
- };
88
- PersistenceProvider.create({
89
- persistOptions,
90
- owner: this,
91
- target: {
92
- getPersistableState: () =>
93
- new PersistableState(hasInitialized ? this[property] : ret),
94
- setPersistableState: state => {
95
- if (!hasInitialized) {
96
- ret = state.value;
97
- } else {
98
- this[property] = state.value;
81
+ // Property is not available on the instance until after the next tick.
82
+ const propertyAvailable = observable.box(false),
83
+ persistOptions = {
84
+ path: property,
85
+ ...PersistenceProvider.mergePersistOptions(this.persistWith, options)
86
+ };
87
+ PersistenceProvider.create({
88
+ persistOptions,
89
+ owner: this,
90
+ target: {
91
+ getPersistableState: () =>
92
+ new PersistableState(propertyAvailable.get() ? this[property] : ret),
93
+ setPersistableState: state => {
94
+ if (!propertyAvailable.get()) {
95
+ ret = state.value;
96
+ } else {
97
+ this[property] = state.value;
98
+ }
99
99
  }
100
100
  }
101
- }
102
- });
101
+ });
103
102
 
104
- hasInitialized = true;
105
- return ret;
106
- };
103
+ // Wait for next tick to ensure construction has completed and property has been made
104
+ // observable via makeObservable.
105
+ wait().thenAction(() => propertyAvailable.set(true));
106
+
107
+ return ret;
108
+ };
107
109
  return {...descriptor, initializer};
108
110
  }
@@ -5,8 +5,6 @@
5
5
  * Copyright © 2025 Extremely Heavy Industries Inc.
6
6
  */
7
7
  import {upperFirst} from 'lodash';
8
- import {observable, runInAction} from 'mobx';
9
- import {getOrCreate} from '../utils/js';
10
8
 
11
9
  /**
12
10
  * Decorator to mark a property as observable and also provide a simple MobX action of the
@@ -40,40 +38,14 @@ function createBindable(target, name, descriptor, isRef) {
40
38
  Object.defineProperty(target, setterName, {value});
41
39
  }
42
40
 
43
- // 2) Place a hidden getter on prototype that wraps the backing observable.
44
- const {initializer} = descriptor,
45
- propName = `_${name}_bindable`,
46
- valName = `_${name}_bindable_value`;
47
- Object.defineProperty(target, propName, {
48
- get() {
49
- return getOrCreate(this, valName, () => {
50
- const initVal = initializer?.call(this);
51
- return isRef ? observable.box(initVal, {deep: false}) : observable.box(initVal);
52
- });
53
- }
54
- });
55
-
56
- // 3) Create the descriptor for a getter/setter pair..
57
- descriptor = {
58
- get() {
59
- return this[propName].get();
60
- },
61
- set(v) {
62
- runInAction(() => this[propName].set(v));
63
- },
64
- enumerable: true,
65
- configurable: true
66
- };
67
-
68
- // 4) Record on class, so we can later create on *instance* in makeObservable.
69
- // (Be sure to create cloned list for *this* particular class.)
41
+ // 2) Record on class, so we can later create on *instance* in makeObservable.
42
+ // (Be sure to create cloned list since this will exist on prototype superclasses of this class)
70
43
  const key = '_xhBindableProperties';
71
44
  if (!target.hasOwnProperty(key)) {
72
45
  target[key] = {...target[key]};
73
46
  }
74
- target[key][name] = descriptor;
47
+ target[key][name] = {isRef};
75
48
 
76
- // 5) Return the get/set to be placed on prototype. (If makeObservable() never called, or called
77
- // late, the non-enumerable property will still be available.)
49
+ // 3) Return original descriptor.
78
50
  return descriptor;
79
51
  }
package/mobx/overrides.ts CHANGED
@@ -9,7 +9,9 @@ import {
9
9
  AnnotationsMap,
10
10
  CreateObservableOptions,
11
11
  makeObservable as baseMakeObservable,
12
- isObservableProp as baseIsObservableProp
12
+ isObservableProp as baseIsObservableProp,
13
+ observable,
14
+ runInAction
13
15
  } from 'mobx';
14
16
 
15
17
  /**
@@ -21,10 +23,21 @@ export function makeObservable(
21
23
  options?: CreateObservableOptions
22
24
  ) {
23
25
  // Finish creating 'bindable' properties for this instance.
24
- // Do here to ensure it's enumerable on *instance*
25
26
  const bindables = target._xhBindableProperties;
26
- forEach(bindables, (descriptor, name) => {
27
- Object.defineProperty(target, name, descriptor);
27
+ forEach(bindables, ({isRef}, name) => {
28
+ const propName = `_${name}_bindable`,
29
+ initVal = target[name];
30
+ target[propName] = isRef ? observable.box(initVal, {deep: false}) : observable.box(initVal);
31
+ Object.defineProperty(target, name, {
32
+ get() {
33
+ return this[propName].get();
34
+ },
35
+ set(v) {
36
+ runInAction(() => this[propName].set(v));
37
+ },
38
+ enumerable: true,
39
+ configurable: true
40
+ });
28
41
  });
29
42
 
30
43
  return baseMakeObservable(target, annotations, options);
@@ -33,8 +46,8 @@ export function makeObservable(
33
46
  /**
34
47
  * An enhanced version of the native mobx isObservableProp
35
48
  */
36
- export function isObservableProp(target: any, propertyKey: PropertyKey) {
49
+ export function isObservableProp(target: any, propertyKey: PropertyKey): boolean {
37
50
  return (
38
- baseIsObservableProp(target, propertyKey) || target?._xhBindableProperties?.[propertyKey]
51
+ baseIsObservableProp(target, propertyKey) || !!target?._xhBindableProperties?.[propertyKey]
39
52
  );
40
53
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xh/hoist",
3
- "version": "73.0.0-SNAPSHOT.1746826691467",
3
+ "version": "73.0.0-SNAPSHOT.1746829743606",
4
4
  "description": "Hoist add-on for building and deploying React Applications.",
5
5
  "repository": "github:xh/hoist-react",
6
6
  "homepage": "https://xh.io",
@@ -8,7 +8,7 @@ import {HoistService, PlainObject, XH} from '@xh/hoist/core';
8
8
  import {withFormattedTimestamps} from '@xh/hoist/format';
9
9
  import {action, makeObservable, observable} from '@xh/hoist/mobx';
10
10
  import {Timer} from '@xh/hoist/utils/async';
11
- import {SECONDS} from '@xh/hoist/utils/datetime';
11
+ import {olderThan, SECONDS} from '@xh/hoist/utils/datetime';
12
12
  import {throwIf} from '@xh/hoist/utils/js';
13
13
  import {find, pull} from 'lodash';
14
14
 
@@ -39,6 +39,13 @@ export class WebSocketService extends HoistService {
39
39
  static instance: WebSocketService;
40
40
 
41
41
  readonly HEARTBEAT_TOPIC = 'xhHeartbeat';
42
+ /** Check connection and send a new heartbeat (which should be promptly ack'd) every 10s. */
43
+ readonly HEARTBEAT_INTERVAL = 10 * SECONDS;
44
+ /** If no heartbeat ack (or other msg) received for past 30s, assume we are disconnected. */
45
+ readonly HEARTBEAT_ACK_TIMEOUT = 30 * SECONDS;
46
+ /** Wait a well-defined interval before trying to reconnect again. */
47
+ readonly HEARTBEAT_RECONNECT_INTERVAL = 30 * SECONDS;
48
+
42
49
  readonly REG_SUCCESS_TOPIC = 'xhRegistrationSuccess';
43
50
  readonly FORCE_APP_SUSPEND_TOPIC = 'xhForceAppSuspend';
44
51
  readonly REQ_CLIENT_HEALTH_RPT_TOPIC = 'xhRequestClientHealthReport';
@@ -66,6 +73,7 @@ export class WebSocketService extends HoistService {
66
73
  private _timer: Timer;
67
74
  private _socket: WebSocket;
68
75
  private _subsByTopic: Record<string, WebSocketSubscription[]> = {};
76
+ private _lastHeartbeatReconnectAttempt: Date = null;
69
77
 
70
78
  constructor() {
71
79
  super();
@@ -93,7 +101,7 @@ export class WebSocketService extends HoistService {
93
101
 
94
102
  this._timer = Timer.create({
95
103
  runFn: () => this.heartbeatOrReconnect(),
96
- interval: 10 * SECONDS,
104
+ interval: this.HEARTBEAT_INTERVAL,
97
105
  delay: true
98
106
  });
99
107
  }
@@ -122,7 +130,6 @@ export class WebSocketService extends HoistService {
122
130
 
123
131
  /**
124
132
  * Cancel a subscription for a given topic/handler.
125
- *
126
133
  * @param subscription - WebSocketSubscription returned when the subscription was established.
127
134
  */
128
135
  unsubscribe(subscription: WebSocketSubscription) {
@@ -192,9 +199,29 @@ export class WebSocketService extends HoistService {
192
199
 
193
200
  private heartbeatOrReconnect() {
194
201
  this.updateConnectedStatus();
202
+
203
+ // 1) Detect 'stale' connection. For some reason, not receiving heartbeat.
204
+ // We have a channel key, so we successfully registered with the server and have not
205
+ // received a disconnect message. We should be receiving at least heartbeat messages,
206
+ // but have observed cases where "something" interrupted connectivity in a surprising
207
+ // way and no new inbound messages were arriving, even with the socket reporting open
208
+ // and accepting outbound messages to send. Detect that case here.
209
+ if (this.connected && olderThan(this.lastMessageTime, this.HEARTBEAT_ACK_TIMEOUT)) {
210
+ this.logWarn('Heartbeat response failing - disconnecting');
211
+ this.noteTelemetryEvent('heartbeatFailed');
212
+ this.disconnect();
213
+ }
214
+
215
+ // 2) Happy path - connected+receiving. Send a new heartbeat for server to ack.
195
216
  if (this.connected) {
196
217
  this.sendMessage({topic: this.HEARTBEAT_TOPIC, data: 'ping'});
197
- } else {
218
+ this.noteTelemetryEvent('heartbeatSent');
219
+ return;
220
+ }
221
+
222
+ // 3) Unhappy path -- attempt a (throttled) reconnect.
223
+ if (!olderThan(this._lastHeartbeatReconnectAttempt, this.HEARTBEAT_RECONNECT_INTERVAL)) {
224
+ this._lastHeartbeatReconnectAttempt = new Date();
198
225
  this.logWarn('Heartbeat found websocket not connected - attempting to reconnect...');
199
226
  this.noteTelemetryEvent('heartbeatReconnectAttempt');
200
227
  this.disconnect();
@@ -252,6 +279,9 @@ export class WebSocketService extends HoistService {
252
279
  case this.REQ_CLIENT_HEALTH_RPT_TOPIC:
253
280
  XH.clientHealthService.sendReportAsync();
254
281
  break;
282
+ case this.HEARTBEAT_TOPIC:
283
+ this.noteTelemetryEvent('heartbeatReceived');
284
+ break;
255
285
  }
256
286
 
257
287
  this.notifySubscribers(msg);
@@ -361,6 +391,9 @@ export interface WebSocketTelemetry {
361
391
  connError?: WebSocketEventTelemetry;
362
392
  msgReceived?: WebSocketEventTelemetry;
363
393
  msgSent?: WebSocketEventTelemetry;
394
+ heartbeatReceived?: WebSocketEventTelemetry;
395
+ heartbeatSent?: WebSocketEventTelemetry;
396
+ heartbeatFailed?: WebSocketEventTelemetry;
364
397
  heartbeatReconnectAttempt?: WebSocketEventTelemetry;
365
398
  instanceChangeReconnectAttempt?: WebSocketEventTelemetry;
366
399
  };