[FIX] web_editor: fix Theme tab infinite loading

ISSUE:

The click on "THEME" tab in editor panel triggers the
'_onThemeTabClick' method which:

1- Starts the loader ('_execWithLoadingEffect' method).
2- Runs '_activateSnippet' which uses the same mutex as the
loader.

Execution order:

A1- '_execWithLoadingEffect' with promise: adds the loader in
the DOM immediately.
A2- '_activateSnippet' sets a second loader to be added after
a delay = 500.
A3- 'releaseLoader' removes the first loader.
A4- '_activateSnippet' ends : (before adding the second
loader: t(4) - t(2) < 500) and timeout is cleared.

In some cases we get t(4) - t(2) > 500 which adds a second
loader to the DOM, and the new flow will be:

B1- Same as A1.
B2- Same as A2.
B3- Second loader added to the DOM / replaces the first one
in 'loadingElements'.
B4- 'releaseLoader' removes the second loader (from the DOM
& 'this.loadingElements').
B5- Same as A4 but the first loader still in the DOM.

The goal of this commit is to fix this behaviour by preventing
more than one loader on the target element.

task-2656308

closes odoo/odoo#77500

X-original-commit: 9f21b2eefab2115c1b8581ad9f43fe1e65f934ed
Signed-off-by: Quentin Smetz (qsm) <qsm@odoo.com>
This commit is contained in:
xO-Tx
2021-09-30 13:32:06 +00:00
parent d9f73a9ce6
commit 98a0376a14
@@ -2576,7 +2576,7 @@ var SnippetsMenu = Widget.extend({
const mutexExecResult = this._mutex.exec(action);
if (!this.loadingTimers[contentLoading]) {
const addLoader = () => {
if (this._loadingEffectDisabled) {
if (this._loadingEffectDisabled || this.loadingElements[contentLoading]) {
return;
}
this.loadingElements[contentLoading] = this._createLoadingElement();