Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: getChildrenByPosition wrong order #554

Open
elsassph opened this issue Dec 9, 2024 · 0 comments
Open

Bug: getChildrenByPosition wrong order #554

elsassph opened this issue Dec 9, 2024 · 0 comments
Labels

Comments

@elsassph
Copy link
Contributor

elsassph commented Dec 9, 2024

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 using ElementCore.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 zIndex first, then _updateTreeOrder in case of identical zIndex,
  • We expect that collected elements are effectively in visible order.

Actual Behavior

  • _updateTreeOrder isn't always correct (elements on top may have a smaller order index than elements behind), which causes collectAtCoord to sometimes return elements in the wrong order,
  • even calling explicitly ElementCore.updateTreeOrder before collecting isn't sufficient,
  • reason may be that both functions (collectAtCoord and updateTreeOrder) 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()

@elsassph elsassph added the bug label Dec 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant