Skip to content

Commit a23f505

Browse files
authored
Merge pull request #453 from codomposer/fix/memory_leak_mainchart
Fix: Memory leak in MainChart ColorSchemeChange listener
2 parents 145e651 + 57945ba commit a23f505

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/views/dashboard/MainChart.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const MainChart = () => {
77
const chartRef = useRef(null)
88

99
useEffect(() => {
10-
document.documentElement.addEventListener('ColorSchemeChange', () => {
10+
const handleColorSchemeChange = () => {
1111
if (chartRef.current) {
1212
setTimeout(() => {
1313
chartRef.current.options.scales.x.grid.borderColor = getStyle(
@@ -23,7 +23,10 @@ const MainChart = () => {
2323
chartRef.current.update()
2424
})
2525
}
26-
})
26+
}
27+
28+
document.documentElement.addEventListener('ColorSchemeChange', handleColorSchemeChange)
29+
return () => document.documentElement.removeEventListener('ColorSchemeChange', handleColorSchemeChange)
2730
}, [chartRef])
2831

2932
const random = () => Math.round(Math.random() * 100)

0 commit comments

Comments
 (0)