[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:
Alexandre Kühn
2021-12-04 14:05:18 +00:00
parent 64864a6402
commit c114614a28
@@ -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);
}