Skip to content

Memory Leak in MainChart ColorSchemeChange listener #452

@codomposer

Description

@codomposer

Description

The MainChart component has a memory leak caused by a ColorSchemeChange event listener that is never cleaned up when the component unmounts.

Location

File: src/views/dashboard/MainChart.js
Lines: 9-27

Problem

The useEffect hook adds a ColorSchemeChange event listener to document.documentElement but doesn't provide a cleanup function:

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])

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions