Skip to content

Commit 4a42389

Browse files
committed
#7076 manager.VDomUpdate: getAdjustedUpdateDepth()
1 parent f470126 commit 4a42389

2 files changed

Lines changed: 47 additions & 2 deletions

File tree

src/manager/VDomUpdate.mjs

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,42 @@ class VDomUpdate extends Collection {
7777
item.children.push({childId, resolve});
7878
}
7979

80+
/**
81+
* Calculates the adjusted updateDepth for a parent component based on its merged children.
82+
* This method is called by the parent component right before it executes its own VDOM update.
83+
* @param {String} ownerId
84+
* @returns {Number|null} The adjusted update depth or null if no merged children are found
85+
*/
86+
getAdjustedUpdateDepth(ownerId) {
87+
let me = this,
88+
owner = Neo.getComponent(ownerId),
89+
item = me.mergedCallbackMap.get(ownerId),
90+
maxDepth = owner?.updateDepth ?? 1,
91+
newDepth;
92+
93+
if (item) {
94+
item.children.forEach(child => {
95+
if (child.childUpdateDepth === -1) {
96+
newDepth = -1;
97+
} else {
98+
// The new depth is the distance to the child plus its own update depth,
99+
// minus 1 because the child's root is at the parent's level 1.
100+
newDepth = child.distance + child.childUpdateDepth - 1;
101+
}
102+
103+
if (newDepth === -1) {
104+
maxDepth = -1;
105+
} else if (maxDepth !== -1) {
106+
maxDepth = Math.max(maxDepth, newDepth);
107+
}
108+
});
109+
110+
return maxDepth;
111+
}
112+
113+
return null;
114+
}
115+
80116
/**
81117
* @param {String} ownerId
82118
*/
@@ -85,7 +121,9 @@ class VDomUpdate extends Collection {
85121
item = me.mergedCallbackMap.get(ownerId);
86122

87123
if (item) {
88-
item.callbacks.forEach(callback => callback());
124+
item.children.forEach(child => {
125+
child.callbacks.forEach(callback => callback());
126+
});
89127
me.mergedCallbackMap.remove(item);
90128
}
91129
}

src/mixin/VdomLifecycle.mjs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ class VdomLifecycle extends Base {
376376
if (parent) {
377377
// We are checking for parent.updateDepth, since we care about the depth of the next update cycle
378378
if (parent.needsVdomUpdate && me.hasUpdateCollision(parent.updateDepth, distance)) {
379-
VDomUpdate.registerMerged(parent.id, me.id, me.resolveUpdateCache);
379+
VDomUpdate.registerMerged(parent.id, me.id, me.resolveUpdateCache, me.updateDepth, distance);
380380
resolve && NeoArray.add(me.resolveUpdateCache, resolve);
381381
me.resolveUpdateCache = [];
382382
return true
@@ -653,6 +653,13 @@ class VdomLifecycle extends Base {
653653
&& mounted
654654
&& vnode
655655
) {
656+
// Check for merged child updates and adjust the update depth accordingly
657+
let adjustedDepth = VDomUpdate.getAdjustedUpdateDepth(me.id);
658+
659+
if (adjustedDepth !== null) {
660+
me.updateDepth = adjustedDepth;
661+
}
662+
656663
// Verify that the critical rendering path => CSS files for the new tree is in place
657664
if (currentWorker.countLoadingThemeFiles !== 0) {
658665
currentWorker.on('themeFilesLoaded', function() {

0 commit comments

Comments
 (0)