[FIX] web: add check to not scroll calendar view if component is destroyed

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) <mcm@odoo.com>
This commit is contained in:
Julien Banken
2023-12-11 08:29:18 +00:00
parent 0eeee0cd53
commit 591a73939a
@@ -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);
}
});