[GH-ISSUE #5262] [Bug]: dynamic update client list #3687

Closed
opened 2026-10-31 20:34:14 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @mitrios-hub on GitHub (Jun 13, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5262

Describe the bug

I noticed that since version 3.0, the data about connected clients does not update dynamically (or updates incorrectly or incompletely). For example, users are online, but not all are shown, or zero are shown; sorting works incorrectly — the most recently online may appear at the very beginning, and some at the very end of the list, and so on.

Image Image Image

Go to another tab in the panel and return to the client list — it does not help. Only a page refresh works.

How to reproduce the problem

  1. Open the panel and verify there are no online clients.
  2. Open the Clients tab and see that there are 0 clients.
  3. Wait for clients to connect and see that the online count has increased.
  4. See that the client list is empty.
  5. Refresh the page and see that the clients have appeared.
  6. Wait for clients to disconnect or new clients to connect and see that the count has changed, but the list has not updated.
  7. Select a sorting type and see that it works incorrectly.

Expected behavior

No response

Actual behavior

No response

Relevant logs


Screenshots

No response

3x-ui version

3.3.1

Xray-core version

26.6.1

How did you install 3x-ui?

install.sh script

Operating system

Debian 13

Which parts of the panel are affected?

No response

Browser (only if it is a UI bug)

No response

Is the panel behind a reverse proxy or CDN?

None

Before submitting

  • I searched existing issues and this bug has not been reported.
  • I am running the latest released version of 3x-ui (or have verified the bug still exists on it).
  • This bug report is written in English.
  • I have redacted any sensitive data (tokens, real domains, client UUIDs).
Originally created by @mitrios-hub on GitHub (Jun 13, 2026). Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5262 ### Describe the bug I noticed that since version 3.0, the data about connected clients does not update dynamically (or updates incorrectly or incompletely). For example, users are online, but not all are shown, or zero are shown; sorting works incorrectly — the most recently online may appear at the very beginning, and some at the very end of the list, and so on. <img width="949" height="486" alt="Image" src="https://github.com/user-attachments/assets/05daa5f5-9047-446b-b8a1-24bfdd210546" /> <img width="488" height="658" alt="Image" src="https://github.com/user-attachments/assets/23fe1e40-5bf2-4411-8886-270b655f2140" /> <img width="488" height="615" alt="Image" src="https://github.com/user-attachments/assets/0942b236-a383-4d36-8857-bae2c91d7379" /> Go to another tab in the panel and return to the client list — it does not help. Only a page refresh works. ### How to reproduce the problem 1. Open the panel and verify there are no online clients. 2. Open the Clients tab and see that there are 0 clients. 3. Wait for clients to connect and see that the online count has increased. 4. See that the client list is empty. 5. Refresh the page and see that the clients have appeared. 6. Wait for clients to disconnect or new clients to connect and see that the count has changed, but the list has not updated. 7. Select a sorting type and see that it works incorrectly. ### Expected behavior _No response_ ### Actual behavior _No response_ ### Relevant logs ```shell ``` ### Screenshots _No response_ ### 3x-ui version 3.3.1 ### Xray-core version 26.6.1 ### How did you install 3x-ui? install.sh script ### Operating system Debian 13 ### Which parts of the panel are affected? _No response_ ### Browser (only if it is a UI bug) _No response_ ### Is the panel behind a reverse proxy or CDN? None ### Before submitting - [x] I searched [existing issues](../issues?q=is%3Aissue) and this bug has not been reported. - [x] I am running the latest released version of 3x-ui (or have verified the bug still exists on it). - [x] This bug report is written in English. - [x] I have redacted any sensitive data (tokens, real domains, client UUIDs).
bsakaguchi 2026-10-31 20:34:14 +07:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@github-actions[bot] commented on GitHub (Jun 13, 2026):

Both symptoms you describe — the list not reflecting newly connected clients and the sort order becoming stale — are caused by the same architectural gap in the v3 React frontend.

How the client list is currently updated

frontend/src/hooks/useClients.ts fetches the paged client list with staleTime: Infinity (line 185). React Query therefore never schedules an automatic background refetch; the page is only re-fetched when one of these events occurs:

  • A mutation (create / edit / delete client) calls invalidateAll().
  • The WebSocket invalidate event arrives with type: "clients" (handled in frontend/src/api/websocketBridge.ts:33-45).

The backend job internal/web/job/xray_traffic_job.go runs on every traffic poll and broadcasts two WebSocket events:

  1. BroadcastTraffic — updates the online/offline badge list only.
  2. BroadcastClientStats — carries per-client traffic counters for all clients.

The frontend handler applyClientStatsEvent (useClients.ts:483-513) processes event 2 by iterating over the rows already present in the current page and patching their traffic fields in-place. It does not add rows for clients that were absent when the page loaded, remove rows for clients that have since been deleted, or re-sort the array. Clients who connect after the initial page fetch therefore never appear until the page is manually refreshed.

Why the sort order breaks

The sort is computed server-side on the initial fetch. applyClientStatsEvent updates row.traffic.lastOnline for existing rows (line 506), but does not reorder the items array to match the new values. After an in-place update, a client whose lastOnline just changed stays at its original array position, producing the scrambled order you observe.

Why the summary counters stay accurate

The summary card re-computes from allClientStats (set by applyClientStatsEvent line 487), which carries statistics for all clients regardless of the current page. That is why the online count in the header tracks reality while the table rows do not.

When invalidate is sent and when it is not

xray_traffic_job.go only issues BroadcastInvalidate(MessageTypeInbounds) when clients are disabled due to quota exhaustion (line 58). The node_traffic_sync_job.go sends BroadcastInvalidate(MessageTypeClients) only on structural changes (j.structural.takeAndReset(), line 168). Neither job broadcasts a clients invalidate on every normal traffic poll, so in a single-node setup without quota events the list is never server-refreshed by WebSocket alone.

The combination of staleTime: Infinity and an in-place patch strategy that cannot account for new or reordered rows reproduces all steps you listed exactly.

This comment was generated automatically; a maintainer may follow up.

<!-- gh-comment-id:4697864702 --> @github-actions[bot] commented on GitHub (Jun 13, 2026): Both symptoms you describe — the list not reflecting newly connected clients and the sort order becoming stale — are caused by the same architectural gap in the v3 React frontend. **How the client list is currently updated** `frontend/src/hooks/useClients.ts` fetches the paged client list with `staleTime: Infinity` (line 185). React Query therefore never schedules an automatic background refetch; the page is only re-fetched when one of these events occurs: - A mutation (create / edit / delete client) calls `invalidateAll()`. - The WebSocket `invalidate` event arrives with `type: "clients"` (handled in `frontend/src/api/websocketBridge.ts:33-45`). The backend job `internal/web/job/xray_traffic_job.go` runs on every traffic poll and broadcasts two WebSocket events: 1. `BroadcastTraffic` — updates the online/offline badge list only. 2. `BroadcastClientStats` — carries per-client traffic counters for all clients. The frontend handler `applyClientStatsEvent` (`useClients.ts:483-513`) processes event 2 by iterating over the rows **already present in the current page** and patching their traffic fields in-place. It does not add rows for clients that were absent when the page loaded, remove rows for clients that have since been deleted, or re-sort the array. Clients who connect after the initial page fetch therefore never appear until the page is manually refreshed. **Why the sort order breaks** The sort is computed server-side on the initial fetch. `applyClientStatsEvent` updates `row.traffic.lastOnline` for existing rows (line 506), but does not reorder the items array to match the new values. After an in-place update, a client whose `lastOnline` just changed stays at its original array position, producing the scrambled order you observe. **Why the summary counters stay accurate** The summary card re-computes from `allClientStats` (set by `applyClientStatsEvent` line 487), which carries statistics for all clients regardless of the current page. That is why the online count in the header tracks reality while the table rows do not. **When `invalidate` is sent and when it is not** `xray_traffic_job.go` only issues `BroadcastInvalidate(MessageTypeInbounds)` when clients are disabled due to quota exhaustion (line 58). The `node_traffic_sync_job.go` sends `BroadcastInvalidate(MessageTypeClients)` only on structural changes (`j.structural.takeAndReset()`, line 168). Neither job broadcasts a clients invalidate on every normal traffic poll, so in a single-node setup without quota events the list is never server-refreshed by WebSocket alone. The combination of `staleTime: Infinity` and an in-place patch strategy that cannot account for new or reordered rows reproduces all steps you listed exactly. *This comment was generated automatically; a maintainer may follow up.*
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
MHSanaei/3x-ui#3687
No description provided.