[PR #5369] [CLOSED] feat(inbounds): optional tag field with automatic routing rule sync #5864

Closed
opened 2026-11-02 04:04:37 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/5369
Author: @nima1024m
Created: 6/15/2026
Status: ❌ Closed

Base: main ← Head: feat/inbound-tag-field


📝 Commits (10+)

  • 4533b1c feat(inbounds): add optional tag field and sync routing on tag changes
  • 57e7822 fix(inbounds): tag field crash and add live routing sync e2e tests
  • 677fa5d fix(inbounds): return needRestart after deferred routing tag sync
  • 6adeaf5 Merge branch 'main' into feat/inbound-tag-field
  • 84a2599 chore: merge origin/main into feat/inbound-tag-field
  • 32101fc chore: merge origin/main into feat/inbound-tag-field
  • a2164f2 Merge branch 'main' into feat/inbound-tag-field
  • 5423cc9 fix(i18n): use single-brace interpolation for inbound tag auto-preview
  • 2425fc2 Merge branch 'MHSanaei:main' into feat/inbound-tag-field
  • 7a6335e v3.4.0

📊 Changes

19 files changed (+642 additions, -22 deletions)

View changed files

📝 frontend/src/pages/inbounds/form/InboundFormModal.tsx (+61 -21)
📝 frontend/src/test/inbound-form-modal.test.tsx (+41 -0)
📝 internal/config/version (+1 -1)
➕ internal/web/service/routing_sync_e2e_live_test.go (+299 -0)
➕ internal/web/service/routing_sync_e2e_seed_test.go (+132 -0)
📝 internal/web/service/xray_setting_routing_sync_test.go (+43 -0)
📝 internal/web/translation/ar-EG.json (+5 -0)
📝 internal/web/translation/en-US.json (+5 -0)
📝 internal/web/translation/es-ES.json (+5 -0)
📝 internal/web/translation/fa-IR.json (+5 -0)
📝 internal/web/translation/id-ID.json (+5 -0)
📝 internal/web/translation/ja-JP.json (+5 -0)
📝 internal/web/translation/pt-BR.json (+5 -0)
📝 internal/web/translation/ru-RU.json (+5 -0)
📝 internal/web/translation/tr-TR.json (+5 -0)
📝 internal/web/translation/uk-UA.json (+5 -0)
📝 internal/web/translation/vi-VN.json (+5 -0)
📝 internal/web/translation/zh-CN.json (+5 -0)
📝 internal/web/translation/zh-TW.json (+5 -0)

📄 Description

Summary

Adds an optional Tag field to the inbound create/edit modal (below Remark) and keeps Xray routing rules in sync when inbound tags change or inbounds are deleted — the same policy already used for outbound tag renames.

  • Frontend: Tag field with auto/manual modes, duplicate validation, i18n (13 locales), and a fix for a ReferenceError on the first keystroke in the Tag field.
  • Backend: PropagateInboundTagRename and RemoveInboundTagReferences update routing rules and loopback outbound settings.inboundTag on inbound update/delete.
  • Restart signalling: UpdateInbound uses a named needRestart return so the post-commit routing sync correctly tells callers to restart Xray when the template changes.
  • Tests: Unit tests (including UpdateInbound integration), live DB e2e tests (-tags=e2e), and manual browser verification against a running panel.

Diff: 20 files, +1,240 / −26 lines

Motivation

Routing rules reference inbound tags via inboundTag. Renaming or deleting an inbound without updating those rules leaves stale references. This PR keeps the Xray template consistent automatically, including:

  • Multi-condition rules — e.g. inboundTag + domain
  • Dual-tag rules — e.g. two values in inboundTag

Without the needRestart fix, routing rules in xrayTemplateConfig would update on tag rename but Xray could keep running with stale routing because the deferred sync ran after the return value was already captured.

Changes

Frontend

frontend/src/pages/inbounds/form/InboundFormModal.tsx

Mode Behavior
Auto Empty field → submits tag: "" → panel auto-assigns (in-{port}-tcp, etc.)
Manual Custom tag with duplicate check against existing inbounds

Bug fix: currentTagInput is defined before the tagIsAuto useMemo (fixes crash on first keystroke).

Backend

File Role
xray_setting_routing_sync.go Routing + loopback outbound sync helpers
inbound.go Hooks in UpdateInbound (rename) and DelInbound (delete cleanup); named needRestart return for deferred sync
routing_sync_e2e_live_test.go Live DB e2e tests (//go:build e2e)
routing_sync_e2e_seed_test.go Template seed helpers for manual/e2e runs (//go:build e2e)

Also preserves the existing auto tag on edit when port/transport is unchanged.

i18n

New keys under pages.inbounds.form: tag, tagHelp, tagPlaceholder, tagDuplicate, tagAutoPreview (13 locales).

Routing sync behavior

Event Inbound-only rule Multi-condition (inboundTag + domain) Dual-tag (inboundTag × 2)
Rename Tag updated Tag updated; domain kept Matched tag updated
Clear tag → auto Tag → in-{port}-tcp Tag → auto; domain kept Custom → auto; other tag kept
Delete Rule removed inboundTag stripped; domain kept Deleted tag removed; other kept

Testing

Automated

Unit tests — all pass:

go test ./internal/web/service/ -run 'PropagateInboundTag|RemoveInboundTag|UpdateInbound_Propagates|DelInbound_Removes'
Test What it verifies
PropagateInboundTagRename_* Routing rules and loopback outbounds updated on rename
RemoveInboundTagReferences_* Inbound-only rules removed; multi-condition and dual-tag rules trimmed correctly
UpdateInbound_PropagatesRoutingRuleOnTagRename Manual tag rename via UpdateInbound updates routing and returns needRestart=true
DelInbound_RemovesInboundOnlyRoutingRule Delete path removes stale inbound-only rules

Live DB e2e (-tags=e2e, requires x-ui/x-ui.db):

go test ./internal/web/service/ -tags=e2e -run TestLiveRoutingSync -v
Test What it verifies
RenameAndDelete Rename propagates to all rule shapes; delete cleans multi-condition rules
CustomToAutoTag Clearing custom tag → auto tag updates routing; delete still cleans correctly
TemplateJSONValid Template stays valid JSON after mutations

Frontend: inbound form modal tests added in inbound-form-modal.test.tsx.

Manual browser E2E

Panel at http://127.0.0.1:2053, Xray Configs → Routing Rules tab. Seeded template: api rule + inbound-only direct + example.com blocked (multi-condition) + dual-tag proxy.

Scenario Result
Tag field — type, custom save, empty → auto Pass (no crash)
Rename custom tag → check routing All 3 rule types updated; no stale tags
Delete inbound Direct rule gone; domain rule kept without tag; dual rule keeps other tag
Clear custom tag → auto-generate Routing follows in-{port}-tcp on all rules including multi-condition
Delete after auto-tag Same cleanup as delete scenario

Seed helpers (optional, panel stopped):

go test ./internal/web/service/ -tags=e2e -run TestLiveRoutingSync_Seed -v -count=1

Test plan (reviewer)

  • Empty tag → auto-assign on create/edit
  • Custom tag save + duplicate validation
  • Rename tag → routing rules update (direct, multi-condition, dual-tag)
  • Rename tag → Xray restarts (or hot-reload) so routing takes effect
  • Clear custom tag → auto tag + routing sync
  • Delete inbound → stale rules cleaned per table above
  • go test ./internal/web/service/ -run 'PropagateInboundTag|RemoveInboundTag|UpdateInbound_Propagates|DelInbound_Removes'
  • (optional) go test ./internal/web/service/ -tags=e2e -run TestLiveRoutingSync -v

Commits

  1. 4533b1cf — feat(inbounds): add optional tag field and sync routing on tag changes
  2. 57e7822e — fix(inbounds): tag field crash and add live routing sync e2e tests
  3. 677fa5d4 — fix(inbounds): return needRestart after deferred routing tag sync

Files changed

  • frontend/src/pages/inbounds/form/InboundFormModal.tsx
  • frontend/src/test/inbound-form-modal.test.tsx
  • internal/web/service/inbound.go
  • internal/web/service/xray_setting_routing_sync.go
  • internal/web/service/xray_setting_routing_sync_test.go
  • internal/web/service/routing_sync_e2e_live_test.go (new, //go:build e2e)
  • internal/web/service/routing_sync_e2e_seed_test.go (new, //go:build e2e)
  • internal/web/translation/*.json (13 locales)

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/MHSanaei/3x-ui/pull/5369 **Author:** [@nima1024m](https://github.com/nima1024m) **Created:** 6/15/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `feat/inbound-tag-field` --- ### 📝 Commits (10+) - [`4533b1c`](https://github.com/MHSanaei/3x-ui/commit/4533b1cf2f060ceae1d749457b60f05ac8e1cfeb) feat(inbounds): add optional tag field and sync routing on tag changes - [`57e7822`](https://github.com/MHSanaei/3x-ui/commit/57e7822e864ea166ff55cc1b3371c9850f37bae3) fix(inbounds): tag field crash and add live routing sync e2e tests - [`677fa5d`](https://github.com/MHSanaei/3x-ui/commit/677fa5d4d8fc70c1be18bc518f3b97cf6fc24af0) fix(inbounds): return needRestart after deferred routing tag sync - [`6adeaf5`](https://github.com/MHSanaei/3x-ui/commit/6adeaf57c48079930daa322ed7023f0906085294) Merge branch 'main' into feat/inbound-tag-field - [`84a2599`](https://github.com/MHSanaei/3x-ui/commit/84a2599ab8581affdd8190d1012b4b186072ca0b) chore: merge origin/main into feat/inbound-tag-field - [`32101fc`](https://github.com/MHSanaei/3x-ui/commit/32101fca468e22230b331eaf8ac4f3e8ae1c423a) chore: merge origin/main into feat/inbound-tag-field - [`a2164f2`](https://github.com/MHSanaei/3x-ui/commit/a2164f2574478bc415d473513909d9596f379784) Merge branch 'main' into feat/inbound-tag-field - [`5423cc9`](https://github.com/MHSanaei/3x-ui/commit/5423cc9cc4ad95294c6a82399abe1091de10ab40) fix(i18n): use single-brace interpolation for inbound tag auto-preview - [`2425fc2`](https://github.com/MHSanaei/3x-ui/commit/2425fc2d90244f3126fc3833e616e7f0f18b5847) Merge branch 'MHSanaei:main' into feat/inbound-tag-field - [`7a6335e`](https://github.com/MHSanaei/3x-ui/commit/7a6335eba3465474dade18c1c99ef288b4a410a7) v3.4.0 ### 📊 Changes **19 files changed** (+642 additions, -22 deletions) <details> <summary>View changed files</summary> 📝 `frontend/src/pages/inbounds/form/InboundFormModal.tsx` (+61 -21) 📝 `frontend/src/test/inbound-form-modal.test.tsx` (+41 -0) 📝 `internal/config/version` (+1 -1) ➕ `internal/web/service/routing_sync_e2e_live_test.go` (+299 -0) ➕ `internal/web/service/routing_sync_e2e_seed_test.go` (+132 -0) 📝 `internal/web/service/xray_setting_routing_sync_test.go` (+43 -0) 📝 `internal/web/translation/ar-EG.json` (+5 -0) 📝 `internal/web/translation/en-US.json` (+5 -0) 📝 `internal/web/translation/es-ES.json` (+5 -0) 📝 `internal/web/translation/fa-IR.json` (+5 -0) 📝 `internal/web/translation/id-ID.json` (+5 -0) 📝 `internal/web/translation/ja-JP.json` (+5 -0) 📝 `internal/web/translation/pt-BR.json` (+5 -0) 📝 `internal/web/translation/ru-RU.json` (+5 -0) 📝 `internal/web/translation/tr-TR.json` (+5 -0) 📝 `internal/web/translation/uk-UA.json` (+5 -0) 📝 `internal/web/translation/vi-VN.json` (+5 -0) 📝 `internal/web/translation/zh-CN.json` (+5 -0) 📝 `internal/web/translation/zh-TW.json` (+5 -0) </details> ### 📄 Description ## Summary Adds an optional **Tag** field to the inbound create/edit modal (below Remark) and keeps Xray routing rules in sync when inbound tags change or inbounds are deleted — the same policy already used for outbound tag renames. - **Frontend:** Tag field with auto/manual modes, duplicate validation, i18n (13 locales), and a fix for a `ReferenceError` on the first keystroke in the Tag field. - **Backend:** `PropagateInboundTagRename` and `RemoveInboundTagReferences` update routing rules and loopback outbound `settings.inboundTag` on inbound update/delete. - **Restart signalling:** `UpdateInbound` uses a named `needRestart` return so the post-commit routing sync correctly tells callers to restart Xray when the template changes. - **Tests:** Unit tests (including `UpdateInbound` integration), live DB e2e tests (`-tags=e2e`), and manual browser verification against a running panel. **Diff:** 20 files, +1,240 / −26 lines ## Motivation Routing rules reference inbound tags via `inboundTag`. Renaming or deleting an inbound without updating those rules leaves stale references. This PR keeps the Xray template consistent automatically, including: - **Multi-condition rules** — e.g. `inboundTag` + `domain` - **Dual-tag rules** — e.g. two values in `inboundTag` Without the `needRestart` fix, routing rules in `xrayTemplateConfig` would update on tag rename but Xray could keep running with stale routing because the deferred sync ran after the return value was already captured. ## Changes ### Frontend `frontend/src/pages/inbounds/form/InboundFormModal.tsx` | Mode | Behavior | |------|----------| | **Auto** | Empty field → submits `tag: ""` → panel auto-assigns (`in-{port}-tcp`, etc.) | | **Manual** | Custom tag with duplicate check against existing inbounds | **Bug fix:** `currentTagInput` is defined before the `tagIsAuto` `useMemo` (fixes crash on first keystroke). ### Backend | File | Role | |------|------| | `xray_setting_routing_sync.go` | Routing + loopback outbound sync helpers | | `inbound.go` | Hooks in `UpdateInbound` (rename) and `DelInbound` (delete cleanup); named `needRestart` return for deferred sync | | `routing_sync_e2e_live_test.go` | Live DB e2e tests (`//go:build e2e`) | | `routing_sync_e2e_seed_test.go` | Template seed helpers for manual/e2e runs (`//go:build e2e`) | Also preserves the existing auto tag on edit when port/transport is unchanged. ### i18n New keys under `pages.inbounds.form`: `tag`, `tagHelp`, `tagPlaceholder`, `tagDuplicate`, `tagAutoPreview` (13 locales). ## Routing sync behavior | Event | Inbound-only rule | Multi-condition (`inboundTag` + `domain`) | Dual-tag (`inboundTag` × 2) | |-------|-------------------|-------------------------------------------|------------------------------| | **Rename** | Tag updated | Tag updated; domain kept | Matched tag updated | | **Clear tag → auto** | Tag → `in-{port}-tcp` | Tag → auto; domain kept | Custom → auto; other tag kept | | **Delete** | Rule removed | `inboundTag` stripped; domain kept | Deleted tag removed; other kept | ## Testing ### Automated **Unit tests** — all pass: ```bash go test ./internal/web/service/ -run 'PropagateInboundTag|RemoveInboundTag|UpdateInbound_Propagates|DelInbound_Removes' ``` | Test | What it verifies | |------|------------------| | `PropagateInboundTagRename_*` | Routing rules and loopback outbounds updated on rename | | `RemoveInboundTagReferences_*` | Inbound-only rules removed; multi-condition and dual-tag rules trimmed correctly | | `UpdateInbound_PropagatesRoutingRuleOnTagRename` | Manual tag rename via `UpdateInbound` updates routing **and** returns `needRestart=true` | | `DelInbound_RemovesInboundOnlyRoutingRule` | Delete path removes stale inbound-only rules | **Live DB e2e** (`-tags=e2e`, requires `x-ui/x-ui.db`): ```bash go test ./internal/web/service/ -tags=e2e -run TestLiveRoutingSync -v ``` | Test | What it verifies | |------|------------------| | `RenameAndDelete` | Rename propagates to all rule shapes; delete cleans multi-condition rules | | `CustomToAutoTag` | Clearing custom tag → auto tag updates routing; delete still cleans correctly | | `TemplateJSONValid` | Template stays valid JSON after mutations | **Frontend:** inbound form modal tests added in `inbound-form-modal.test.tsx`. ### Manual browser E2E Panel at `http://127.0.0.1:2053`, **Xray Configs → Routing Rules** tab. Seeded template: api rule + inbound-only direct + `example.com` blocked (multi-condition) + dual-tag proxy. | Scenario | Result | |----------|--------| | Tag field — type, custom save, empty → auto | Pass (no crash) | | Rename custom tag → check routing | All 3 rule types updated; no stale tags | | Delete inbound | Direct rule gone; domain rule kept without tag; dual rule keeps other tag | | Clear custom tag → auto-generate | Routing follows `in-{port}-tcp` on all rules including multi-condition | | Delete after auto-tag | Same cleanup as delete scenario | **Seed helpers** (optional, panel stopped): ```bash go test ./internal/web/service/ -tags=e2e -run TestLiveRoutingSync_Seed -v -count=1 ``` ## Test plan (reviewer) - [ ] Empty tag → auto-assign on create/edit - [ ] Custom tag save + duplicate validation - [ ] Rename tag → routing rules update (direct, multi-condition, dual-tag) - [ ] Rename tag → Xray restarts (or hot-reload) so routing takes effect - [ ] Clear custom tag → auto tag + routing sync - [ ] Delete inbound → stale rules cleaned per table above - [ ] `go test ./internal/web/service/ -run 'PropagateInboundTag|RemoveInboundTag|UpdateInbound_Propagates|DelInbound_Removes'` - [ ] _(optional)_ `go test ./internal/web/service/ -tags=e2e -run TestLiveRoutingSync -v` ## Commits 1. `4533b1cf` — feat(inbounds): add optional tag field and sync routing on tag changes 2. `57e7822e` — fix(inbounds): tag field crash and add live routing sync e2e tests 3. `677fa5d4` — fix(inbounds): return needRestart after deferred routing tag sync ## Files changed - `frontend/src/pages/inbounds/form/InboundFormModal.tsx` - `frontend/src/test/inbound-form-modal.test.tsx` - `internal/web/service/inbound.go` - `internal/web/service/xray_setting_routing_sync.go` - `internal/web/service/xray_setting_routing_sync_test.go` - `internal/web/service/routing_sync_e2e_live_test.go` *(new, `//go:build e2e`)* - `internal/web/service/routing_sync_e2e_seed_test.go` *(new, `//go:build e2e`)* - `internal/web/translation/*.json` (13 locales) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 04:04:37 +07:00
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#5864
No description provided.