Skip to content

Fix operator precedence in timeline pageSize calculation - #303258

Merged
Dmitriy Vasyura (dmitrivMS) merged 1 commit into
microsoft:mainfrom
ShehabSherif0:fix/timeline-pagesize-operator-precedence
Aug 7, 2026
Merged

Fix operator precedence in timeline pageSize calculation#303258
Dmitriy Vasyura (dmitrivMS) merged 1 commit into
microsoft:mainfrom
ShehabSherif0:fix/timeline-pagesize-operator-precedence

Conversation

@ShehabSherif0

Copy link
Copy Markdown
Contributor

Fixes #303257

Bug

In TimelinePane.pageSize, the nullish coalescing operator (??) has lower precedence than division (/), causing renderHeight (pixels) to be used directly as the page size instead of renderHeight / ItemHeight (items).

Current code

pageSize = Math.max(20, Math.floor((this.tree?.renderHeight ?? 0 / ItemHeight) + (this.pageOnScroll ? 1 : -1)));

JavaScript parses this as this.tree?.renderHeight ?? (0 / ItemHeight) because / binds tighter than ??.

When the tree exists (the common case), renderHeight is a pixel value (e.g., 500). Without the division by ItemHeight (22), the computed page size is ~499 instead of the intended ~22. This causes a ~24x over-fetch on every timeline load and "Load more" action.

Fix

Add parentheses to enforce the intended grouping:

pageSize = Math.max(20, Math.floor(((this.tree?.renderHeight ?? 0) / ItemHeight) + (this.pageOnScroll ? 1 : -1)));

Verification

const ItemHeight = 22, renderHeight = 500;

// Buggy:  renderHeight ?? (0 / ItemHeight)  => 500  =>  pageSize = 499
// Fixed:  (renderHeight ?? 0) / ItemHeight   => 22.7 =>  pageSize = 21

When the tree is null/undefined, both produce pageSize = 20 (via Math.max), so the fallback path is unaffected.

The nullish coalescing operator (??) has lower precedence than division (/),
so `this.tree?.renderHeight ?? 0 / ItemHeight` parses as
`this.tree?.renderHeight ?? (0 / ItemHeight)` instead of the intended
`(this.tree?.renderHeight ?? 0) / ItemHeight`.

This causes the fallback page size to use renderHeight directly (e.g. 500)
instead of dividing by ItemHeight (22), resulting in ~24x over-fetching of
timeline items on every load.
Copilot AI review requested due to automatic review settings March 19, 2026 16:56

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes an operator-precedence bug in TimelinePane.pageSize that caused pixel renderHeight values to be treated as an item count, leading to significant over-fetching in the Timeline view.

Changes:

  • Adds parentheses around the nullish-coalescing expression to ensure renderHeight is divided by ItemHeight before computing the page size.

You can also share your feedback on Copilot code review. Take the survey.

@dmitrivMS
Dmitriy Vasyura (dmitrivMS) merged commit 6d0617c into microsoft:main Aug 7, 2026
48 of 51 checks passed
@vs-code-engineering vs-code-engineering Bot added this to the 1.133.0 milestone Aug 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Timeline: operator precedence bug in pageSize calculation causes ~24x over-fetch

7 participants