From 623bc7b036fb8e4c6d291b11bf7a5aa7faca0f32 Mon Sep 17 00:00:00 2001 From: Flomp Date: Fri, 20 Feb 2026 13:39:55 +0100 Subject: [PATCH] Fixes race condition in crosshair plugin (#827) --- .../maplibre-elevation-profile/elevationprofile.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/web/src/lib/vendor/maplibre-elevation-profile/elevationprofile.ts b/web/src/lib/vendor/maplibre-elevation-profile/elevationprofile.ts index a09e6bdc..03c8e4c3 100644 --- a/web/src/lib/vendor/maplibre-elevation-profile/elevationprofile.ts +++ b/web/src/lib/vendor/maplibre-elevation-profile/elevationprofile.ts @@ -425,6 +425,19 @@ export class ElevationProfile { const elevationUnit = this.settings.unit === "imperial" ? "ft" : "m"; Chart.defaults.font.size = this.settings.fontSize; + // using CrosshairPlugin normally can lead to race conditions: + // https://github.com/AbelHeinsbroek/chartjs-plugin-crosshair/issues/119 + const CustomCrosshairPlugin = function (plugin: typeof CrosshairPlugin) { + const originalAfterDraw = plugin.afterDraw; + plugin.afterDraw = function (chart: Chart & { crosshair?: typeof CrosshairPlugin }, easing: boolean) { + if (chart && chart.crosshair) { + originalAfterDraw.call(this, chart, easing); + } + }; + return plugin; + }; + Chart.register(CustomCrosshairPlugin(CrosshairPlugin)); + this.chart = new Chart<"line", Array, number>(this.canvas, { type: "line", @@ -674,7 +687,6 @@ export class ElevationProfile { }, plugins: [ - CrosshairPlugin, { id: "waypointPlugin", afterDraw: (chart, args, options) => {