[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:
+2
-2
@@ -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 });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user