[PR #4599] [MERGED] feat: complete Zod migration of frontend + bulk client batching #5722

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

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/4599
Author: @MHSanaei
Created: 5/26/2026
Status: ✅ Merged
Merged: 5/27/2026
Merged by: @MHSanaei

Base: main ← Head: feat/frontend-zod-validation


📝 Commits (10+)

  • 6846fac feat(frontend): add Zod runtime validation at API boundary
  • d00ddc3 feat(frontend): extend Zod validation to remaining query/mutation hooks
  • c16fb93 fix(frontend): allow null slices in client/summary schemas
  • 2cd2085 fix(vite): treat /panel/xray as SPA page, not API root
  • 6bbc9f6 feat(frontend): drive form validation from Zod schemas
  • 75b0a21 chore(frontend): silence swagger-ui-react peer-dep warnings on React 19
  • 2d55b3b fix(vite): bypass es-toolkit CJS shim for recharts deep imports
  • a3012da feat(frontend): migrate five secondary form modals to Zod schemas
  • 4ecbb0e feat(frontend): block invalid settings saves with Zod pre-save check
  • 9cf3523 feat(frontend): schema-guard Inbound and Outbound form submits

📊 Changes

250 files changed (+24329 additions, -12090 deletions)

View changed files

📝 .github/workflows/ci.yml (+6 -0)
📝 database/model/model.go (+79 -18)
📝 database/model/model_test.go (+0 -18)
📝 frontend/README.md (+167 -49)
📝 frontend/eslint.config.js (+6 -0)
➕ frontend/eslint.deprecated.config.js (+26 -0)
📝 frontend/package-lock.json (+678 -315)
📝 frontend/package.json (+18 -6)
📝 frontend/public/openapi.json (+137 -1)
📝 frontend/src/api/queries/useAllSettings.ts (+14 -12)
📝 frontend/src/api/queries/useNodeMutations.ts (+16 -21)
📝 frontend/src/api/queries/useNodesQuery.ts (+7 -34)
📝 frontend/src/api/queries/useStatusQuery.ts (+4 -1)
📝 frontend/src/components/FinalMaskForm.tsx (+621 -604)
➕ frontend/src/components/HeaderMapEditor.tsx (+141 -0)
📝 frontend/src/env.d.ts (+1 -0)
➕ frontend/src/generated/types.ts (+359 -0)
➕ frontend/src/generated/zod.ts (+380 -0)
📝 frontend/src/hooks/useClients.ts (+106 -109)
📝 frontend/src/hooks/useDatepicker.ts (+5 -5)

...and 80 more files

📄 Description

Summary

  • Frontend Zod migration: retired the class-based xray model layer (frontend/src/models/inbound.ts, outbound.ts — ~5,750 LoC of [key: string]: any) in favor of Zod schemas as the single source of truth. All form modals are rewritten on Pattern A (AntD Form.useForm + per-field antdRule(schema.shape.field)).
  • Bulk client APIs: new POST /panel/api/clients/bulkDel and /bulkCreate endpoints with per-inbound batching. The frontend bulk-add and bulk-delete flows now post a single request instead of fanning out N round-trips that raced on the shared inbound settings JSON.
  • xray docs alignment: finalmask, sockopt, DNS, Balancer, Rule schemas verified field-by-field against the xray-core documentation and backed by golden fixture snapshots in Vitest.

Major themes

Zod migration (Steps 1–5 of the migration spec)

  • frontend/src/schemas/{primitives,api,forms,protocols,security,stream,protocols/inbound,protocols/outbound}/ — new organized schema tree.
  • frontend/src/lib/xray/ — pure functions that replaced the class methods: link generation (inbound/outbound), defaults factories, headers, JSON helpers, form adapters, protocol capability predicates.
  • frontend/src/generated/{types.ts,zod.ts} — Go codegen (tools/openapigen/) emits backend-aligned schemas; do not edit by hand.
  • models/inbound.ts + models/outbound.ts deleted at Step 5.

Form pattern unification

All non-trivial modals migrated to Pattern A:

  • InboundFormModal, OutboundFormModal (atomic swap; previous files retired)
  • NodeFormModal, BalancerFormModal, DnsServerModal, RuleFormModal, CustomGeoFormModal
  • ClientFormModal, ClientBulkAddModal, ClientBulkAdjustModal
  • LoginPage, TwoFactorModal

safeParse-on-submit replaced with await form.validateFields(). useRef<any> and file-level eslint-disable @typescript-eslint/no-explicit-any removed across these files.

Bulk client endpoints

  • POST /panel/api/clients/bulkDel { emails, keepTraffic } → groups emails by inbound, performs one JSON read-modify-write per inbound, batches DB deletes (ClientInbound/ClientTraffic/InboundClientIps/ClientRecord) with WHERE … IN (…).
  • POST /panel/api/clients/bulkCreate [{ client, inboundIds }, …] → sequential server-side iteration through the same Create path single-add uses; heterogeneous batches stay valid in one round-trip.
  • BulkAdjust rewritten with the same per-inbound batching. Local xray runtime calls skipped (the RemoveUser+AddUser payload does not include totalGB/expiryTime, so it was a no-op that flapped active users). Remote nodes still receive rt.UpdateUser.
  • Skip+report semantics: per-email failures are returned in Skipped[] and processing continues for the rest.

xray docs alignment

  • finalmask: removed cubic from QUIC congestion, added bbrProfile, switched brutalUp/Down to string, tightened ranges, added sudoku mask, added Address_Port_Strategy/HappyEyeballs/CustomSockopt schemas.
  • sockopt: tcpFastOpen accepts bool or int, domainStrategy default fixed to AsIs, tcpKeepAliveInterval/Idle defaults fixed to 45/45, casing on Address_Port_Strategy enum values fixed.
  • DNS: new DnsObjectSchema (queryStrategy, hosts/servers, disableCache/Fallback, useSystemHosts, serveStale, etc.); DnsServerObject preprocesses legacy expectIPs → expectedIPs alias.
  • Routing: RuleObjectSchema (16 fields incl. webhook/protocol enums), BalancerObjectSchema + BalancerStrategySettingsSchema (least-ping/least-load).

Test infrastructure

  • Vitest config (frontend/vitest.config.ts) with auto-discovery via import.meta.glob.
  • Golden fixtures: frontend/src/test/golden/fixtures/ + frontend/src/test/{finalmask,sockopt,dns,balancer,rule,stream,…}.test.ts. Snapshots regenerate via vitest run -u.
  • Backend web/middleware/validate.go + tests for boundary validation.
  • CI workflow now runs typecheck and test in addition to lint/build.

Lint hardening

frontend/eslint.config.js: @typescript-eslint/no-explicit-any: error enforced.

Test plan

  • npm run typecheck clean
  • npm run lint clean
  • npm run test — 324/324 passing
  • go build ./... clean
  • go vet ./... clean
  • go test ./web/service/ passing
  • Manual smoke per protocol: create / edit / share-link / delete for vless, vmess, trojan, shadowsocks, wireguard, hysteria2, http
  • Connect a real xray client to a newly-created inbound and verify traffic
  • Backup → restore the database; verify inbounds round-trip
  • Bulk delete 200 clients (timing comparison vs. pre-batching)
  • Bulk adjust 200 clients (timing comparison vs. pre-batching)
  • Bulk add 200 clients (timing comparison vs. pre-batching)

🔄 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/4599 **Author:** [@MHSanaei](https://github.com/MHSanaei) **Created:** 5/26/2026 **Status:** ✅ Merged **Merged:** 5/27/2026 **Merged by:** [@MHSanaei](https://github.com/MHSanaei) **Base:** `main` ← **Head:** `feat/frontend-zod-validation` --- ### 📝 Commits (10+) - [`6846fac`](https://github.com/MHSanaei/3x-ui/commit/6846fac1ccd27730cd9a2ce1e82006fca38b834a) feat(frontend): add Zod runtime validation at API boundary - [`d00ddc3`](https://github.com/MHSanaei/3x-ui/commit/d00ddc3f5823bea2fc3a81bebd6b919f52d004ee) feat(frontend): extend Zod validation to remaining query/mutation hooks - [`c16fb93`](https://github.com/MHSanaei/3x-ui/commit/c16fb9389925f1ad240ee17a3d5cf2bfb7f12d50) fix(frontend): allow null slices in client/summary schemas - [`2cd2085`](https://github.com/MHSanaei/3x-ui/commit/2cd2085b75bb5ae979387d33be4e54b3ee19792e) fix(vite): treat /panel/xray as SPA page, not API root - [`6bbc9f6`](https://github.com/MHSanaei/3x-ui/commit/6bbc9f6769fc0d6a29e810d972c3edff2f80b6c3) feat(frontend): drive form validation from Zod schemas - [`75b0a21`](https://github.com/MHSanaei/3x-ui/commit/75b0a2198797f795995551b36b2b647364b15d90) chore(frontend): silence swagger-ui-react peer-dep warnings on React 19 - [`2d55b3b`](https://github.com/MHSanaei/3x-ui/commit/2d55b3b663720d5ca075a4ffaff99517d92e877b) fix(vite): bypass es-toolkit CJS shim for recharts deep imports - [`a3012da`](https://github.com/MHSanaei/3x-ui/commit/a3012daa8f370804ceb7022648562513ede0b78b) feat(frontend): migrate five secondary form modals to Zod schemas - [`4ecbb0e`](https://github.com/MHSanaei/3x-ui/commit/4ecbb0e55f4352587e323c1e69721e861afe7515) feat(frontend): block invalid settings saves with Zod pre-save check - [`9cf3523`](https://github.com/MHSanaei/3x-ui/commit/9cf35234a5b26a73833e50140dd1bac31023aae5) feat(frontend): schema-guard Inbound and Outbound form submits ### 📊 Changes **250 files changed** (+24329 additions, -12090 deletions) <details> <summary>View changed files</summary> 📝 `.github/workflows/ci.yml` (+6 -0) 📝 `database/model/model.go` (+79 -18) 📝 `database/model/model_test.go` (+0 -18) 📝 `frontend/README.md` (+167 -49) 📝 `frontend/eslint.config.js` (+6 -0) ➕ `frontend/eslint.deprecated.config.js` (+26 -0) 📝 `frontend/package-lock.json` (+678 -315) 📝 `frontend/package.json` (+18 -6) 📝 `frontend/public/openapi.json` (+137 -1) 📝 `frontend/src/api/queries/useAllSettings.ts` (+14 -12) 📝 `frontend/src/api/queries/useNodeMutations.ts` (+16 -21) 📝 `frontend/src/api/queries/useNodesQuery.ts` (+7 -34) 📝 `frontend/src/api/queries/useStatusQuery.ts` (+4 -1) 📝 `frontend/src/components/FinalMaskForm.tsx` (+621 -604) ➕ `frontend/src/components/HeaderMapEditor.tsx` (+141 -0) 📝 `frontend/src/env.d.ts` (+1 -0) ➕ `frontend/src/generated/types.ts` (+359 -0) ➕ `frontend/src/generated/zod.ts` (+380 -0) 📝 `frontend/src/hooks/useClients.ts` (+106 -109) 📝 `frontend/src/hooks/useDatepicker.ts` (+5 -5) _...and 80 more files_ </details> ### 📄 Description ## Summary - **Frontend Zod migration**: retired the class-based xray model layer (`frontend/src/models/inbound.ts`, `outbound.ts` — ~5,750 LoC of `[key: string]: any`) in favor of Zod schemas as the single source of truth. All form modals are rewritten on Pattern A (AntD `Form.useForm` + per-field `antdRule(schema.shape.field)`). - **Bulk client APIs**: new `POST /panel/api/clients/bulkDel` and `/bulkCreate` endpoints with per-inbound batching. The frontend bulk-add and bulk-delete flows now post a single request instead of fanning out N round-trips that raced on the shared inbound settings JSON. - **xray docs alignment**: finalmask, sockopt, DNS, Balancer, Rule schemas verified field-by-field against the xray-core documentation and backed by golden fixture snapshots in Vitest. ## Major themes ### Zod migration (Steps 1–5 of the migration spec) - `frontend/src/schemas/{primitives,api,forms,protocols,security,stream,protocols/inbound,protocols/outbound}/` — new organized schema tree. - `frontend/src/lib/xray/` — pure functions that replaced the class methods: link generation (inbound/outbound), defaults factories, headers, JSON helpers, form adapters, protocol capability predicates. - `frontend/src/generated/{types.ts,zod.ts}` — Go codegen (`tools/openapigen/`) emits backend-aligned schemas; do not edit by hand. - `models/inbound.ts` + `models/outbound.ts` deleted at Step 5. ### Form pattern unification All non-trivial modals migrated to Pattern A: - `InboundFormModal`, `OutboundFormModal` (atomic swap; previous files retired) - `NodeFormModal`, `BalancerFormModal`, `DnsServerModal`, `RuleFormModal`, `CustomGeoFormModal` - `ClientFormModal`, `ClientBulkAddModal`, `ClientBulkAdjustModal` - `LoginPage`, `TwoFactorModal` `safeParse`-on-submit replaced with `await form.validateFields()`. `useRef<any>` and file-level `eslint-disable @typescript-eslint/no-explicit-any` removed across these files. ### Bulk client endpoints - `POST /panel/api/clients/bulkDel { emails, keepTraffic }` → groups emails by inbound, performs one JSON read-modify-write per inbound, batches DB deletes (`ClientInbound`/`ClientTraffic`/`InboundClientIps`/`ClientRecord`) with `WHERE … IN (…)`. - `POST /panel/api/clients/bulkCreate [{ client, inboundIds }, …]` → sequential server-side iteration through the same `Create` path single-add uses; heterogeneous batches stay valid in one round-trip. - `BulkAdjust` rewritten with the same per-inbound batching. Local xray runtime calls skipped (the `RemoveUser`+`AddUser` payload does not include `totalGB`/`expiryTime`, so it was a no-op that flapped active users). Remote nodes still receive `rt.UpdateUser`. - Skip+report semantics: per-email failures are returned in `Skipped[]` and processing continues for the rest. ### xray docs alignment - finalmask: removed `cubic` from QUIC congestion, added `bbrProfile`, switched `brutalUp/Down` to string, tightened ranges, added `sudoku` mask, added `Address_Port_Strategy`/`HappyEyeballs`/`CustomSockopt` schemas. - sockopt: `tcpFastOpen` accepts bool or int, `domainStrategy` default fixed to `AsIs`, `tcpKeepAliveInterval`/`Idle` defaults fixed to `45/45`, casing on `Address_Port_Strategy` enum values fixed. - DNS: new `DnsObjectSchema` (queryStrategy, hosts/servers, disableCache/Fallback, useSystemHosts, serveStale, etc.); `DnsServerObject` preprocesses legacy `expectIPs` → `expectedIPs` alias. - Routing: `RuleObjectSchema` (16 fields incl. webhook/protocol enums), `BalancerObjectSchema` + `BalancerStrategySettingsSchema` (least-ping/least-load). ### Test infrastructure - Vitest config (`frontend/vitest.config.ts`) with auto-discovery via `import.meta.glob`. - Golden fixtures: `frontend/src/test/golden/fixtures/` + `frontend/src/test/{finalmask,sockopt,dns,balancer,rule,stream,…}.test.ts`. Snapshots regenerate via `vitest run -u`. - Backend `web/middleware/validate.go` + tests for boundary validation. - CI workflow now runs `typecheck` and `test` in addition to `lint`/`build`. ### Lint hardening `frontend/eslint.config.js`: `@typescript-eslint/no-explicit-any: error` enforced. ## Test plan - [x] `npm run typecheck` clean - [x] `npm run lint` clean - [x] `npm run test` — 324/324 passing - [x] `go build ./...` clean - [x] `go vet ./...` clean - [x] `go test ./web/service/` passing - [x] Manual smoke per protocol: create / edit / share-link / delete for vless, vmess, trojan, shadowsocks, wireguard, hysteria2, http - [x] Connect a real xray client to a newly-created inbound and verify traffic - [ ] Backup → restore the database; verify inbounds round-trip - [x] Bulk delete 200 clients (timing comparison vs. pre-batching) - [x] Bulk adjust 200 clients (timing comparison vs. pre-batching) - [x] Bulk add 200 clients (timing comparison vs. pre-batching) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 04:03: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#5722
No description provided.