[FIX] mail: properly render following canceled patching
Before this commit, sometimes component do not properly render changes in the models. Although the modeling is correct, there is a problem in the component not re-rendering itself. The shouldUpdateBasedOnProps component hook did not consider update attempts that could be canceled. This commit adds this consideration, so that it ensures component is eventually rendered correctly Task-2410314 Task-2705078 closes odoo/odoo#80877 X-original-commit: 12c77f52c5a16c95e57de31587d67eda4d582bde Signed-off-by: Sébastien Theys (seb) <seb@odoo.com> Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com>
This commit is contained in:
+8
-1
@@ -2,6 +2,7 @@
|
||||
'use strict';
|
||||
|
||||
const { Component } = owl;
|
||||
const { onPatched } = owl.hooks;
|
||||
|
||||
/**
|
||||
* Compares `a` and `b` up to the given `propsCompareDepth`.
|
||||
@@ -55,7 +56,11 @@ function isEqual(a, b, propsCompareDepth) {
|
||||
*/
|
||||
export function useShouldUpdateBasedOnProps({ propsCompareDepth = {} } = {}) {
|
||||
const component = Component.current;
|
||||
let forceRender = false;
|
||||
component.shouldUpdate = nextProps => {
|
||||
if (forceRender) {
|
||||
return true;
|
||||
}
|
||||
const allNewProps = Object.assign({}, nextProps);
|
||||
const defaultProps = component.constructor.defaultProps;
|
||||
for (const key in defaultProps) {
|
||||
@@ -63,6 +68,8 @@ export function useShouldUpdateBasedOnProps({ propsCompareDepth = {} } = {}) {
|
||||
allNewProps[key] = defaultProps[key];
|
||||
}
|
||||
}
|
||||
return !isEqual(component.props, allNewProps, propsCompareDepth);
|
||||
forceRender = !isEqual(component.props, allNewProps, propsCompareDepth);
|
||||
return forceRender;
|
||||
};
|
||||
onPatched(() => forceRender = false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user