From b7dfc7f71c9d1f8205060b828f57aac356f6db7e Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Thu, 20 Oct 2022 07:58:38 +0000 Subject: [PATCH] [FIX] web: SearchPanel: fix race condition with sections This commit fixes a race condition spotted by the click all test, in the Lunch application. To reproduce, go to Lunch > Configuration > Products, in the list view, toggle filter "Archived" s.t. there's no record matching the domain (and nothing displayed in the search panel anymore), then switch to kanban view, and remove the filter. On a multi-build, this scenario fails ~4 times out of 10. The issue occurs because a re-rendering of the search panel is triggered by its parent (because of the filter change), but the search panel didn't compute its active sections yet (this is done when the "update" event is triggered on the search model). The exact situation is hard to reproduce, but if there are non empty sections in the model, and the active sections haven't been computed yet in the search panel, it crashes. For instance, it happens all the time by delaying the promise returned by "_fetchSections". This commit doesn't introduce a qunit test because we didn't manage to reproduce the exact same situation in a test. This makes the Lunch click all test pass all the time though. closes odoo/odoo#103638 X-original-commit: b84df7e08b4d413de2e8a0b1df6cb8d6ad4b08cf Signed-off-by: Mathieu Duckerts-Antoine Signed-off-by: Aaron Bohy (aab) --- addons/web/static/src/search/search_panel/search_panel.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/addons/web/static/src/search/search_panel/search_panel.js b/addons/web/static/src/search/search_panel/search_panel.js index fbf3f759bbf..72cb802be4e 100644 --- a/addons/web/static/src/search/search_panel/search_panel.js +++ b/addons/web/static/src/search/search_panel/search_panel.js @@ -2,7 +2,7 @@ import { useBus } from "@web/core/utils/hooks"; -const { Component, onMounted, onWillStart, useRef, useState } = owl; +const { Component, onMounted, onWillUpdateProps, onWillStart, useRef, useState } = owl; //------------------------------------------------------------------------- // Helpers @@ -59,6 +59,11 @@ export class SearchPanel extends Component { this.updateActiveValues(); }); + onWillUpdateProps(async () => { + await this.env.searchModel.sectionsPromise; + this.updateActiveValues(); + }); + onMounted(() => { this.updateGroupHeadersChecked(); if (this.hasImportedState) {