Skip to content

Commit a0e1950

Browse files
committed
Fix: Add race condition protection and disable chart animations
Per code review feedback, adds two important improvements: 1. Race condition protection: - Track elevation update sequence number - Ignore stale data from late-returning API calls - Prevents chart showing outdated elevation when waypoints dragged rapidly 2. Disable chart animations during updates: - Use chart.update('none') instead of chart.update() - Improves performance during drag operations - Prevents animation queueing and visual lag These fixes ensure the chart always shows current data and responds smoothly even with rapid waypoint dragging or slow network connections.
1 parent eab0a71 commit a0e1950

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

tabs/mission_control.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4231,6 +4231,9 @@ function iconKey(filename) {
42314231
return altitude;
42324232
}
42334233

4234+
// Track elevation chart update sequence to prevent race conditions
4235+
let elevationUpdateSequence = 0;
4236+
42344237
function plotElevation() {
42354238
if ($('#missionPlannerElevation').is(":visible") && !disableMarkerEdit) {
42364239
if (mission.isEmpty()) {
@@ -4307,8 +4310,17 @@ function iconKey(filename) {
43074310
}
43084311
else {
43094312
(async () => {
4313+
// Capture current sequence number to detect stale updates
4314+
const currentSequence = ++elevationUpdateSequence;
4315+
43104316
try {
43114317
const [lengthMission, totalMissionDistance, samples, elevation, altPoint2measure, namePoint2measure, refPoint2measure] = await mission.getElevation(globalSettings);
4318+
4319+
// Check if a newer update has been triggered while we were fetching data
4320+
if (currentSequence !== elevationUpdateSequence) {
4321+
console.log('Ignoring stale elevation data');
4322+
return;
4323+
}
43124324
const x_elevation = Array.from(Array(samples+1), (_,i)=> i*totalMissionDistance/samples);
43134325
const y_missionElevation = altPoint2measure.map((x,i) => x / 100 + HOME.getAlt()*(1-refPoint2measure[i]));
43144326

@@ -4364,8 +4376,8 @@ function iconKey(filename) {
43644376
window.elevationChartInstance.options.plugins.title.text = chartTitle;
43654377
window.elevationChartInstance.options.scales.y.min = Math.floor(-10 + Math.min(minMission, minElevation));
43664378
window.elevationChartInstance.options.scales.y.max = Math.ceil(10 + Math.max(maxMission, maxElevation));
4367-
// Trigger re-render
4368-
window.elevationChartInstance.update();
4379+
// Trigger re-render without animation for better performance during drag operations
4380+
window.elevationChartInstance.update('none');
43694381
} else {
43704382
// Create new chart
43714383
window.elevationChartInstance = new Chart(ctx, {

0 commit comments

Comments
 (0)