Skip to content

Commit 44ad0e1

Browse files
committed
fix(ui): avoid stale closure when clearing connectivity error
Always dispatch setConnectivityError(null) on successful API response instead of conditionally checking connectivityError. This avoids stale closure issues where the callback captures an outdated value. Also removes the unused handleRefreshClick callback since onRefreshClicked is not needed - loadData() is already called via onRefresh. References: #RI-7761
1 parent 610aa24 commit 44ad0e1

File tree

3 files changed

+4
-29
lines changed

3 files changed

+4
-29
lines changed

redisinsight/ui/src/components/database-overview/DatabaseOverview.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ const DatabaseOverview = () => {
3030
isBdbPackages,
3131
lastRefreshTime,
3232
handleEnableAutoRefresh,
33-
handleRefreshClick,
3433
handleRefresh,
3534
} = useDatabaseOverview()
3635

@@ -102,7 +101,6 @@ const DatabaseOverview = () => {
102101
DATABASE_OVERVIEW_MINIMUM_REFRESH_INTERVAL,
103102
)}
104103
onRefresh={handleRefresh}
105-
onRefreshClicked={handleRefreshClick}
106104
onEnableAutoRefresh={handleEnableAutoRefresh}
107105
/>
108106
</FlexItem>

redisinsight/ui/src/components/database-overview/hooks/useDatabaseOverview.spec.ts

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ describe('useDatabaseOverview', () => {
9696
expect(data.isBdbPackages).toBeUndefined()
9797
expect(data.usedMemoryPercent).toBeUndefined()
9898
expect(typeof data.handleRefresh).toBe('function')
99-
expect(typeof data.handleRefreshClick).toBe('function')
10099
expect(typeof data.handleEnableAutoRefresh).toBe('function')
101100
})
102101

@@ -157,22 +156,6 @@ describe('useDatabaseOverview', () => {
157156
expect(actions).toContainEqual(getDatabaseConfigInfo())
158157
})
159158

160-
it('should handle refresh click correctly (no-op)', () => {
161-
// handleRefreshClick is intentionally a no-op.
162-
// AutoRefresh.handleRefreshClick calls onRefresh() before onRefreshClicked(),
163-
// so loadData() is already called via handleRefresh.
164-
mockedStore.clearActions()
165-
166-
const data = renderHelper(mockedStore)
167-
act(() => {
168-
data.handleRefreshClick()
169-
})
170-
171-
const actions = mockedStore.getActions()
172-
// handleRefreshClick should not dispatch any actions
173-
expect(actions).toHaveLength(0)
174-
})
175-
176159
it('should send telemetry event when auto-refresh is enabled', () => {
177160
const data = renderHelper(mockedStore)
178161
act(() => {

redisinsight/ui/src/components/database-overview/hooks/useDatabaseOverview.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ export const useDatabaseOverview = () => {
5252
if (connectedInstanceId) {
5353
dispatch(
5454
getDatabaseConfigInfoAction(connectedInstanceId, () => {
55-
// Clear connectivity error on successful API call
56-
if (connectivityError) {
57-
dispatch(setConnectivityError(null))
58-
}
55+
// Clear connectivity error on successful API call.
56+
// Always dispatch to avoid stale closure issues - dispatching null
57+
// when there's no error is a safe no-op.
58+
dispatch(setConnectivityError(null))
5959
}),
6060
)
6161
setLastRefreshTime(Date.now())
@@ -85,11 +85,6 @@ export const useDatabaseOverview = () => {
8585
const handleRefresh = () => {
8686
loadData()
8787
}
88-
// Note: handleRefreshClick is intentionally a no-op.
89-
// AutoRefresh.handleRefreshClick calls onRefresh() before onRefreshClicked(),
90-
// so loadData() is already called via handleRefresh. This callback exists only
91-
// for cases where additional side effects are needed on manual click.
92-
const handleRefreshClick = () => {}
9388
const usedMemoryPercent = getUsedMemoryPercent(
9489
planMemoryLimit,
9590
usedMemory,
@@ -117,6 +112,5 @@ export const useDatabaseOverview = () => {
117112
usedMemoryPercent,
118113
handleEnableAutoRefresh,
119114
handleRefresh,
120-
handleRefreshClick,
121115
}
122116
}

0 commit comments

Comments
 (0)