mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[PR #6127] [MERGED] refactor(ui): share one onNumber handler for numeric setting inputs #6090
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#6090
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/6127
Author: @PathGao
Created: 7/28/2026
Status: ✅ Merged
Merged: 7/28/2026
Merged by: @MHSanaei
Base:
main← Head:refactor-onnumber-helper📝 Commits (2)
dc4c18brefactor(ui): share one onNumber handler for numeric setting inputs26ca7dbrefactor(ui): fold the remaining hand-rolled numeric guards into onNumber📊 Changes
12 files changed (+108 additions, -19 deletions)
View changed files
📝
frontend/src/pages/settings/EmailTab.tsx(+2 -1)📝
frontend/src/pages/settings/GeneralTab.tsx(+10 -9)📝
frontend/src/pages/settings/SubscriptionFormatsTab.tsx(+3 -2)📝
frontend/src/pages/settings/SubscriptionGeneralTab.tsx(+3 -2)📝
frontend/src/pages/xray/balancers/ObservatorySettingsTab.tsx(+2 -1)📝
frontend/src/pages/xray/dns/DnsTab.tsx(+2 -1)📝
frontend/src/pages/xray/dns/useDnsColumns.tsx(+3 -1)📝
frontend/src/pages/xray/outbounds/OutboundsTab.tsx(+3 -2)➕
frontend/src/test/general-tab.test.tsx(+40 -0)➕
frontend/src/test/on-number.test.ts(+23 -0)📝
frontend/src/test/subscription-general-tab.test.tsx(+1 -0)➕
frontend/src/utils/onNumber.ts(+16 -0)📄 Description
Summary
Extract the null-safe InputNumber change handling introduced with the cleared-port fix (#6121) into a shared
onNumber(apply)helper, and convert all eighteen null-unsafe numeric onChange sites in the settings and xray pages to it (sixteenNumber(v) || 0sites, the hand-rolled guard on the observatory sampling field, and the smtp port's undocumented fallback — see review thread). Follow-up to the automated review on #6121, which flagged the idiom as the drift-prone root pattern.Why
Ant Design's InputNumber reports a cleared field as
null. TheNumber(v) || 0idiom turns that into a stored0— or, combined withmin={N}, into a silently clamped value, which is exactly how the cleared-port bug happened. #6121 fixed the three port fields with an inlineif (v != null)guard, but the same idiom remained at sixteen other call sites, so every new numeric setting copies whichever neighbor it was pasted from.onNumber(apply)centralizes the semantic: null / empty / NaN change events are ignored (the field snaps back to its stored value on blur), numeric events — including0typed explicitly and stringMode strings — pass through unchanged.One site intentionally keeps a different semantic and is left alone: the Telegram notify interval clamps through
Math.max(1, …), a visible floor. The smtp port's|| 587fallback was initially kept as "deliberate", but the review correctly noted nothing documents that intent and clearing silently overwrites a configured non-standard port — it is now converted like the other port fields (a one-line revert if the maintainer wants the reset affordance back).Type of change
Areas affected
How was this tested?
frontend/src/test/on-number.test.ts): numeric pass-through including zero and negatives; null/undefined/NaN ignored. The helper is number-only by design (nostringModeinput exists in the repo).general-tab.test.tsx: clearingpageSizecalls nothing and the input snaps back to the stored value on blur; typing0forwards{ pageSize: 0 }.subscription-general-tab.test.tsx) pass through the helper, now also asserting the blur snap-back display value.npm run lint,npm run typecheck,npm run buildpass.Screenshots / recordings
N/A — no visual change; only what a cleared field writes.
Breaking changes
None.
Behavior note for reviewers: for the thirteen non-port fields (e.g.
sessionMaxAge,pageSize, DNSpoolSize, outbound observatory interval), clearing the input previously stored0; it now keeps the stored value, consistent with the port fields. Zero remains reachable by typing0. If a maintainer prefers the old store-zero behavior for any specific field, that site can trivially opt out by not using the helper.Checklist
go build ./...and the test suite pass locally.npm run lint,npm run typecheck, andnpm run buildpass.🤖 Generated with Claude Code
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.