[PR #6052] [MERGED] fix(warp): preserve outbound customization when rotating IP #6065

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

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/6052
Author: @H-TTTTT
Created: 7/20/2026
Status: ✅ Merged
Merged: 7/21/2026
Merged by: @MHSanaei

Base: main ← Head: fix/warp-change-ip-preserve


📝 Commits (1)

  • 5aa7e42 fix(warp): preserve outbound customization when rotating IP

📊 Changes

2 files changed (+142 additions, -6 deletions)

View changed files

📝 frontend/src/pages/xray/overrides/WarpModal.tsx (+43 -6)
➕ frontend/src/test/warp-change-ip.test.ts (+99 -0)

📄 Description

Summary

The WARP Change IP button rebuilds the warp outbound from a fixed default template (collectConfig) and then replaces the whole in-memory outbound via onResetOutbound (XrayPage.tsx: tt.outbounds[index] = payload.outbound). Only secretKey/address/reserved and the first peer's publicKey/endpoint survive that rebuild, so a user's custom mtu, domainStrategy, noKernelTun, the first peer's keepAlive / allowedIPs / preSharedKey, and any extra peers are silently dropped from the editor.

Because the Outbounds tab renders that in-memory copy for the rest of the session and a later page Save persists it to /panel/api/xray/update, the loss can become permanent — even though the backend ChangeWarpIP → UpdateWarpXraySetting already patches only the rotated fields and leaves every other field (including a peer's keepAlive) untouched in the stored template.

This is a frontend-only bug; the scheduled auto IP-rotation job calls the backend method directly and is unaffected.

Changes

  • New pure helper `mergeWarpRotation(existing, data, config)` mirrors the server-side `UpdateWarpXraySetting`: it patches only `secretKey`, `address`, `reserved`, and the first peer's `publicKey`/`endpoint` into the existing outbound object, preserving everything else. Shallow-clones each touched level so the original state object is never mutated.
  • `changeIp()` now calls `mergeWarpRotation` and passes the merged outbound to `onResetOutbound`, instead of the rebuilt default. `collectConfig` is still called to refresh `stagedOutbound` (the explicit, labeled Reset button keeps its existing semantics).
  • `register()` (first-time creation, nothing to preserve yet) is unchanged and still uses `collectConfig`'s full build.
  • Extracted as a module-level function so it is unit-testable without rendering the modal.

Verification

  • `npx vitest run src/test/warp-change-ip.test.ts` — 4 passing: preserves custom fields, no mutation of input, null on missing peer, seeds default when no prior outbound.
  • `npx tsc --noEmit` + `npx eslint` on the touched files — clean.

Fixes #6019


🔄 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/6052 **Author:** [@H-TTTTT](https://github.com/H-TTTTT) **Created:** 7/20/2026 **Status:** ✅ Merged **Merged:** 7/21/2026 **Merged by:** [@MHSanaei](https://github.com/MHSanaei) **Base:** `main` ← **Head:** `fix/warp-change-ip-preserve` --- ### 📝 Commits (1) - [`5aa7e42`](https://github.com/MHSanaei/3x-ui/commit/5aa7e4263ad58b31e703151c969619bce5148ab5) fix(warp): preserve outbound customization when rotating IP ### 📊 Changes **2 files changed** (+142 additions, -6 deletions) <details> <summary>View changed files</summary> 📝 `frontend/src/pages/xray/overrides/WarpModal.tsx` (+43 -6) ➕ `frontend/src/test/warp-change-ip.test.ts` (+99 -0) </details> ### 📄 Description ## Summary The WARP **Change IP** button rebuilds the `warp` outbound from a fixed default template (`collectConfig`) and then replaces the whole in-memory outbound via `onResetOutbound` (`XrayPage.tsx: tt.outbounds[index] = payload.outbound`). Only `secretKey`/`address`/`reserved` and the first peer's `publicKey`/`endpoint` survive that rebuild, so a user's custom `mtu`, `domainStrategy`, `noKernelTun`, the first peer's `keepAlive` / `allowedIPs` / `preSharedKey`, and any extra peers are silently dropped from the editor. Because the Outbounds tab renders that in-memory copy for the rest of the session and a later page **Save** persists it to `/panel/api/xray/update`, the loss can become permanent — even though the backend `ChangeWarpIP` → `UpdateWarpXraySetting` already patches only the rotated fields and leaves every other field (including a peer's `keepAlive`) untouched in the stored template. This is a frontend-only bug; the scheduled auto IP-rotation job calls the backend method directly and is unaffected. ## Changes - New pure helper \`mergeWarpRotation(existing, data, config)\` mirrors the server-side \`UpdateWarpXraySetting\`: it patches **only** \`secretKey\`, \`address\`, \`reserved\`, and the first peer's \`publicKey\`/\`endpoint\` into the existing outbound object, preserving everything else. Shallow-clones each touched level so the original state object is never mutated. - \`changeIp()\` now calls \`mergeWarpRotation\` and passes the merged outbound to \`onResetOutbound\`, instead of the rebuilt default. \`collectConfig\` is still called to refresh \`stagedOutbound\` (the explicit, labeled **Reset** button keeps its existing semantics). - \`register()\` (first-time creation, nothing to preserve yet) is unchanged and still uses \`collectConfig\`'s full build. - Extracted as a module-level function so it is unit-testable without rendering the modal. ## Verification - \`npx vitest run src/test/warp-change-ip.test.ts\` — 4 passing: preserves custom fields, no mutation of input, null on missing peer, seeds default when no prior outbound. - \`npx tsc --noEmit\` + \`npx eslint\` on the touched files — clean. Fixes #6019 --- <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:07 +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#6065
No description provided.