[FIX] web: stop signaling RPC responses on the bus for silent RPCs

When an RPC request is made, we signal it on the bus. This is used,
among other things, to block the UI when the network is unresponsive.
Some RPCs however are meant to be done in the background (eg,
longpolling) and not block the UI as they take a long time by design.

When the response to an RPC arrive, we signal it on the bus so that the
UI can be unblocked. Until this commit, the silent RPCs that never
signaled making an RPC on the bus signal that their response has
arrived, which can cause the UI to be unblocked even though a
non-background RPC was made.

This commit fixes that.

X-original-commit: 695efbfdce200c05b53bc23dc838d81f24589aa3
Part-of: odoo/odoo#80543
This commit is contained in:
Samuel Degueldre
2021-11-30 12:06:06 +00:00
parent e2d89d0b94
commit 35ccfb712e
2 changed files with 10 additions and 4 deletions
@@ -58,12 +58,16 @@ function jsonrpc(env, rpcId, url, params, settings = {}) {
request.addEventListener("load", () => {
if (request.status === 502) {
// If Odoo is behind another server (eg.: nginx)
bus.trigger("RPC:RESPONSE", data.id);
if (!settings.silent) {
bus.trigger("RPC:RESPONSE", data.id);
}
reject(new ConnectionLostError());
return;
}
const { error: responseError, result: responseResult } = JSON.parse(request.response);
bus.trigger("RPC:RESPONSE", data.id);
if (!settings.silent) {
bus.trigger("RPC:RESPONSE", data.id);
}
if (!responseError) {
return resolve(responseResult);
}
@@ -72,7 +76,9 @@ function jsonrpc(env, rpcId, url, params, settings = {}) {
});
// handle failure
request.addEventListener("error", () => {
bus.trigger("RPC:RESPONSE", data.id);
if (!settings.silent) {
bus.trigger("RPC:RESPONSE", data.id);
}
reject(new ConnectionLostError());
});
// configure and send request
@@ -197,7 +197,7 @@ QUnit.test("check trigger RPC:REQUEST and RPC:RESPONSE for a simple rpc", async
assert.verifySteps(["RPC:REQUEST", "RPC:RESPONSE"]);
await env.services.rpc("/test/", {}, { silent: true });
assert.verifySteps(["RPC:RESPONSE"]);
assert.verifySteps([]);
unpatch(browser, "mock.xhr");
});