From 591a73939a3bb3dc8a46751188197837fc71da0c Mon Sep 17 00:00:00 2001 From: Julien Banken Date: Wed, 6 Dec 2023 16:49:26 +0100 Subject: [PATCH] [FIX] web: add check to not scroll calendar view if component is destroyed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In the `onMounted` hook of the calendar renderer, the given callback function will schedule a new function call using `setTimeout` with a delay of 0 if some conditions are satisfied. The scheduled function will then trigger a scroll in the calendar view to display a precise timeslot. If the component is destroyed before the scheduled function is executed, the scheduled function may trigger an error as the root element of the calendar will be removed from the DOM when the component is destroyed. This commit will fix that issue by checking that the root element of the calendar exists before calling the `scrollToTime` function. Steps to reproduce the error: 1. Open Knowledge 2. Open the template gallery 3. Select the template "Sprint Calendar" 4. Quickly apply the template => If you have the right timing: a traceback will be displayed indicating that the function `scrollToTime` is not defined on `null`. TO BE: No traceback should be displayed when applying the template. task-3627780 closes odoo/odoo#145292 Signed-off-by: Michaƫl Mattiello (mcm) --- .../calendar/calendar_common/calendar_common_renderer.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/addons/web/static/src/views/calendar/calendar_common/calendar_common_renderer.js b/addons/web/static/src/views/calendar/calendar_common/calendar_common_renderer.js index 0eb52b4874c..6607e4afc95 100644 --- a/addons/web/static/src/views/calendar/calendar_common/calendar_common_renderer.js +++ b/addons/web/static/src/views/calendar/calendar_common/calendar_common_renderer.js @@ -54,7 +54,9 @@ export class CalendarCommonRenderer extends Component { if (this.props.model.scale === "day" || this.props.model.scale === "week") { //Need to wait React browser.setTimeout(() => { - this.fc.api.scrollToTime("06:00:00"); + if (this.fc.api.view) { + this.fc.api.scrollToTime("06:00:00"); + } }, 0); } });