diff options
| author | Samuel Degueldre <sad@odoo.com> | 2021-03-23 12:56:42 +0000 |
|---|---|---|
| committer | qsm-odoo <qsm@odoo.com> | 2021-03-25 10:16:32 +0000 |
| commit | 7623a0c771495cd41bf40af37c0d2b6e4beb7cdc (patch) | |
| tree | 1760b06a056762514d7be18f4558ba01401665b0 /addons/web_editor/static/src/js/editor | |
| parent | 374d3c7f95fca9832afb0d34d710f28dbadcdfa6 (diff) | |
[FIX] web_editor: fix race condition in option selection
Previously, when selecting certain options, especially ones which had
slow updateUI methods, the selected value was sometimes reset to its
previous value. This was caused by a race condition in which, when a
snippet option updated its value, it would wait for options on the
parent snippet editors to update all of their options' UI, but it
incorrectly only waited for *one* of the snippet editors to finish
instead of waiting for all of them.
This commit fixes that by stopping the event propagation and triggering
a new event that will let the direct parent know when all parent editors
are done updating their options' UI before signalling that the UI update
is done.
task-2487578
closes odoo/odoo#68238
Signed-off-by: Quentin Smetz (qsm) <qsm@odoo.com>
Co-authored-by: Arthur Detroux <ard@odoo.com>
Diffstat (limited to 'addons/web_editor/static/src/js/editor')
| -rw-r--r-- | addons/web_editor/static/src/js/editor/snippets.editor.js | 43 |
1 files changed, 33 insertions, 10 deletions
diff --git a/addons/web_editor/static/src/js/editor/snippets.editor.js b/addons/web_editor/static/src/js/editor/snippets.editor.js index 36870033db2..424b1d4b631 100644 --- a/addons/web_editor/static/src/js/editor/snippets.editor.js +++ b/addons/web_editor/static/src/js/editor/snippets.editor.js @@ -833,18 +833,32 @@ var SnippetEditor = Widget.extend({ * @param {OdooEvent} ev */ _onSnippetOptionUpdate: async function (ev) { - const proms1 = Object.keys(this.styles).map(key => { - return this.styles[key].updateUI({ - noVisibility: true, + if (ev.target === this) { + return; + } + ev.stopPropagation(); + const updateOptionsUI = async () => { + const proms1 = Object.keys(this.styles).map(key => { + return this.styles[key].updateUI({ + noVisibility: true, + }); }); - }); - await Promise.all(proms1); - - const proms2 = Object.keys(this.styles).map(key => { - return this.styles[key].updateUIVisibility(); - }); - await Promise.all(proms2); + await Promise.all(proms1); + const proms2 = Object.keys(this.styles).map(key => { + return this.styles[key].updateUIVisibility(); + }); + await Promise.all(proms2); + }; + // Wait for the current editor's option UI updates and the parent ones + await Promise.all([ + updateOptionsUI(), + new Promise(resolve => { + this.trigger_up('snippet_option_update', Object.assign({}, ev.data, { + onSuccess: () => resolve(), + })); + }), + ]); ev.data.onSuccess(); }, /** @@ -917,6 +931,7 @@ var SnippetsMenu = Widget.extend({ 'snippet_editor_destroyed': '_onSnippetEditorDestroyed', 'snippet_removed': '_onSnippetRemoved', 'snippet_cloned': '_onSnippetCloned', + 'snippet_option_update': '_onSnippetOptionUpdate', 'snippet_option_visibility_update': '_onSnippetOptionVisibilityUpdate', 'snippet_thumbnail_url_request': '_onSnippetThumbnailURLRequest', 'reload_snippet_dropzones': '_disableUndroppableSnippets', @@ -2611,6 +2626,14 @@ var SnippetsMenu = Widget.extend({ * @private * @param {OdooEvent} ev */ + _onSnippetOptionUpdate: function (ev) { + ev.stopPropagation(); + ev.data.onSuccess(); + }, + /** + * @private + * @param {OdooEvent} ev + */ _onSnippetOptionVisibilityUpdate: async function (ev) { if (!ev.data.show) { await this._activateSnippet(false); |
