[PR #5859] [MERGED] Frontend dev tooling (Husky, lint-staged, MSW, Storybook) + full React Hook Form migration #6010

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

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/5859
Author: @MHSanaei
Created: 7/8/2026
Status: ✅ Merged
Merged: 7/8/2026
Merged by: @MHSanaei

Base: main ← Head: feat/rhf-migration-and-dev-tooling


📝 Commits (10+)

  • 1c9b751 chore(frontend): add husky + lint-staged pre-commit gate
  • bcb3742 test(frontend): add MSW request mocking
  • 1a6efff chore(frontend): add Storybook + component stories
  • d8755d2 feat(frontend): add React Hook Form primitives
  • 3b98f4c refactor(frontend): migrate Pattern-B leaf forms to React Hook Form
  • 807407f refactor(frontend): migrate LoginPage to React Hook Form
  • 42d1f57 refactor(frontend): migrate ClientFormModal to React Hook Form
  • e09bc7b refactor(frontend): migrate Node and DNS modals to React Hook Form
  • 15c5878 refactor(frontend): migrate HostFormModal to React Hook Form
  • 904815a refactor(frontend): migrate OutboundFormModal + fragments to React Hook Form

📊 Changes

98 files changed (+9824 additions, -5417 deletions)

View changed files

📝 .github/workflows/docs-ci.yml (+3 -0)
📝 frontend/.gitignore (+1 -0)
➕ frontend/.husky/pre-commit (+1 -0)
➕ frontend/.storybook/main.ts (+25 -0)
➕ frontend/.storybook/preview.tsx (+60 -0)
📝 frontend/CLAUDE.md (+11 -4)
📝 frontend/package-lock.json (+3803 -334)
📝 frontend/package.json (+24 -2)
➕ frontend/public/mockServiceWorker.js (+349 -0)
➕ frontend/src/components/clients/ClientSpeedTag.stories.tsx (+21 -0)
➕ frontend/src/components/clients/ConfigBlock.stories.tsx (+29 -0)
➕ frontend/src/components/feedback/PromptModal.stories.tsx (+70 -0)
➕ frontend/src/components/feedback/TextModal.stories.tsx (+51 -0)
➕ frontend/src/components/form/rhf/FormField.tsx (+93 -0)
➕ frontend/src/components/form/rhf/index.ts (+5 -0)
➕ frontend/src/components/form/rhf/normalizeAntdOnChange.ts (+10 -0)
➕ frontend/src/components/form/rhf/rhfZodValidate.ts (+9 -0)
➕ frontend/src/components/form/rhf/toDotted.ts (+5 -0)
➕ frontend/src/components/form/rhf/useZodForm.ts (+18 -0)
➕ frontend/src/components/ui/InfinityIcon.stories.tsx (+27 -0)

...and 78 more files

📄 Description

Summary

Adds four frontend developer-tooling additions and migrates all panel forms from Ant Design's Form store to React Hook Form (RHF). Ant Design components stay; only the form-state layer changes. 14 focused commits; every commit is green (typecheck, ESLint, 727 vitest tests, build).

Dev tooling

  • Husky + lint-staged — pre-commit gate running eslint --fix on staged frontend TS/TSX. The hook installs from the repo root into frontend/.husky (the only package.json is in frontend/).
  • MSW — request-level mocking. A node setupServer exercises the real http-init.ts pipeline (CSRF acquisition, 403 refetch-and-retry) alongside the existing HttpUtil spies, so the current tests are untouched. Browser worker generated for Storybook/dev.
  • Storybook 10 (React-Vite builder, compatible with the pinned Vite 8.1.3 / React 19). Decorators mirror the vitest component harness (AntD ConfigProvider + light/dark toolbar + en-US i18next); main.ts neutralizes the app config's multi-entry input / renderBuiltUrl / shared outDir so build-storybook can never clobber internal/web/dist. Seed stories across the presentational library.
  • React Hook Form primitives in src/components/form/rhf/ — FormField (a Controller wrapping an AntD Form.Item shell), useZodForm (zodResolver, Zod 4), rhfZodValidate.

React Hook Form migration

Every form moved to RHF while preserving exact submit behaviour (same safeParse, same toast, same wire payload):

  • Pattern-B leaf modals (client bulk ops, routing rule, balancer, WARP, Nord)
  • LoginPage, ClientFormModal
  • Node / DNS / Host modals
  • OutboundFormModal + all outbound fragments, and the host json-form wrappers that reuse them
  • InboundFormModal (the 1054-line giant) + all inbound fragments

Shared config editors are not rewritten: the 1180-line FinalMaskForm, SniffingFields, and CustomSockoptList stay Ant-Design-Form islands, wrapped in small value/onChange adapters (src/lib/xray/forms/fields/) and bound via a Controller (the same pattern the pre-existing HostFinalMaskForm used). HeaderMapEditor already exposes value/onChange and binds directly. The now-unused antdRule helper is removed and frontend/CLAUDE.md documents the new pattern.

Intentionally out of scope (not Form-based, left as-is): the settings tabs (control panels that live-patch allSetting), FilterDrawer, and GroupsPage.

Verification

  • typecheck, lint, build, and the full 727-test vitest suite pass on every commit. The golden share-link / config fixtures pass byte-for-byte, confirming identical wire output.
  • Driven live against a real build (headless Chrome): login succeeds, an inbound is created correctly, and both the network (→ws) and security (→tls) cascades persist the right streamSettings.

🔄 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/5859 **Author:** [@MHSanaei](https://github.com/MHSanaei) **Created:** 7/8/2026 **Status:** ✅ Merged **Merged:** 7/8/2026 **Merged by:** [@MHSanaei](https://github.com/MHSanaei) **Base:** `main` ← **Head:** `feat/rhf-migration-and-dev-tooling` --- ### 📝 Commits (10+) - [`1c9b751`](https://github.com/MHSanaei/3x-ui/commit/1c9b7511e6906f540f666709efc0f8cac968bdd1) chore(frontend): add husky + lint-staged pre-commit gate - [`bcb3742`](https://github.com/MHSanaei/3x-ui/commit/bcb3742e8230e601436d4343e08e0ff4fb1f9935) test(frontend): add MSW request mocking - [`1a6efff`](https://github.com/MHSanaei/3x-ui/commit/1a6efffe12bc185b8f0abf374cda81f6dcb6ab68) chore(frontend): add Storybook + component stories - [`d8755d2`](https://github.com/MHSanaei/3x-ui/commit/d8755d22b5849c6515de527a994718ecac025186) feat(frontend): add React Hook Form primitives - [`3b98f4c`](https://github.com/MHSanaei/3x-ui/commit/3b98f4c121993cd3fd7b809c22f4a8be3a7e7c1e) refactor(frontend): migrate Pattern-B leaf forms to React Hook Form - [`807407f`](https://github.com/MHSanaei/3x-ui/commit/807407fe46fbb92e2d73c1ea93363a9d9ecf1f86) refactor(frontend): migrate LoginPage to React Hook Form - [`42d1f57`](https://github.com/MHSanaei/3x-ui/commit/42d1f5743718719069e2e2cdfc5bdf19362eed13) refactor(frontend): migrate ClientFormModal to React Hook Form - [`e09bc7b`](https://github.com/MHSanaei/3x-ui/commit/e09bc7ba8278e38865cfb49f20a37a3c2fa94046) refactor(frontend): migrate Node and DNS modals to React Hook Form - [`15c5878`](https://github.com/MHSanaei/3x-ui/commit/15c58782de2749c351f4337cad859fc2d21802c3) refactor(frontend): migrate HostFormModal to React Hook Form - [`904815a`](https://github.com/MHSanaei/3x-ui/commit/904815ac203a2b10ba7a024abbb54fc23823da63) refactor(frontend): migrate OutboundFormModal + fragments to React Hook Form ### 📊 Changes **98 files changed** (+9824 additions, -5417 deletions) <details> <summary>View changed files</summary> 📝 `.github/workflows/docs-ci.yml` (+3 -0) 📝 `frontend/.gitignore` (+1 -0) ➕ `frontend/.husky/pre-commit` (+1 -0) ➕ `frontend/.storybook/main.ts` (+25 -0) ➕ `frontend/.storybook/preview.tsx` (+60 -0) 📝 `frontend/CLAUDE.md` (+11 -4) 📝 `frontend/package-lock.json` (+3803 -334) 📝 `frontend/package.json` (+24 -2) ➕ `frontend/public/mockServiceWorker.js` (+349 -0) ➕ `frontend/src/components/clients/ClientSpeedTag.stories.tsx` (+21 -0) ➕ `frontend/src/components/clients/ConfigBlock.stories.tsx` (+29 -0) ➕ `frontend/src/components/feedback/PromptModal.stories.tsx` (+70 -0) ➕ `frontend/src/components/feedback/TextModal.stories.tsx` (+51 -0) ➕ `frontend/src/components/form/rhf/FormField.tsx` (+93 -0) ➕ `frontend/src/components/form/rhf/index.ts` (+5 -0) ➕ `frontend/src/components/form/rhf/normalizeAntdOnChange.ts` (+10 -0) ➕ `frontend/src/components/form/rhf/rhfZodValidate.ts` (+9 -0) ➕ `frontend/src/components/form/rhf/toDotted.ts` (+5 -0) ➕ `frontend/src/components/form/rhf/useZodForm.ts` (+18 -0) ➕ `frontend/src/components/ui/InfinityIcon.stories.tsx` (+27 -0) _...and 78 more files_ </details> ### 📄 Description ## Summary Adds four frontend developer-tooling additions and migrates **all** panel forms from Ant Design's `Form` store to **React Hook Form** (RHF). Ant Design components stay; only the form-*state* layer changes. 14 focused commits; every commit is green (typecheck, ESLint, 727 vitest tests, build). ## Dev tooling - **Husky + lint-staged** — pre-commit gate running `eslint --fix` on staged frontend TS/TSX. The hook installs from the repo root into `frontend/.husky` (the only `package.json` is in `frontend/`). - **MSW** — request-level mocking. A node `setupServer` exercises the real `http-init.ts` pipeline (CSRF acquisition, 403 refetch-and-retry) alongside the existing `HttpUtil` spies, so the current tests are untouched. Browser worker generated for Storybook/dev. - **Storybook 10** (React-Vite builder, compatible with the pinned Vite 8.1.3 / React 19). Decorators mirror the vitest component harness (AntD `ConfigProvider` + light/dark toolbar + en-US i18next); `main.ts` neutralizes the app config's multi-entry input / `renderBuiltUrl` / shared `outDir` so `build-storybook` can never clobber `internal/web/dist`. Seed stories across the presentational library. - **React Hook Form** primitives in `src/components/form/rhf/` — `FormField` (a `Controller` wrapping an AntD `Form.Item` shell), `useZodForm` (`zodResolver`, Zod 4), `rhfZodValidate`. ## React Hook Form migration Every form moved to RHF while preserving exact submit behaviour (same `safeParse`, same toast, same wire payload): - Pattern-B leaf modals (client bulk ops, routing rule, balancer, WARP, Nord) - `LoginPage`, `ClientFormModal` - `Node` / `DNS` / `Host` modals - `OutboundFormModal` + all outbound fragments, and the host json-form wrappers that reuse them - `InboundFormModal` (the 1054-line giant) + all inbound fragments **Shared config editors are not rewritten:** the 1180-line `FinalMaskForm`, `SniffingFields`, and `CustomSockoptList` stay Ant-Design-`Form` islands, wrapped in small value/onChange adapters (`src/lib/xray/forms/fields/`) and bound via a `Controller` (the same pattern the pre-existing `HostFinalMaskForm` used). `HeaderMapEditor` already exposes value/onChange and binds directly. The now-unused `antdRule` helper is removed and `frontend/CLAUDE.md` documents the new pattern. **Intentionally out of scope** (not `Form`-based, left as-is): the settings tabs (control panels that live-patch `allSetting`), `FilterDrawer`, and `GroupsPage`. ## Verification - `typecheck`, `lint`, `build`, and the full **727-test** vitest suite pass on every commit. The golden share-link / config fixtures pass byte-for-byte, confirming identical wire output. - Driven live against a real build (headless Chrome): login succeeds, an inbound is created correctly, and both the network (→ws) and security (→tls) cascades persist the right `streamSettings`. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 04:05:44 +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#6010
No description provided.