From 37e9e2c8f0f5c5708bf965df43636556a8121c40 Mon Sep 17 00:00:00 2001 From: James Rich <2199651+jamesarich@users.noreply.github.com> Date: Fri, 10 Apr 2026 19:05:56 -0500 Subject: [PATCH] fix(charts): hoist rememberVicoZoomState above vararg layers to prevent ClassCastException (#5060) --- .../org/meshtastic/feature/node/metrics/BaseMetricChart.kt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/feature/node/src/commonMain/kotlin/org/meshtastic/feature/node/metrics/BaseMetricChart.kt b/feature/node/src/commonMain/kotlin/org/meshtastic/feature/node/metrics/BaseMetricChart.kt index 0b9f40044..cb96607d9 100644 --- a/feature/node/src/commonMain/kotlin/org/meshtastic/feature/node/metrics/BaseMetricChart.kt +++ b/feature/node/src/commonMain/kotlin/org/meshtastic/feature/node/metrics/BaseMetricChart.kt @@ -96,6 +96,11 @@ fun GenericMetricChart( onPointSelected: ((Double) -> Unit)? = null, vicoScrollState: VicoScrollState = rememberVicoScrollState(), ) { + // Hoist zoom state above rememberCartesianChart so that the variable slot count + // from the vararg layers spread does not shift this remember call during recomposition + // (toggling legend chips changes the layer count, which corrupts the slot table). + val zoomState = rememberVicoZoomState(zoomEnabled = true, initialZoom = Zoom.Content) + val markerVisibilityListener = remember(onPointSelected) { object : CartesianMarkerVisibilityListener { @@ -126,7 +131,7 @@ fun GenericMetricChart( modelProducer = modelProducer, modifier = modifier, scrollState = vicoScrollState, - zoomState = rememberVicoZoomState(zoomEnabled = true, initialZoom = Zoom.Content), + zoomState = zoomState, ) }