From 2587f31912cc67b6c2a51097b702953d8758e2ef Mon Sep 17 00:00:00 2001 From: FrancoisGe Date: Fri, 6 Jan 2023 09:46:43 +0000 Subject: [PATCH] [FIX] web: search in m2o displays lost connection notification In the PR 104415, we add the possibility to abort the name_search rpcs which will be ignored. Unfortunately, we forgot that xhr.abort performs a reject which will be converted into an "XmlHttpRequestError abort" error. This error will cause a notification "Connection lost. Trying to reconnect...". Solution: We revert the modifications in the abort function and in the m2o we catch all the errors on the rpc name_search that we are going to abort because they have no more use. How to reproduce: - Go to a form view with a m2o field - Having a slow network or a lot of records in the m2o - Enter several char in the m2o search bar Before this commit: A notification "Connection lost. Trying to reconnect..." is displayed. After this commit: There is no notification. closes odoo/odoo#109500 X-original-commit: 7bff161ac5e916bf4d4eabe4f9ada9a147893cf2 Signed-off-by: Samuel Degueldre --- addons/web/static/src/legacy/js/core/ajax.js | 16 +++++----------- .../src/legacy/js/fields/relational_fields.js | 4 ++++ 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/addons/web/static/src/legacy/js/core/ajax.js b/addons/web/static/src/legacy/js/core/ajax.js index 71484e5c9d8..3e694c472cd 100644 --- a/addons/web/static/src/legacy/js/core/ajax.js +++ b/addons/web/static/src/legacy/js/core/ajax.js @@ -97,17 +97,11 @@ function _genericJsonRpc (fct_name, params, settings, fct) { }); // FIXME: jsonp? - /** - * @param {Boolean} rejectError Returns an error if true. Allows you to cancel - * ignored rpc's in order to unblock the ui and not display an error. - */ - promise.abort = function (rejectError = true) { - if (rejectError) { - rejection({ - message: "XmlHttpRequestError abort", - event: $.Event('abort') - }); - } + promise.abort = function () { + rejection({ + message: "XmlHttpRequestError abort", + event: $.Event('abort') + }); if (!shadow) { core.bus.trigger('rpc_response'); diff --git a/addons/web/static/src/legacy/js/fields/relational_fields.js b/addons/web/static/src/legacy/js/fields/relational_fields.js index 48a12a91db1..d78da7bc3a4 100644 --- a/addons/web/static/src/legacy/js/fields/relational_fields.js +++ b/addons/web/static/src/legacy/js/fields/relational_fields.js @@ -641,6 +641,10 @@ var FieldMany2One = AbstractField.extend({ } if (this.lastNameSearch) { + this.lastNameSearch.catch((reason) => { + // the last rpc name_search will be aborted, so we want to ignore its rejection + reason.event.preventDefault(); + }) this.lastNameSearch.abort(false) } this.lastNameSearch = this._rpc({