LearnNewsExamplesServices
Frontmatter
id8562
titleRefactor TimelineCanvas.onTimelineDataLoad to use waitForDomRect
stateClosed
labels
airefactoring
assigneestobiu
createdAtJan 11, 2026, 11:59 PM
updatedAtJan 12, 2026, 12:27 AM
githubUrlhttps://github.com/neomjs/neo/issues/8562
authortobiu
commentsCount1
parentIssue8398
subIssues[]
subIssuesCompleted0
subIssuesTotal0
blockedBy[]
blocking[]
closedAtJan 12, 2026, 12:27 AM

Refactor TimelineCanvas.onTimelineDataLoad to use waitForDomRect

Closed v11.20.0 airefactoring
tobiu
tobiu commented on Jan 11, 2026, 11:59 PM

The current implementation of onTimelineDataLoad in TimelineCanvas.mjs uses a recursive retry logic with setTimeout to wait for DOM elements (ticket avatars/badges) to be available. This mimics the behavior of waitForDomRect, but in an ad-hoc, less robust way.

We should refactor this method to be async and explicitly use waitForDomRect for the target elements. This will simplify the code, leverage the framework's built-in robust waiting mechanism, and ensure consistent behavior.

Proposed Change:

  1. Make onTimelineDataLoad async.
  2. Replace the me.timeout(delay).then(...) and the retry logic with a call to me.waitForDomRect({ id: ids, attempts: 20, delay: 50 }).
  3. Handle the case where waitForDomRect returns valid rects directly.

Current Logic:

        // If this is a fresh data load (not a resize), wait a bit for DOM
        let delay = attempt === 0 ? 0 : 50;

        me.timeout(delay).then(async () => {
            // ... fetch rects
            // ... retry if missing
        });

New Logic (Conceptual):

    async onTimelineDataLoad(records, isResize = false) {
        // ... (guards)
        let ids = records.map(r => `${r.id}-target`);
        let rects = await me.waitForDomRect({ id: ids, attempts: 20, delay: 50 });
        // ... (process rects)
    }

This change aligns TimelineCanvas with the robust pattern used elsewhere (e.g., in MainContainerController).

tobiu added the ai label on Jan 11, 2026, 11:59 PM
tobiu added the refactoring label on Jan 11, 2026, 11:59 PM
tobiu referenced in commit 605635a - "fix: Prevent race condition in TimelineCanvas by making sections store update optional (#8562, #8563)" on Jan 12, 2026, 12:26 AM
tobiu assigned to @tobiu on Jan 12, 2026, 12:26 AM
tobiu
tobiu Jan 12, 2026, 12:26 AM

Input from Gemini 3 Pro:

✦ I have refactored onTimelineDataLoad in TimelineCanvas.mjs to use waitForDomRect.

Changes:

  • Replaced the manual recursive setTimeout logic with a single await this.waitForDomRect({ attempts: 20, delay: 50, id: ids }).
  • Added a stale data check (if (me.lastRecords !== records) return) to prevent race conditions from out-of-order updates.
  • Ensured timelineRect is fetched (as a check) but doesn't strictly block execution if items are found, improving robustness.
  • Updated onResize to call onTimelineDataLoad with the correct arguments (removed the unused attempt param).

This makes the method cleaner, more robust, and fully async.

tobiu added parent issue #8398 on Jan 12, 2026, 12:26 AM
tobiu closed this issue on Jan 12, 2026, 12:27 AM