From b9612f1326b9a4ab668faa0b08e859e35ff76d62 Mon Sep 17 00:00:00 2001 From: MHSanaei Date: Tue, 2 Jun 2026 02:08:06 +0200 Subject: [PATCH] fix(xray): clear dirty state after saving unchanged config Editing an outbound and re-saving it without real changes left the top Save button stuck enabled, and clicking it never cleared it. The form re-normalizes values into deeply-equal config, so react-query keeps the same configQuery.data reference on refetch and the seed effect that resets the dirty baseline never re-runs. Advance the baseline to the persisted value in saveMut.onSuccess instead of relying solely on the refetch. --- frontend/src/hooks/useXraySetting.ts | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/frontend/src/hooks/useXraySetting.ts b/frontend/src/hooks/useXraySetting.ts index ed9f59a6..13119940 100644 --- a/frontend/src/hooks/useXraySetting.ts +++ b/frontend/src/hooks/useXraySetting.ts @@ -197,13 +197,21 @@ export function useXraySetting(): UseXraySettingResult { }, [queryClient]); const saveMut = useMutation({ - mutationFn: async () => - HttpUtil.post('/panel/xray/update', { - xraySetting: xraySettingRef.current, - outboundTestUrl: outboundTestUrlRef.current || DEFAULT_TEST_URL, - }), - onSuccess: (msg) => { - if (msg?.success) queryClient.invalidateQueries({ queryKey: keys.xray.config() }); + mutationFn: async () => { + const sentXraySetting = xraySettingRef.current; + const sentTestUrl = outboundTestUrlRef.current || DEFAULT_TEST_URL; + const msg = await HttpUtil.post('/panel/xray/update', { + xraySetting: sentXraySetting, + outboundTestUrl: sentTestUrl, + }); + return { msg, sentXraySetting, sentTestUrl }; + }, + onSuccess: ({ msg, sentXraySetting, sentTestUrl }) => { + if (!msg?.success) return; + oldXraySettingRef.current = sentXraySetting; + oldOutboundTestUrlRef.current = sentTestUrl; + setSaveDisabled(true); + queryClient.invalidateQueries({ queryKey: keys.xray.config() }); }, });