From 844b0e60dfb656b51289bacc78cd46a55d0551e5 Mon Sep 17 00:00:00 2001 From: Stanislaw Grams Date: Mon, 16 Mar 2026 23:46:04 +0100 Subject: [PATCH] [fix](trx-frontend-http): roll back optimistic freq update when set_freq fails setRigFrequency applied applyLocalTunedFrequency before the network round-trip, leaving the spectrum view shifted to the new frequency even when the POST was rejected (e.g. 403 when the user loses control access). Save the previous frequency and restore it in the catch block so the UI stays aligned with the actual server-side state. Co-authored-by: Claude Sonnet 4.6 Signed-off-by: Stanislaw Grams --- .../trx-frontend-http/assets/web/app.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/trx-client/trx-frontend/trx-frontend-http/assets/web/app.js b/src/trx-client/trx-frontend/trx-frontend-http/assets/web/app.js index e9346c9..a6a687e 100644 --- a/src/trx-client/trx-frontend/trx-frontend-http/assets/web/app.js +++ b/src/trx-client/trx-frontend/trx-frontend-http/assets/web/app.js @@ -1822,12 +1822,20 @@ async function setRigFrequency(freqHz) { throw new Error(`Unsupported frequency: ${targetHz}`); } // Optimistic local update before any network round-trip. + const prevFreqHz = lastFreqHz; applyLocalTunedFrequency(targetHz); - // set_freq and set_center_freq are independent server operations — run in parallel. - await Promise.all([ - postPath(`/set_freq?hz=${targetHz}`), - ensureTunedBandwidthCoverage(targetHz), - ]); + try { + // set_freq and set_center_freq are independent server operations — run in parallel. + await Promise.all([ + postPath(`/set_freq?hz=${targetHz}`), + ensureTunedBandwidthCoverage(targetHz), + ]); + } catch (err) { + // Roll back the optimistic update so the spectrum view stays on the + // actual server-side frequency (e.g. when the user loses control access). + if (prevFreqHz != null) applyLocalTunedFrequency(prevFreqHz, true); + throw err; + } } function spectrumBinIndexForHz(data, hz) {