mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[PR #4567] [CLOSED] feat(frontend): introduce Zod for runtime validation #5718
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#5718
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/4567
Author: @MHSanaei
Created: 5/25/2026
Status: ❌ Closed
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
59 files changed (+3145 additions, -804 deletions)
View changed files
📝
database/model/model.go(+8 -8)📝
frontend/package-lock.json(+156 -155)📝
frontend/package.json(+11 -2)📝
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/generated/types.ts(+359 -0)➕
frontend/src/generated/zod.ts(+380 -0)📝
frontend/src/hooks/useClients.ts(+59 -95)📝
frontend/src/hooks/useDatepicker.ts(+5 -5)📝
frontend/src/hooks/useXraySetting.ts(+40 -60)📝
frontend/src/pages/clients/ClientBulkAddModal.tsx(+6 -23)📝
frontend/src/pages/clients/ClientBulkAdjustModal.tsx(+9 -4)📝
frontend/src/pages/clients/ClientFormModal.tsx(+22 -6)📝
frontend/src/pages/inbounds/InboundFormModal.tsx(+15 -1)📝
frontend/src/pages/inbounds/useInbounds.ts(+19 -31)📝
frontend/src/pages/index/CustomGeoFormModal.tsx(+7 -25)📝
frontend/src/pages/index/CustomGeoSection.tsx(+1 -1)📝
frontend/src/pages/index/IndexPage.tsx(+2 -2)...and 39 more files
📄 Description
Summary
Adds Zod 4 as the source of truth for runtime validation across the frontend, in three layers:
parseMsg(msg, schema, context)validates ~20 endpoint responses against schemas (status, nodes, clients, inbounds, xray, settings, auth). On drift, logs a[zod] ...console warning and passes the payload through unchanged so users never see a broken UI from a backend metadata change.LoginPage,NodeFormModal,ClientFormModal,ClientBulkAddModal,ClientBulkAdjustModal,BalancerFormModal,RuleFormModal,CustomGeoFormModal,TwoFactorModal).NodeFormModalis the full AntDForm.useForm+antdRuleshowcase; others use the lightersafeParse-on-submit pattern that keeps existing controlled-component state intact.AllSettingSchemanow carries the real ranges and path rules (ports 1-65535,tgCpu0-100,subUpdates1-168 h,webBasePath/subPathmust start with/, etc.).SettingsPageruns the full schema against the draft before save and surfaces the first issue.Two unrelated infra fixes hitched on the same branch because they were uncovered during dev-server testing:
fix(vite): treat /panel/xray as SPA page— the dev-server bypass classified/panel/xrayas an API path because of an exact-match againstpanel/xray/(the API prefix with trailing slash stripped). On reload,/panel/xraygot proxied to the Go backend, which returned the embedded builtindex.htmland broke asset URLs.fix(vite): bypass es-toolkit CJS shim for recharts deep imports—es-toolkit's./compat/*exports map only declares a CJS condition, and the shim uses arequire_X.Ypattern that both Vite's optimizer (Rolldown in Vite 8) and the prod build mishandle, crashing every recharts route withrequire_isUnsafeProperty is not a function. A smallenforce: 'pre'plugin emits a virtual ESM module peres-toolkit/compat/<name>import that re-exports the named symbol as default — works in dev (registered viaoptimizeDeps.rolldownOptions.plugins) and prod (top-level plugin).One small dep-compat chore: npm
overridesto silenceswagger-ui-react's React-19 peer-dep warnings, including the nested-override syntax ("react-debounce-input": { "react": "^19.0.0" }) for the wedged 2022 package that has no maintained successor.Commits
Test plan
npm run typecheck && npm run lint && npm run buildfromfrontend/— all clean.npm run dev, log in, leave the dashboard open ~30s. Console should show no[zod] ...warnings./panel/api/server/statusto drop a top-level field. UI should keep rendering and exactly one[zod] server/status response failed validationwarning should appear.antdRulereaches i18next).webPortto70000and click Save — toast showswebPort: Number must be less than or equal to 65535, request never goes out. Reset to a valid port — save succeeds./panel/api-docs, expand a JSON response (react-inspectorv9 path) and toggle the "Try it out" textarea (react-debounce-inputpath) — both should work.Non-goals (deferred to follow-ups)
InboundFormModal(2248 lines) andOutboundFormModal(1471 lines) — the largest forms still use the manualif (!form.x)pattern.Status,AllSetting,DBInbound) stay; schemas validate input but the classes are still the runtime wrapper.scripts/build-openapi.mjs.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.