Skip to content

fix(resource-renderers): show MB when an image size rounds to 1024 KB - #1096

Merged
Rinat S (rsolmano) merged 3 commits into
JetBrains:mainfrom
kevin9327:fix/image-size-mb-rollover
Nov 1, 2026
Merged

Rinat S (rsolmano) merged 3 commits into
JetBrains:mainfrom
kevin9327:fix/image-size-mb-rollover

Conversation

@kevin9327

Copy link
Copy Markdown
Contributor

Problem

formatByteLength (the size shown in the image viewer's info line and in the image diff) picks KB for anything under 1 MiB, then rounds. Sizes in the last half-kilobyte before 1 MiB round up to 1024, so they are shown as 1024 KB instead of moving to MB:

formatByteLength(t, 1024 * 1024 - 1) // main: "1024 KB"   expected: "1.0 MB"

A 1,048,575-byte image reads 1024 KB while a 1,048,576-byte one reads 1.0 MB.

Approach

The KB figure is formatted first, and KB is used only while that rounded figure is below 1024; otherwise the existing MB branch formats it. Every other size, and the 1-decimal/0-decimal rule, is unchanged.

Changes

  • imageState.ts: formatByteLength checks the rounded KB figure before choosing KB.
  • index.test.ts: one size just under 1 MiB reads 1.0 MB, one that rounds to 1023 stays 1023 KB, and exactly 1 MiB stays 1.0 MB. The first case fails on main (1024 KB) and passes with the change.

Screenshots

Not applicable: the visible effect is the size text above (1.0 MB instead of 1024 KB).

Related issues

None found.

Checklist

  • Fast gates pass: bun run lint, bun run typecheck, bun run test. I ran biome check (2.5.0) on the two changed files and the new cases against imageState.ts with bun test (the full index.test.ts needs the locales package installed): they pass, and the first one fails without the fix. I did not run the full workspace gates.
  • E2E suite passes for app-affecting changes. Not run.
  • Before/after screenshots are included for frontend changes, or marked not applicable
  • Relevant SPEC.md / top-level specs updated to reflect any boundary, contract, or behavior change (no contract change)
  • I have read the Contributing guide and agree to the Code of Conduct

This change was prepared with AI assistance; I reviewed it and ran the tests above locally.

@jetbrains-air jetbrains-air Bot 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.

Approved — ready to merge.

@jetbrains-air jetbrains-air Bot 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.

Approved — ready to merge.

@jetbrains-air jetbrains-air Bot 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.

Approved — ready to merge.

@rsolmano
Rinat S (rsolmano) added this pull request to the merge queue Nov 1, 2026
Merged via the queue into JetBrains:main with commit 09f0489 Nov 1, 2026
11 checks passed
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.

2 participants