[PR #5525] [MERGED] fix(inbounds): accept null rewritePort in tunnel settings (#5516) #5912

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

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/5525
Author: @rqzbeh
Created: 6/23/2026
Status: ✅ Merged
Merged: 6/24/2026
Merged by: @MHSanaei

Base: main ← Head: fix/tunnel-rewriteport-null


📝 Commits (1)

  • 34f37de fix(inbounds): accept null rewritePort in tunnel settings (#5516)

📊 Changes

2 files changed (+32 additions, -1 deletions)

View changed files

📝 frontend/src/schemas/protocols/inbound/tunnel.ts (+6 -1)
➕ frontend/src/test/tunnel-rewriteport.test.ts (+26 -0)

📄 Description

Summary

Fix a validation crash when the tunnel inbound's Rewrite port field is cleared. Closes #5516.

Why

When the Rewrite port field is cleared, Ant Design's InputNumber writes null into the form store (its standard behavior for an empty numeric field). The advanced JSON tab reflects this as "rewritePort": null.

On save, the tunnel schema declared:

rewritePort: PortSchema.optional()

Zod's .optional() permits undefined but not null, so the form-store null was rejected with settings.rewritePort — Invalid input. The only workaround was to manually delete the rewritePort key in the JSON editor (which sets the value to undefined).

The fix accepts null and collapses it to undefined, so the field is omitted from the serialized payload — matching the deleted-key behavior:

rewritePort: PortSchema.nullable().transform((v) => v ?? undefined).optional()

The trailing .optional() keeps the key optional in the inferred type (a bare .transform() would make it required and break the default-settings factory).

Type of change

  • Bug fix

Areas affected

  • Frontend (UI / panel pages)

How was this tested?

  • Added frontend/src/test/tunnel-rewriteport.test.ts covering: null → omitted, missing → omitted, valid port preserved, out-of-range still rejected.
  • npm run typecheck and npm run lint pass.
  • npm run gen produces no diff (codegen gate clean).
  • Verified schema behavior directly against zod: { rewritePort: null } and {} both parse to {}; 8443 is preserved; 70000 is rejected.
  • Manual: tunnel inbound → clear Rewrite port → Save succeeds, and the port is omitted from settings.

Breaking changes

None. A previously-crashing input (null) now parses to "port omitted"; all valid ports behave as before.

Checklist

  • I tested the change locally and confirmed the described behavior.
  • I added or updated tests for the new behavior (when applicable).
  • For frontend changes: npm run lint, npm run typecheck pass.
  • My commits follow the project's existing message style.
  • I have no unrelated changes mixed into this PR.

🔄 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/5525 **Author:** [@rqzbeh](https://github.com/rqzbeh) **Created:** 6/23/2026 **Status:** ✅ Merged **Merged:** 6/24/2026 **Merged by:** [@MHSanaei](https://github.com/MHSanaei) **Base:** `main` ← **Head:** `fix/tunnel-rewriteport-null` --- ### 📝 Commits (1) - [`34f37de`](https://github.com/MHSanaei/3x-ui/commit/34f37de664824325a1c563bfd319cccdabe0dc72) fix(inbounds): accept null rewritePort in tunnel settings (#5516) ### 📊 Changes **2 files changed** (+32 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `frontend/src/schemas/protocols/inbound/tunnel.ts` (+6 -1) ➕ `frontend/src/test/tunnel-rewriteport.test.ts` (+26 -0) </details> ### 📄 Description ## Summary Fix a validation crash when the tunnel inbound's **Rewrite port** field is cleared. Closes #5516. ## Why When the Rewrite port field is cleared, Ant Design's `InputNumber` writes `null` into the form store (its standard behavior for an empty numeric field). The advanced JSON tab reflects this as `"rewritePort": null`. On save, the tunnel schema declared: ```ts rewritePort: PortSchema.optional() ``` Zod's `.optional()` permits `undefined` but **not** `null`, so the form-store `null` was rejected with `settings.rewritePort — Invalid input`. The only workaround was to manually delete the `rewritePort` key in the JSON editor (which sets the value to `undefined`). The fix accepts `null` and collapses it to `undefined`, so the field is omitted from the serialized payload — matching the deleted-key behavior: ```ts rewritePort: PortSchema.nullable().transform((v) => v ?? undefined).optional() ``` The trailing `.optional()` keeps the key optional in the inferred type (a bare `.transform()` would make it required and break the default-settings factory). ## Type of change - [x] Bug fix ## Areas affected - [x] Frontend (UI / panel pages) ## How was this tested? - Added `frontend/src/test/tunnel-rewriteport.test.ts` covering: `null` → omitted, missing → omitted, valid port preserved, out-of-range still rejected. - `npm run typecheck` and `npm run lint` pass. - `npm run gen` produces no diff (codegen gate clean). - Verified schema behavior directly against zod: `{ rewritePort: null }` and `{}` both parse to `{}`; `8443` is preserved; `70000` is rejected. - Manual: tunnel inbound → clear Rewrite port → Save succeeds, and the port is omitted from settings. ## Breaking changes None. A previously-crashing input (`null`) now parses to "port omitted"; all valid ports behave as before. ## 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] For frontend changes: `npm run lint`, `npm run typecheck` pass. - [x] My commits follow the project's existing message style. - [x] I have no unrelated changes mixed into this PR. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 04:04:58 +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#5912
No description provided.