Skip to content

Commit

Permalink
Fix chart loading causing freeze
Browse files Browse the repository at this point in the history
  • Loading branch information
mrkwanzaa committed Nov 6, 2024
1 parent 7d25865 commit 78c831c
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/ui/views/dashboard/DashboardChart.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,6 @@ const DashboardChart = ({ chartObj }) => {
const rightVariant = R.propOr('bar', 'rightVariant', cleanedChartObj)
const showNA = R.propOr(false, 'showNA', cleanedChartObj)

useEffect(() => {
setLoading(false)
}, [formattedData])

// for some reason useLayoutEffect doesn't set the state before the chart is rendered
// so we use useMemo to trigger the loading state
useMemo(() => {
Expand All @@ -87,9 +83,11 @@ const DashboardChart = ({ chartObj }) => {
const runWorkers = async () => {
memoizedChartFunc(cleanedChartObj).then((computedData) => {
setFormattedData(computedData)
setLoading(false)
})
}
runWorkers()
const workerRunner = setTimeout(runWorkers, 1)
return () => clearTimeout(workerRunner)
}, [cleanedChartObj, memoizedChartFunc])

const groupingRange = R.pipe(
Expand Down

0 comments on commit 78c831c

Please sign in to comment.