fix: include controls without data-sap-ui attribute in control tree#344
Conversation
plamenivanov91
left a comment
There was a problem hiding this comment.
- Performance concern — getDomRef() called on every DOM node with an id
The condition "node.id && control" will match for any DOM element that happens to have an id matching a registered UI5 element. For deeply nested DOMs this adds overhead since getDomRef() can trigger layout/reflow in some edge cases. The "typeof control.getDomRef === function" check is redundant because isA("sap.ui.core.Control") guarantees getDomRef exists on the prototype. It adds defensive noise without value. You can simplify to:
} else if (node.id && control && control.isA("sap.ui.core.Control") && control.getDomRef && control.getDomRef() === node) {
- Swallowed exception — empty catch block
try { domRef = control.getDomRef(); } catch (e) { // getDomRef() can throw when a control is partially destroyed or mid re-render }
While the comment explains the intent, silently swallowing exceptions can hide bugs during development. Consider at minimum a console.debug or gating it behind a known condition (e.g. control.bIsDestroyed) to narrow the catch scope rather than blanket-catching everything.
- Consider unit tests (if possible)
|
About the unit tests: |
Problem:
sap.ui.core.HTMLand similar controls that render raw HTML were invisible in the control tree because the tree walker only detected controls via thedata-sap-uiDOM attribute, causing their children to appear flattened at the wrong level.Solution:
getDomRef()directly in the condition, correctly preserving parent-child hierarchy.Related to: #343