mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 19:11:53 +07:00
[GH-ISSUE #6894] [Feature]: Respect global Hosts order in subscriptions and support drag-and-drop #4576
Labels
No labels
backlog
bug
clarification needed
documentation
duplicate
enhancement
github_actions
good first issue
invalid
javascript
New Feature
PR welcomed
pull-request
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
MHSanaei/3x-ui#4576
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @HamedSanaei on GitHub (Oct 21, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/6894
### Is your feature request related to a problem?
Yes. The Host groups displayed in
/panel/hostshave a persistedsort_orderand Up/Down controls, but their global order is not reflected in the final subscription when hosts belong to different inbounds.The current code retrieves inbounds by
sub_sort_index ASC, id ASC(internal/sub/service.go:getInboundsBySubId), then iterates through those inbounds.internal/sub/host_sub.go:hostEndpointsappliessort_order ASC, id ASConly inside each inbound. The raw/base64, Clash/Mihomo, and JSON subscription builders consequently group generated Host endpoints by parent inbound. Moving a Host group above another group from a different inbound does not reliably move it above that group in the exported list. Changing inbound order instead is too coarse.Separately,
/panel/hostsrequires repeated Up/Down clicks to reposition Host rows, while/panel/routingalready has a convenient drag-and-drop approach for routing rules.Describe the solution you'd like
1. Make global Host order optionally control the generated subscription
/panel/hosts, regardless of inbound ID orsub_sort_index.Inbound-first (current behavior)/Hosts-firstsubscription ordering mode (or an equivalent opt-in) would avoid changing existing subscribers' order without their administrator's consent.2. Add drag-and-drop for Host rows on
/panel/hosts/panel/routing.POST /panel/api/hosts/reorderendpoint and theHostService.ReorderHostGroups/sort_ordermechanism where practical; no second incompatible ordering source.Expected behavior example
With Hosts-first ordering selected, the resulting subscription is B → A → C, even if inbound #5 has the smaller inbound ID or subscription sort index. Dragging A above B should change the next subscription response to A → B → C without editing the inbounds.
(The server can guarantee the order in the generated subscription; some client applications may subsequently apply their own local sorting.)
Alternatives you've considered
sub_sort_indexcan only reorder entire inbound blocks, not interleave Host entries across inbounds.Concrete use case
I operate multiple inbounds and maintain preferred, secondary, and backup Host endpoints. I want the most reliable Host to appear first for subscribers, and need to adjust that priority quickly as conditions change. The Host's priority should not be determined by when I originally created its inbound.
Mockups, screenshots, or examples
Use the current drag-and-drop control on
/panel/routingas the UX reference for the Hosts table.Relevant implementation points:
frontend/src/pages/hosts/HostList.tsxandHostsPage.tsx(existing Up/Down UI)internal/web/controller/host.goandinternal/web/service/host.go(existing/reorderendpoint,sort_orderpersistence)internal/sub/service.go,host_sub.go,clash_service.go,json_service.go(subscription ordering across formats)internal/sub/host_sub_test.go:TestSub_HostSortComposesWithSubSortIndexcurrently asserts inbound-first ordering. Preserve this for the default mode and add regression coverage for Hosts-first ordering across different inbounds, multiple hosts/groups, exclusions, and format parity.Related but distinct issues: #5424 concerns sorting inbounds in the panel, #4835 concerns reordering attached inbounds per client, and #5332 concerns negative inbound sort indexes. This request is specifically cross-inbound Host ordering in subscription output plus Hosts-page drag-and-drop.
Which parts of the panel would this affect?
Are you willing to help?
Before submitting
@github-actions[bot] commented on GitHub (Oct 21, 2026):
This is a valid feature request. Your reading of the current code is accurate: Host order is stored globally, but subscriptions only apply it inside each inbound, so a Host can never be placed ahead of a Host that belongs to an inbound sorted earlier. The Hosts page also has no drag-and-drop yet.
What the code does today
ReorderHostGroupsgives each group its position in the list you submit, across every inbound (internal/web/service/host.go:305-316): So the data a "Hosts-first" mode needs is already persisted. No new ordering source or migration is needed for the order itself..Order("sub_sort_index ASC").Order("id ASC")(internal/sub/service.go:691). For each inbound,hostEndpointsrunsWhere("inbound_id = ? AND is_disabled = ?", inbound.Id, false).Order("sort_order asc, id asc")(internal/sub/host_sub.go:21-24). The same call is made from the raw builder (service.go:498), Clash (clash_service.go:74), JSON (json_service.go:152) and the panel's own share links (links.go:41).TestSub_HostSortComposesWithSubSortIndex(internal/sub/host_sub_test.go:167-169) says: "host sort_order composes with inbound SubSortIndex: inbounds order by SubSortIndex, hosts within an inbound by sort_order." The JSON builder also re-sorts its output bysortIndex,kindandid(json_service.go:174-184) so that balancer entries slot in between inbounds. Hosts-first ordering would have to take that sort into account as well.reorder(frontend/src/pages/hosts/HostsPage.tsx:94-104). The arrow buttons are infrontend/src/pages/hosts/HostList.tsx:98-111. The routing page implements its drag with plain pointer events, not a drag-and-drop library (frontend/src/pages/xray/routing/RoutingTab.tsx:288-323). That is the pattern you would follow.Points a PR would need to settle
sort_orderon every row, becauseReorderHostGroupsupdates bygroup_id. Those endpoints tie on order, so a deterministic tie-break is needed. Falling back to the existing(sub_sort_index, id)order would keep it stable.externalProxyfallback, have nosort_orderof their own. Placing them before or after all Host entries is a design choice to make explicitly.hostEndpoints. The existing exclusion and ownership checks (ExcludeFromSub,ExcludeFromSubTypes, client filtering) happen inside that loop, so they should carry over unchanged.internal/web/translation/. Any new endpoint also needs theendpoints.ts/make gensteps described inCLAUDE.md.I found no existing or duplicate issue for cross-inbound Host ordering. As you noted, #5424, #4835 and #5332 are about inbound ordering, not Host ordering.
Verdict: Feature request
This reply was generated automatically by an issue-analysis assistant; a maintainer may follow up.
@HamedSanaei commented on GitHub (Oct 22, 2026):
### Implementation update — PR #6895
The two features requested in this issue have been implemented and pushed to PR #6895:
subHostSortModesetting. The default remainsinbound-firstfor backward compatibility;hosts-firstuses the saved cross-inbound Host group order in Raw/Base64, Clash/Mihomo and JSON/Xray subscriptions./panel/hosts: Host rows can be reordered by dragging. The existing reorder API, Up/Down accessibility controls, optimistic save and rollback remain in use.a6d3a426, the duplicated pointer gesture handling was extracted into the sharedusePointerRowReorderhook, now used by both Hosts and Routing Rules. Their distinct persistence behavior is preserved, and cancelling a drag in Routing no longer changes rule order.Reported local validation: 31 focused tests, all 1,877 frontend tests, TypeScript, lint, formatting, frontend build, Go subscription tests, and a real Chromium drag-and-drop check passed.
Status: PR #6895 is open for maintainer review. CI and Docs CI are awaiting maintainer approval to run; upstream CI has not yet been verified.
Maintainers: please review the implementation and approve the pending workflows when convenient. Thank you!