From 8a72a2a4c7679f6c7a8d608d9990b8902b679f87 Mon Sep 17 00:00:00 2001 From: nanaya Date: Tue, 7 Jan 2025 20:19:21 +0900 Subject: [PATCH 1/3] Reset changelog chart before creating a new one --- .../js/core-legacy/changelog-chart-loader.coffee | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/resources/js/core-legacy/changelog-chart-loader.coffee b/resources/js/core-legacy/changelog-chart-loader.coffee index 2e6a570da3f..75a0e885da7 100644 --- a/resources/js/core-legacy/changelog-chart-loader.coffee +++ b/resources/js/core-legacy/changelog-chart-loader.coffee @@ -10,11 +10,18 @@ export default class ChangelogChartLoader $(window).on 'resize', @resize $(document).on 'turbo:load', @initialize + initialize: => - return if !@container[0]? + container = @container[0] + + return unless container? + + # reset existing chart + container.innerHTML = '' + + container._chart = new ChangelogChart container + container._chart.loadData() - @container[0]._chart = new ChangelogChart @container[0] - @container[0]._chart.loadData() resize: => @container[0]?._chart.resize() From f713a0e736dd0d27abfc76dfd8586371d594315a Mon Sep 17 00:00:00 2001 From: nanaya Date: Tue, 7 Jan 2025 20:22:20 +0900 Subject: [PATCH 2/3] Simplify existence check --- .../js/core-legacy/changelog-chart-loader.coffee | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/resources/js/core-legacy/changelog-chart-loader.coffee b/resources/js/core-legacy/changelog-chart-loader.coffee index 75a0e885da7..884ca05d09d 100644 --- a/resources/js/core-legacy/changelog-chart-loader.coffee +++ b/resources/js/core-legacy/changelog-chart-loader.coffee @@ -4,24 +4,22 @@ import ChangelogChart from 'charts/changelog-chart' export default class ChangelogChartLoader - container: document.getElementsByClassName('js-changelog-chart') - constructor: -> $(window).on 'resize', @resize $(document).on 'turbo:load', @initialize initialize: => - container = @container[0] + @container = document.querySelector('.js-changelog-chart') - return unless container? + return unless @container? # reset existing chart - container.innerHTML = '' + @container.innerHTML = '' - container._chart = new ChangelogChart container - container._chart.loadData() + @container._chart = new ChangelogChart @container + @container._chart.loadData() resize: => - @container[0]?._chart.resize() + @container?._chart.resize() From 8347eb5a18491b37c5a5da69d8496b369044d2b5 Mon Sep 17 00:00:00 2001 From: nanaya Date: Tue, 7 Jan 2025 20:27:58 +0900 Subject: [PATCH 3/3] More precise chart event handling --- .../core-legacy/changelog-chart-loader.coffee | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/resources/js/core-legacy/changelog-chart-loader.coffee b/resources/js/core-legacy/changelog-chart-loader.coffee index 884ca05d09d..25c056497aa 100644 --- a/resources/js/core-legacy/changelog-chart-loader.coffee +++ b/resources/js/core-legacy/changelog-chart-loader.coffee @@ -5,21 +5,27 @@ import ChangelogChart from 'charts/changelog-chart' export default class ChangelogChartLoader constructor: -> - $(window).on 'resize', @resize - $(document).on 'turbo:load', @initialize + document.addEventListener 'turbo:load', @initialize + document.addEventListener 'turbo:before-cache', @reset initialize: => - @container = document.querySelector('.js-changelog-chart') + container = document.querySelector('.js-changelog-chart') - return unless @container? + return unless container? # reset existing chart - @container.innerHTML = '' + container.innerHTML = '' - @container._chart = new ChangelogChart @container - @container._chart.loadData() + @chart = new ChangelogChart container + @chart.loadData() + window.addEventListener 'resize', @resize + + + reset: => + @chart = null + window.removeEventListener 'resize', @resize resize: => - @container?._chart.resize() + @chart.resize()