[PR #6127] [MERGED] refactor(ui): share one onNumber handler for numeric setting inputs #6090

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

📋 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)

  • dc4c18b refactor(ui): share one onNumber handler for numeric setting inputs
  • 26ca7db refactor(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 (sixteen Number(v) || 0 sites, 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. The Number(v) || 0 idiom turns that into a stored 0 — or, combined with min={N}, into a silently clamped value, which is exactly how the cleared-port bug happened. #6121 fixed the three port fields with an inline if (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 — including 0 typed 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 || 587 fallback 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

  • Refactoring (no behavior change)
  • Bug fix (see behavior note below for the one deliberate change)

Areas affected

  • Frontend (UI / panel pages)

How was this tested?

  • New unit tests for the helper (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 (no stringMode input exists in the repo).
  • New general-tab.test.tsx: clearing pageSize calls nothing and the input snaps back to the stored value on blur; typing 0 forwards { pageSize: 0 }.
  • The #6121 regression tests (subscription-general-tab.test.tsx) pass through the helper, now also asserting the blur snap-back display value.
  • Full frontend suite: 100 test files / 906 tests pass; npm run lint, npm run typecheck, npm run build pass.

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, DNS poolSize, outbound observatory interval), clearing the input previously stored 0; it now keeps the stored value, consistent with the port fields. Zero remains reachable by typing 0. 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

  • I tested the change locally and confirmed the described behavior.
  • I added or updated tests for the new behavior (when applicable).
  • go build ./... and the test suite pass locally.
  • For frontend changes: npm run lint, npm run typecheck, and npm run build pass.
  • I updated the Wiki / README / API docs if user-facing behavior changed (not applicable — no documented behavior changes).
  • My commits follow the project's existing message style.
  • I have no unrelated changes mixed into this PR.

🤖 Generated with Claude Code


🔄 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/6127 **Author:** [@PathGao](https://github.com/PathGao) **Created:** 7/28/2026 **Status:** ✅ Merged **Merged:** 7/28/2026 **Merged by:** [@MHSanaei](https://github.com/MHSanaei) **Base:** `main` ← **Head:** `refactor-onnumber-helper` --- ### 📝 Commits (2) - [`dc4c18b`](https://github.com/MHSanaei/3x-ui/commit/dc4c18b1607a499c9fa6e54946b6bd5d4a063806) refactor(ui): share one onNumber handler for numeric setting inputs - [`26ca7db`](https://github.com/MHSanaei/3x-ui/commit/26ca7db435a9748290c0bbb86ff5a582797b0db0) refactor(ui): fold the remaining hand-rolled numeric guards into onNumber ### 📊 Changes **12 files changed** (+108 additions, -19 deletions) <details> <summary>View changed files</summary> 📝 `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) </details> ### 📄 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 (sixteen `Number(v) || 0` sites, 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`. The `Number(v) || 0` idiom turns that into a stored `0` — or, combined with `min={N}`, into a silently clamped value, which is exactly how the cleared-port bug happened. #6121 fixed the three port fields with an inline `if (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 — including `0` typed 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 `|| 587` fallback 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 - [x] Refactoring (no behavior change) - [x] Bug fix (see behavior note below for the one deliberate change) ## Areas affected - [x] Frontend (UI / panel pages) ## How was this tested? - New unit tests for the helper (`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 (no `stringMode` input exists in the repo). - New `general-tab.test.tsx`: clearing `pageSize` calls nothing and the input snaps back to the stored value on blur; typing `0` forwards `{ pageSize: 0 }`. - The #6121 regression tests (`subscription-general-tab.test.tsx`) pass through the helper, now also asserting the blur snap-back display value. - Full frontend suite: 100 test files / 906 tests pass; `npm run lint`, `npm run typecheck`, `npm run build` pass. ## 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`, DNS `poolSize`, outbound observatory interval), clearing the input previously stored `0`; it now keeps the stored value, consistent with the port fields. Zero remains reachable by typing `0`. 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 - [x] I tested the change locally and confirmed the described behavior. - [x] I added or updated tests for the new behavior (when applicable). - [x] `go build ./...` and the test suite pass locally. - [x] For frontend changes: `npm run lint`, `npm run typecheck`, and `npm run build` pass. - [x] I updated the Wiki / README / API docs if user-facing behavior changed (not applicable — no documented behavior changes). - [x] My commits follow the project's existing message style. - [x] I have no unrelated changes mixed into this PR. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 04:06:17 +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#6090
No description provided.