-
Notifications
You must be signed in to change notification settings - Fork 110
Open
Labels
Description
Problem/Opportunity
getChildrenByPosition may return wrong results, due to inconsistent _updateTreeOrder tagging.
Note: we don't (and won't) use zIndex and only use "natural" elements order.
Steps to reproduce
TBD. This requires a complex app tree structure which I couldn't reproduce outside of our application.
Expected Behavior
- When using
stage.getChildrenByPosition, elements are collected usingElementCore.collectAtCoord, - Inside this collection function, the results are sorted (at every step of the recursion!), as a flat list, using
ElementCore.sortZIndexedChildren, - This sorting function sorts based on
zIndexfirst, then_updateTreeOrderin case of identicalzIndex, - We expect that collected elements are effectively in visible order.
Actual Behavior
_updateTreeOrderisn't always correct (elements on top may have a smaller order index than elements behind), which causescollectAtCoordto sometimes return elements in the wrong order,- even calling explicitly
ElementCore.updateTreeOrderbefore collecting isn't sufficient, - reason may be that both functions (
collectAtCoordandupdateTreeOrder) do not have identical conditions for skipping/considering elements.
Notes (Optional)
We managed to work around the issue by force re-indexing the elements:
function updateTreeOrder(core: IElementCoreInternal, order: number = 0): number {
core._updateTreeOrder = order++;
if (core._children) {
core._children.forEach((child) => {
order = updateTreeOrder(child, order);
});
}
return order;
}
Invoked as:
updateTreeOrder(stage.root.core);
Just before calling stage.getChildrenByPosition()