[FIX] mail: no infinite loop with useXToModel hooks

Before this commit, implementation of `useXToModel` performed
essentially 2 updates in succession, even when ref or component
hasn't changed.

This is a problem, especially when 2 components in hierarchy make
use of `useXToComponents`, as this could lead to infinite loops.

closes odoo/odoo#83344

X-original-commit: 95cb2648484f8529947e2bed14d86a20e6ad37b6
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
2022-01-25 15:41:21 +00:00
parent 4c3530b7d6
commit 0b7ff0bafe
2 changed files with 4 additions and 4 deletions
@@ -22,10 +22,10 @@ export function useComponentToModel({ fieldName, modelName }) {
}
onWillUpdateProps(nextProps => {
const currentRecord = modelManager.models[modelName].get(component.props.localId);
if (currentRecord) {
const nextRecord = modelManager.models[modelName].get(nextProps.localId);
if (currentRecord && currentRecord !== nextRecord) {
currentRecord.update({ [fieldName]: clear() });
}
const nextRecord = modelManager.models[modelName].get(nextProps.localId);
if (nextRecord) {
nextRecord.update({ [fieldName]: component });
}
@@ -24,10 +24,10 @@ export function useRefToModel({ fieldName, modelName, refName }) {
}
onWillUpdateProps(nextProps => {
const currentRecord = modelManager.models[modelName].get(component.props.localId);
if (currentRecord) {
const nextRecord = modelManager.models[modelName].get(nextProps.localId);
if (currentRecord && currentRecord !== nextRecord) {
currentRecord.update({ [fieldName]: clear() });
}
const nextRecord = modelManager.models[modelName].get(nextProps.localId);
if (nextRecord) {
nextRecord.update({ [fieldName]: ref });
}