Skip to content

Code Quality: Prevent exceptions when available size is zero or negative #17477

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

Merged
merged 2 commits into from
Aug 21, 2025

Conversation

seer-by-sentry[bot]
Copy link
Contributor

Resolved / Related Issues

To prevent extra work, all changes to the Files codebase must link to an approved issue marked as Ready to build. Please insert the issue number following the hashtag with the issue number that this Pull Request resolves.

Steps used to test these changes

Stability is a top priority for Files and all changes are required to go through testing before being merged into the repo. Please include a list of steps that you used to test this PR.

  1. The issue was that: BreadcrumbBar's ItemsRepeater received zero width from parent Grid, causing WinUI's MeasureOverride to divide by zero.
  2. Prevents DivideByZeroException in WinUI when availableSize has zero dimensions by providing a minimal positive size for measurement.
  3. Handles zero or negative available width by hiding all items in the breadcrumb bar.

This fix was generated by Seer in Sentry, triggered by Yair. 👁️ Run ID: 903159

Not quite right? Click here to continue debugging with Seer.

@yaira2 yaira2 requested a review from Copilot August 20, 2025 14:45
@yaira2 yaira2 marked this pull request as ready for review August 20, 2025 14:45
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes a DivideByZeroException in the BreadcrumbBar control that occurred when the available size was zero or negative. The fix ensures proper measurement and visibility handling when the breadcrumb bar receives insufficient space.

  • Prevents division by zero exceptions in WinUI by providing minimum positive size for measurements
  • Hides all breadcrumb items when available width is zero or negative
  • Maintains the original layout logic while adding safety checks for edge cases

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@@ -33,14 +33,21 @@ protected override Size MeasureOverride(NonVirtualizingLayoutContext context, Si
var accumulatedSize = new Size(0, 0);

Choose a reason for hiding this comment

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

This should return early if the children count is zero or no children available
if (context?.Children == null || context.Children.Count == 0)
{
return Size.Empty;
}

Copy link
Member

Choose a reason for hiding this comment

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

Are you able to follow up with a PR? We're currently working on polishing things up for v4, but this should be a quick one to review.

Choose a reason for hiding this comment

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

yeah, sure. was there an issue number for this?

Copy link
Member

Choose a reason for hiding this comment

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

Not currently

Choose a reason for hiding this comment

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

@yaira2 I have created a PR: #17483
Let me know if that helps

@yaira2 yaira2 changed the title Fix: Prevent exceptions when available size is zero or negative Code Quality: Prevent exceptions when available size is zero or negative Aug 21, 2025
@yaira2 yaira2 added ready to merge Pull requests that are approved and ready to merge and removed needs - code review labels Aug 21, 2025
@yaira2 yaira2 merged commit 1e67aa4 into main Aug 21, 2025
8 checks passed
@yaira2 yaira2 deleted the seer/fix/breadcrumb-zero-size branch August 21, 2025 04:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready to merge Pull requests that are approved and ready to merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants