Skip to content

Deduplicate formatBytes/formatSize utility functions across codebase #14

Description

@kanweiwei

The formatBytes / formatFileSize / formatSize utility function is duplicated 24 times across the codebase (verified 2026-09) instead of being imported from the canonical location.

Canonical location: web/lib/utils.ts exports formatBytes and formatSize

Duplicate locations include:

  • web/utils/change-helpers.tsxformatFileSize
  • web/hooks/useMobileUpload.tsformatFileSize
  • web/storage/diagnostics.tsformatBytes
  • web/opfs/utils/opfs-utils.ts, web/opfs/utils/storage-utils.tsformatBytes
  • web/skills/skill-store.ts, web/skills/skill-resources.tsformatBytes / formatSize
  • web/services/stream-reader.service.tsformatFileSize
  • web/store/offline-queue.store.tsformatFileSize
  • web/agent/tools/formats/image/handler.tsformatSize
  • 12+ files under web/components/ (agent renderers, sync views, export dialogs...)

Note: web/components/agent/tool-renderers/PageScreenshotRenderer.tsx has a formatBytes(base64: string) that is semantically a different function — leave it alone.

What to do:

  1. Pick a few files to start with (don't need to do all at once)
  2. In each file, remove the local formatBytes/formatSize/formatFileSize function
  3. Replace with import { formatBytes } from '@/lib/utils' (or formatSize)
  4. Verify the behavior is the same (some variants differ slightly in decimal places — match the canonical version)
  5. Run cd web && pnpm typecheck to confirm no errors

Skills needed: TypeScript, ability to refactor imports

Estimated time: 1-2 hours (can be done incrementally, a few files per PR)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions