mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 19:11:53 +07:00
[PR #4599] [MERGED] feat: complete Zod migration of frontend + bulk client batching #5722
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#5722
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?
📋 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+)
6846facfeat(frontend): add Zod runtime validation at API boundaryd00ddc3feat(frontend): extend Zod validation to remaining query/mutation hooksc16fb93fix(frontend): allow null slices in client/summary schemas2cd2085fix(vite): treat /panel/xray as SPA page, not API root6bbc9f6feat(frontend): drive form validation from Zod schemas75b0a21chore(frontend): silence swagger-ui-react peer-dep warnings on React 192d55b3bfix(vite): bypass es-toolkit CJS shim for recharts deep importsa3012dafeat(frontend): migrate five secondary form modals to Zod schemas4ecbb0efeat(frontend): block invalid settings saves with Zod pre-save check9cf3523feat(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/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 (AntDForm.useForm+ per-fieldantdRule(schema.shape.field)).POST /panel/api/clients/bulkDeland/bulkCreateendpoints 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.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.tsdeleted 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,CustomGeoFormModalClientFormModal,ClientBulkAddModal,ClientBulkAdjustModalLoginPage,TwoFactorModalsafeParse-on-submit replaced withawait form.validateFields().useRef<any>and file-leveleslint-disable @typescript-eslint/no-explicit-anyremoved 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) withWHERE … IN (…).POST /panel/api/clients/bulkCreate [{ client, inboundIds }, …]→ sequential server-side iteration through the sameCreatepath single-add uses; heterogeneous batches stay valid in one round-trip.BulkAdjustrewritten with the same per-inbound batching. Local xray runtime calls skipped (theRemoveUser+AddUserpayload does not includetotalGB/expiryTime, so it was a no-op that flapped active users). Remote nodes still receivert.UpdateUser.Skipped[]and processing continues for the rest.xray docs alignment
cubicfrom QUIC congestion, addedbbrProfile, switchedbrutalUp/Downto string, tightened ranges, addedsudokumask, addedAddress_Port_Strategy/HappyEyeballs/CustomSockoptschemas.tcpFastOpenaccepts bool or int,domainStrategydefault fixed toAsIs,tcpKeepAliveInterval/Idledefaults fixed to45/45, casing onAddress_Port_Strategyenum values fixed.DnsObjectSchema(queryStrategy, hosts/servers, disableCache/Fallback, useSystemHosts, serveStale, etc.);DnsServerObjectpreprocesses legacyexpectIPs→expectedIPsalias.RuleObjectSchema(16 fields incl. webhook/protocol enums),BalancerObjectSchema+BalancerStrategySettingsSchema(least-ping/least-load).Test infrastructure
frontend/vitest.config.ts) with auto-discovery viaimport.meta.glob.frontend/src/test/golden/fixtures/+frontend/src/test/{finalmask,sockopt,dns,balancer,rule,stream,…}.test.ts. Snapshots regenerate viavitest run -u.web/middleware/validate.go+ tests for boundary validation.typecheckandtestin addition tolint/build.Lint hardening
frontend/eslint.config.js:@typescript-eslint/no-explicit-any: errorenforced.Test plan
npm run typecheckcleannpm run lintcleannpm run test— 324/324 passinggo build ./...cleango vet ./...cleango test ./web/service/passing🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.