Skip to content

Commit ab04189

Browse files
shku-odooWajih-Wanis
authored andcommitted
[FIX] web: Prevent focusCell() error on destroyed components
Steps to Reproduce: - Open a Repair Order form view in Odoo 17 or 18. - Navigate to the Parts tab. - In the list view of parts, click the Smart Button on any part line. - A pop-up form view opens showing detailed operations. - Click the “Pick From” field value, but don't change its value. - Click the Save button in the pop-up. - Observe the browser console for the error: TypeError: Cannot read properties of null (reading 'querySelector') at ListRenderer.focusCell Root Cause: - Asynchronous patching in OWL (onPatched with await Promise.resolve()) continues execution after the next tick, even if the component is destroyed. - When the component is destroyed, OWL sets status(this) = 3 (DESTROYED). - focusCell() accesses DOM using querySelector, which fails if the component is destroyed. - The code did not check the component status before calling focusCell(). Fix: - Added `if (status(this) === destroyed) return;` to stop focusCell() execution on destroyed components. - Ensured async patching is handled safely with await Promise.resolve(). 17: https://github.com/odoo/odoo/blob/f9726cfe93e8850a38d9de06acfa5d78473b50b0/addons/web/static/src/views/list/list_renderer.js#L223 18: https://github.com/odoo/odoo/blob/1cac54db8634267a780b4011291f1e8a80ac5f5b/addons/web/static/src/views/list/list_renderer.js#L213 closes odoo#232156 X-original-commit: c4ec69a Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
1 parent e311e98 commit ab04189

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

addons/web/static/src/views/list/list_renderer.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import {
2626
onPatched,
2727
onWillPatch,
2828
onWillRender,
29+
status,
2930
useExternalListener,
3031
useRef,
3132
} from "@odoo/owl";
@@ -214,7 +215,9 @@ export class ListRenderer extends Component {
214215
// HACK: we need to wait for the next tick to be sure that the Field components are patched.
215216
// OWL don't wait the patch for the children components if the children trigger a patch by himself.
216217
await Promise.resolve();
217-
218+
if (status(this) === "destroyed") {
219+
return;
220+
}
218221
if (this.activeElement !== this.uiService.activeElement) {
219222
return;
220223
}

0 commit comments

Comments
 (0)