LearnNewsExamplesServices
Frontmatter
id8560
titleReplace hardcoded timeout in MainContainerController with deterministic wait
stateClosed
labels
airefactoringperformance
assigneestobiu
createdAtJan 11, 2026, 11:45 PM
updatedAtJan 11, 2026, 11:55 PM
githubUrlhttps://github.com/neomjs/neo/issues/8560
authortobiu
commentsCount1
parentIssue8398
subIssues[]
subIssuesCompleted0
subIssuesTotal0
blockedBy[]
blocking[]
closedAtJan 11, 2026, 11:55 PM

Replace hardcoded timeout in MainContainerController with deterministic wait

Closed v11.20.0 airefactoringperformance
tobiu
tobiu commented on Jan 11, 2026, 11:45 PM

In apps/portal/view/news/tickets/MainContainerController.mjs, onRouteItem uses a hardcoded delay:

            if (!oldValue?.hashString?.startsWith('/news/tickets')) {
                await me.timeout(100);
                tree.scrollToItem(itemId)
            }

This delay is intended to wait for the tree to expand and render before scrolling. However, 100ms is arbitrary and can be flaky or wasteful.

Proposed Solution: Replace await me.timeout(100) with a deterministic wait, likely await tree.promiseUpdate(), which ensures that the VDOM updates (triggered by tree.expandParents(itemId)) have been processed and applied to the DOM.

We need to verify if promiseUpdate() is sufficient for scrollToItem to work (which relies on document.getElementById).

tobiu added the ai label on Jan 11, 2026, 11:45 PM
tobiu added the refactoring label on Jan 11, 2026, 11:45 PM
tobiu added the performance label on Jan 11, 2026, 11:45 PM
tobiu referenced in commit 5eb836d - "refactor: Replace timeouts with robust DOM waits in TreeList logic (#8560)" on Jan 11, 2026, 11:54 PM
tobiu assigned to @tobiu on Jan 11, 2026, 11:54 PM
tobiu
tobiu Jan 11, 2026, 11:54 PM

Input from Gemini 3 Pro:

✦ I have replaced the hardcoded timeout(100) in MainContainerController.mjs with a robust waitForDomRect check.

Changes:

  • Replaced await me.timeout(100) with await tree.waitForDomRect({id, attempts: 20, delay: 20}).
  • This ensures the code waits for the tree item to be truly rendered, visible, and laid out (expanded) before attempting to scroll to it.
  • This addresses the flakiness of fixed timeouts while ensuring scrolling only happens when the target is ready.

I also removed the arbitrary 20ms delay in TreeList.afterSetCurrentPageRecord as discussed, assuming the reactive update cycle should handle selection state correctly.

tobiu added parent issue #8398 on Jan 11, 2026, 11:54 PM
tobiu closed this issue on Jan 11, 2026, 11:55 PM
tobiu cross-referenced by #8561 on Jan 11, 2026, 11:56 PM