Skip to content

Conversation

@codomposer
Copy link
Contributor

@codomposer codomposer commented Oct 29, 2025

Fix: Issue 452

Closes #444
Closes #355
Closes #329

Problem

The ColorSchemeChange event listener in MainChart was never cleaned up, causing memory leaks on component unmount.

Solution

Added cleanup function to remove the event listener when component unmounts.

Changes

  • Extracted inline arrow function to named handleColorSchemeChange function
  • Added return statement in useEffect to remove listener on unmount

Code

Before:

useEffect(() => {
  document.documentElement.addEventListener('ColorSchemeChange', () => {
    if (chartRef.current) {
      setTimeout(() => {
        chartRef.current.options.scales.x.grid.borderColor = getStyle(
          '--cui-border-color-translucent',
        )
        chartRef.current.options.scales.x.grid.color = getStyle('--cui-border-color-translucent')
        chartRef.current.options.scales.x.ticks.color = getStyle('--cui-body-color')
        chartRef.current.options.scales.y.grid.borderColor = getStyle(
          '--cui-border-color-translucent',
        )
        chartRef.current.options.scales.y.grid.color = getStyle('--cui-border-color-translucent')
        chartRef.current.options.scales.y.ticks.color = getStyle('--cui-body-color')
        chartRef.current.update()
      })
    }
  })
}, [chartRef])

@mrholek mrholek merged commit a23f505 into coreui:main Oct 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CSidebar below a fixed CHeader bar CDataTable Header sticky feature not available ! CSidebar auto-collapses on clicking on the panel in React app

2 participants