From c9c6a00449eb72c41234940aead9832b8c46d030 Mon Sep 17 00:00:00 2001 From: Jinjing <6427696+AmethystLiang@users.noreply.github.com> Date: Fri, 9 Oct 2026 05:58:50 -0700 Subject: [PATCH] Keep usage overflow chip width stable as hidden count changes (#26873) The "+N" overflow chip in the status bar changed width whenever its count changed, so the density probe that decides how many usage chips fit kept re-measuring. Reserve the width of the provider-count label with an invisible sizer span, so the chip keeps the same size across counts. - Pass the total provider count into UsageOverflowChip and render it in an invisible, grid-stacked sizer span. - Overlay the visible "+N" label on the same grid cell so the chip width tracks the total, not the hidden subset. - Add an e2e test that loads ten usage providers, shrinks the viewport to collapse them, and checks the chip width stays stable and no "Maximum update depth" or React #185 errors occur. --- .../status-bar/StatusBarProviderSegment.tsx | 10 +- .../status-bar/StatusBarSurface.tsx | 1 + .../status-bar/cursor-usage-headline.test.tsx | 4 +- tests/e2e/status-bar-density-overflow.spec.ts | 101 ++++++++++++++++++ 4 files changed, 113 insertions(+), 3 deletions(-) create mode 100644 tests/e2e/status-bar-density-overflow.spec.ts diff --git a/src/renderer/src/components/status-bar/StatusBarProviderSegment.tsx b/src/renderer/src/components/status-bar/StatusBarProviderSegment.tsx index f9a484ede41..aac39d99e25 100644 --- a/src/renderer/src/components/status-bar/StatusBarProviderSegment.tsx +++ b/src/renderer/src/components/status-bar/StatusBarProviderSegment.tsx @@ -95,9 +95,11 @@ export function getUsageTone(p: ProviderRateLimits): UsageTone { */ export function UsageOverflowChip({ hidden, + providerCount, display }: { hidden: readonly ProviderRateLimits[] + providerCount: number display: UsagePercentageDisplay }): React.JSX.Element { const tones = hidden.map(getUsageTone) @@ -128,9 +130,13 @@ export function UsageOverflowChip({ value0: names } )} - className="inline-flex h-4 items-center rounded-full border border-border px-1.5 text-[11px] font-medium tabular-nums text-foreground data-[tone=urgent]:border-destructive/40 data-[tone=urgent]:text-destructive data-[tone=warning]:border-status-warning-border data-[tone=warning]:text-status-warning data-[usage-collapsed=true]:invisible data-[usage-collapsed=true]:absolute" + className="inline-grid h-4 items-center justify-items-center rounded-full border border-border px-1.5 text-[11px] font-medium tabular-nums text-foreground data-[tone=urgent]:border-destructive/40 data-[tone=urgent]:text-destructive data-[tone=warning]:border-status-warning-border data-[tone=warning]:text-status-warning data-[usage-collapsed=true]:invisible data-[usage-collapsed=true]:absolute" > - +{Math.max(1, hidden.length)} + {/* Why: count changes must not invalidate density measurements and restart probing. */} + + +{Math.max(1, hidden.length)} ) } diff --git a/src/renderer/src/components/status-bar/StatusBarSurface.tsx b/src/renderer/src/components/status-bar/StatusBarSurface.tsx index 0b542cc875e..cd3c1dea6dc 100644 --- a/src/renderer/src/components/status-bar/StatusBarSurface.tsx +++ b/src/renderer/src/components/status-bar/StatusBarSurface.tsx @@ -161,6 +161,7 @@ export function StatusBarSurface({ ))} {collapseUsage ? (