Skip to content

fix(web): show 1.0 MB instead of 1024.0 KB at file size unit boundaries - #6560

Open
SwastikTripathi wants to merge 2 commits into
usememos:mainfrom
SwastikTripathi:fix/file-size-unit-boundary
Open

SwastikTripathi wants to merge 2 commits into
usememos:mainfrom
SwastikTripathi:fix/file-size-unit-boundary

Conversation

@SwastikTripathi

Copy link
Copy Markdown
Contributor

formatFileSize picks the unit before rounding, so a size just under the next unit rounds up to 1024 of the smaller one:

formatFileSize(1048575)        // "1024.0 KB", expected "1.0 MB"
formatFileSize(1073741823)     // "1024.0 MB", expected "1.0 GB"
formatFileSize(1024 ** 5)      // "1.0 undefined", no unit past TB

It's used for attachment metadata, the storage line in account settings and the byte-based usage limits.

The function now moves to the next unit when the rounded value reaches 1024, adds PB, and clamps the unit index to the list.

Added web/tests/format.test.ts: the boundary and PB cases fail before the change. All 200 web test files pass, tsc --noEmit --skipLibCheck is clean and biome is clean on the changed files.

@SwastikTripathi
SwastikTripathi requested a review from a team as a code owner November 14, 2026 03:31
@coderabbitai

coderabbitai Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

formatFileSize now clamps the selected unit, promotes values when rounding would display 1024, and supports PB. Tests cover byte and kilobyte values, unit-promotion boundaries, and petabyte-scale values.

Suggested reviewers: johnnyjoygh, bluedbird

Merge Risk: Minimal · up to 673c0

This change fixes file size display at unit boundaries, so values show as 1.0 MB instead of 1024.0 KB, and adds PB support. The resource stats section now uses the same formatter. The risk of merging is minimal.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: formatFileSize now shows 1.0 MB instead of 1024.0 KB at unit boundaries. The raw summary confirms the rounding-based unit promotion in web/src/utils/format.ts, and the…
Description check Passed The description explains the bug, gives before and after examples for formatFileSize, lists the affected usages, and describes the fix and the added tests. It matches the changeset in web/src/utils/fo…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: formatFileSize now shows 1.0 MB instead of 1024.0 KB at unit boundaries. The raw summary confirms the rounding-based unit promotion in web/src/utils/format.ts, and the title's scope fits the change.

Full details: Description check

Explanation

The description explains the bug, gives before and after examples for formatFileSize, lists the affected usages, and describes the fix and the added tests. It matches the changeset in web/src/utils/format.ts and web/tests/format.test.ts.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Some tools did not complete. Review the errors below.

Biome (2.6.3)

web/src/components/Settings/ResourceStatsSection.tsx

Biome could not lint this file: nested root configuration. Check the repository's Biome configuration and plugins.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: af16cfd5-14cc-4435-9c18-8d68c3b98e33
Commits

Reviewing files that changed from the base of the PR and between 8c87eef and 673c03a.

Files selected for processing: 1

  • web/src/components/Settings/ResourceStatsSection.tsx

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.

The resource stats section had its own copy of the size formatter with
the same unit boundary bug (1048575 bytes showed as 1024.0 KB).
@SwastikTripathi

Copy link
Copy Markdown
Contributor Author

Added 673c03a: the admin resource stats section had its own copy of the size formatter (formatBytes in ResourceStatsSection.tsx) with the same boundary bug, so 1048575 bytes showed as "1024.0 KB" there too. It now uses formatFileSize. pnpm lint (tsc + biome) is clean and all 200 web test files pass.

This branch has not been deployed

No deployments
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.

1 participant