]> Piment Noir Git Repositories - e-mobility-charging-stations-simulator.git/commit
fix(ui-web): resolve WS race condition causing DISCONNECTED on modern skin
authorJérôme Benoit <jerome.benoit@sap.com>
Wed, 29 Apr 2026 23:09:37 +0000 (01:09 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Wed, 29 Apr 2026 23:09:37 +0000 (01:09 +0200)
commite626ef8a0f8ce4ac1010fc440a0c27dd225b4435
treec5ea1f2f9c27506a87a56896170a194089027c1e
parent72aba1edf1957107024a043cbbd122fc0a4ee552
fix(ui-web): resolve WS race condition causing DISCONNECTED on modern skin

Problem: when skin layouts are lazy-loaded via defineAsyncComponent, the
WebSocket 'open' event can fire before the layout mounts and registers its
listener. The layout then shows DISCONNECTED until manual refresh because
getData() is never triggered.

Root cause: UIClient connects in main.ts constructor (fire-and-forget),
but the skin layout mounts asynchronously after the chunk loads. If the
WS handshake completes during chunk loading, the 'open' event is dispatched
to an EventTarget with zero listeners.

Fix: expose connection state and fetch eagerly when already connected.

- ui-common/WebSocketClient: add `get connected(): boolean` getter
  (returns readyState === OPEN)
- ui-web/UIClient: add `isConnected(): boolean` (delegates to client.connected)
- ui-web/useLayoutData: in onMounted, call getData() immediately if
  isConnected() is true. Otherwise the normal 'open' handler will
  trigger getData() when the connection establishes — no premature
  fetch, no error toast, no duplicate calls.
- ui-web/tests: add isConnected to MockUIClient (defaults to false);
  add 2 explicit tests for both branches of the mount-time check
ui/common/src/client/WebSocketClient.ts
ui/web/src/composables/UIClient.ts
ui/web/src/shared/composables/useLayoutData.ts
ui/web/tests/unit/helpers.ts
ui/web/tests/unit/shared/composables/useLayoutData.test.ts
ui/web/tests/unit/skins/modern/ModernLayout.test.ts