This is an automated email from the ASF dual-hosted git repository.

lizhimins pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/rocketmq-dashboard.git


The following commit(s) were added to refs/heads/master by this push:
     new 88bf0b7a0 fix(web): keep failing live-refresh ticks quiet on the 
broker cluster page (#5645)
88bf0b7a0 is described below

commit 88bf0b7a0dca1399c202bd333008785951f3c42d
Author: Apulupie <[email protected]>
AuthorDate: Fri Nov 27 12:56:31 2026 +0800

    fix(web): keep failing live-refresh ticks quiet on the broker cluster page 
(#5645)
---
 web/src/pages/studio/BrokerCluster.tsx             | 69 +++++++++++++---------
 .../pages/studio/__tests__/BrokerCluster.test.tsx  | 59 ++++++++++++++++++
 2 files changed, 99 insertions(+), 29 deletions(-)

diff --git a/web/src/pages/studio/BrokerCluster.tsx 
b/web/src/pages/studio/BrokerCluster.tsx
index 80f949fd6..2b1f5b9c7 100644
--- a/web/src/pages/studio/BrokerCluster.tsx
+++ b/web/src/pages/studio/BrokerCluster.tsx
@@ -219,35 +219,46 @@ const BrokerClusterPage = () => {
     setProxyData([]);
   }, []);
 
-  const loadData = useCallback(async () => {
-    // A completed snapshot remains useful on refresh, but never under a 
different instance.
-    if (requestedInstanceRef.current !== selectedInstanceId) {
-      requestedInstanceRef.current = selectedInstanceId;
-      clearData();
-    }
-    if (!selectedInstanceId && !isMockMode()) {
-      clearData();
-      return;
-    }
-    const requestId = ++loadRequestId.current;
-    setLoading(true);
-    try {
-      const clusters = await listClusters(selectedInstanceId);
-      if (!mountedRef.current || requestId !== loadRequestId.current) return;
-      const mapped = mapClusters(clusters);
-      setBrokerData(mapped.brokers);
-      setNameServerData(mapped.nameServers);
-      setProxyData(mapped.proxies);
-    } catch {
-      if (!mountedRef.current || requestId !== loadRequestId.current) return;
-      clearData();
-      message.error(t('common.refreshFailed'));
-    } finally {
-      if (mountedRef.current && requestId === loadRequestId.current) {
-        setLoading(false);
+  // A failing live-refresh tick must neither toast on every interval nor 
blank the topology the
+  // user is looking at: a transient broker/instance outage would otherwise 
turn into an error
+  // toast every REFRESH_INTERVAL_MS and an empty table between ticks. Silent 
ticks keep the last
+  // good data; explicit refreshes keep the loud failure. (Same rationale as 
the consumer page's
+  // silent auto-refresh.)
+  const loadData = useCallback(
+    async (silent = false) => {
+      // A completed snapshot remains useful on refresh, but never under a 
different instance.
+      if (requestedInstanceRef.current !== selectedInstanceId) {
+        requestedInstanceRef.current = selectedInstanceId;
+        clearData();
       }
-    }
-  }, [clearData, message, selectedInstanceId, t]);
+      if (!selectedInstanceId && !isMockMode()) {
+        clearData();
+        return;
+      }
+      const requestId = ++loadRequestId.current;
+      if (!silent) setLoading(true);
+      try {
+        const clusters = await listClusters(selectedInstanceId);
+        if (!mountedRef.current || requestId !== loadRequestId.current) return;
+        const mapped = mapClusters(clusters);
+        setBrokerData(mapped.brokers);
+        setNameServerData(mapped.nameServers);
+        setProxyData(mapped.proxies);
+      } catch {
+        if (!mountedRef.current || requestId !== loadRequestId.current) return;
+        if (silent) return;
+        clearData();
+        message.error(t('common.refreshFailed'));
+      } finally {
+        // The latest request clears the spinner even when it is a silent 
tick: a tick that
+        // supersedes an explicit refresh would otherwise leave that refresh's 
spinner on forever.
+        if (mountedRef.current && requestId === loadRequestId.current) {
+          setLoading(false);
+        }
+      }
+    },
+    [clearData, message, selectedInstanceId, t],
+  );
 
   useEffect(() => {
     let active = true;
@@ -286,7 +297,7 @@ const BrokerClusterPage = () => {
     };
   }, [loadData]);
 
-  useVisiblePolling(autoRefresh, REFRESH_INTERVAL_MS, loadData);
+  useVisiblePolling(autoRefresh, REFRESH_INTERVAL_MS, () => void 
loadData(true));
 
   const renderStatus = (status: string) => {
     const config: Record<string, { color: string; label: string }> = {
diff --git a/web/src/pages/studio/__tests__/BrokerCluster.test.tsx 
b/web/src/pages/studio/__tests__/BrokerCluster.test.tsx
index 25cc5c75f..321c1acb3 100644
--- a/web/src/pages/studio/__tests__/BrokerCluster.test.tsx
+++ b/web/src/pages/studio/__tests__/BrokerCluster.test.tsx
@@ -507,4 +507,63 @@ describe('BrokerCluster Page', () => {
       screen.queryByRole('columnheader', { name: /连接数|[Cc]onnections/ }),
     ).not.toBeInTheDocument();
   });
+
+  it('keeps the last topology and stays quiet when a live-refresh tick fails', 
async () => {
+    const visibilityState = vi.spyOn(document, 'visibilityState', 
'get').mockReturnValue('visible');
+    vi.mocked(listClusters)
+      .mockResolvedValueOnce(clusterFixture)
+      .mockRejectedValue(new Error('instance down'));
+    renderWithProviders(<BrokerCluster />);
+    await screen.findByText('broker-api-a');
+
+    vi.useFakeTimers();
+    fireEvent.click(screen.getByRole('switch'));
+    await act(async () => {
+      await vi.advanceTimersByTimeAsync(6000);
+    });
+
+    // The failing silent tick neither blanks the table nor toasts on every 
interval.
+    expect(screen.getByText('broker-api-a')).toBeInTheDocument();
+    expect(screen.queryByText('刷新失败')).not.toBeInTheDocument();
+
+    // An explicit refresh after the outage keeps the loud failure: data 
clears and one toast shows.
+    await act(async () => {
+      fireEvent.click(screen.getByText('重置'));
+      await vi.advanceTimersByTimeAsync(0);
+    });
+    expect(screen.queryByText('broker-api-a')).not.toBeInTheDocument();
+    expect(screen.getByText('刷新失败')).toBeInTheDocument();
+    visibilityState.mockRestore();
+  });
+
+  it('clears the spinner when a live-refresh tick supersedes a pending 
explicit refresh', async () => {
+    const visibilityState = vi.spyOn(document, 'visibilityState', 
'get').mockReturnValue('visible');
+    const explicit = createDeferred<ClusterInfo[]>();
+    vi.mocked(listClusters)
+      .mockResolvedValueOnce(clusterFixture)
+      .mockReturnValueOnce(explicit.promise)
+      .mockResolvedValue(clusterFixture);
+    const { container } = renderWithProviders(<BrokerCluster />);
+    await screen.findByText('broker-api-a');
+
+    vi.useFakeTimers();
+    await act(async () => {
+      fireEvent.click(screen.getByText('重置'));
+    });
+    // antd's Spin turns the spinner on through a debounce timer.
+    await act(async () => {
+      await vi.advanceTimersByTimeAsync(0);
+    });
+    expect(container.querySelector('.ant-spin-spinning')).not.toBeNull();
+
+    // The tick becomes the latest request, so the explicit refresh can no 
longer clear the spinner.
+    fireEvent.click(screen.getByRole('switch'));
+    await act(async () => {
+      await vi.advanceTimersByTimeAsync(2000);
+    });
+    expect(container.querySelector('.ant-spin-spinning')).toBeNull();
+
+    await act(async () => explicit.resolve(clusterFixture));
+    visibilityState.mockRestore();
+  });
 });

Reply via email to