Skip to content

Commit 897c227

Browse files
fix(devtools): guard canvas ref access for Chart.js pages
Add null checks on useRef().current before calling getContext('2d') on index, metrics, and queue-details pages. Prevents crash when canvas elements aren't in the DOM yet during mount. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 3ae9d71 commit 897c227

File tree

3 files changed

+4
-0
lines changed

3 files changed

+4
-0
lines changed

packages/devtools/src/pages/index.stx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@
201201
})
202202
.then((metricsRes: Response) => metricsRes.json())
203203
.then((metrics: MetricsData) => {
204+
if (!throughputCanvas.current) return
204205
if (throughputChart) throughputChart.destroy()
205206
const ctx1 = throughputCanvas.current.getContext('2d')
206207
throughputChart = new Chart(ctx1, {
@@ -234,6 +235,7 @@
234235
})
235236
.then((statsRes2: Response) => statsRes2.json())
236237
.then((stats: DashboardStats) => {
238+
if (!queueStatusCanvas.current) return
237239
if (queueStatusChart) queueStatusChart.destroy()
238240
const ctx2 = queueStatusCanvas.current.getContext('2d')
239241
queueStatusChart = new Chart(ctx2, {

packages/devtools/src/pages/metrics.stx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@
138138
)
139139
statUptime.set(String(Math.round(sData.uptime / 3600)))
140140

141+
if (!throughputRef.current || !latencyRef.current || !errorRateRef.current) return
141142
if (throughputChart) throughputChart.destroy()
142143
throughputChart = new Chart(throughputRef.current.getContext('2d'), {
143144
type: 'line',

packages/devtools/src/pages/queue-details.stx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@
222222
const labels: string[] = data.throughput ? data.throughput.map((d: ThroughputPoint) => d.label || d.time || '') : []
223223
const values: number[] = data.throughput ? data.throughput.map((d: ThroughputPoint) => d.value || d.count || 0) : []
224224

225+
if (!throughputRef.current) return
225226
const ctx = throughputRef.current.getContext('2d')
226227

227228
if (throughputChart) throughputChart.destroy()

0 commit comments

Comments
 (0)