From c7d8ae18bb0fe3834f27e1deb998a3a6bae92357 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 3 May 2026 22:54:31 +0000 Subject: [PATCH 1/5] Don't show fractional bytes in file size display filesize's `pad: true` option pads results like "5 B" to "5.00 B", but fractional bytes are nonsensical. Add a `formatBytes` wrapper that suppresses padding when the unit is bytes, and use it in FileInput and the image upload progress display. Closes #3209 --- app/forms/image-upload.tsx | 6 ++---- app/ui/lib/FileInput.tsx | 4 ++-- app/util/units.spec.ts | 30 ++++++++++++++++++++++++++++++ app/util/units.ts | 13 +++++++++++++ 4 files changed, 47 insertions(+), 6 deletions(-) create mode 100644 app/util/units.spec.ts diff --git a/app/forms/image-upload.tsx b/app/forms/image-upload.tsx index facc6b28ea..c14a554419 100644 --- a/app/forms/image-upload.tsx +++ b/app/forms/image-upload.tsx @@ -7,7 +7,6 @@ */ import { skipToken, useQuery } from '@tanstack/react-query' import cn from 'classnames' -import { filesize } from 'filesize' import pMap from 'p-map' import pRetry from 'p-retry' import { useRef, useState } from 'react' @@ -50,10 +49,9 @@ import { invariant } from '~/util/invariant' import { docLinks, links } from '~/util/links' import { pb } from '~/util/path-builder' import { isAllZeros } from '~/util/str' -import { GiB, KiB } from '~/util/units' +import { formatBytes, GiB, KiB } from '~/util/units' -/** Format file size with two decimal points */ -const fsize = (bytes: number) => filesize(bytes, { base: 2, pad: true }) +const fsize = (bytes: number) => formatBytes(bytes, { pad: true }) type FormValues = { imageName: string diff --git a/app/ui/lib/FileInput.tsx b/app/ui/lib/FileInput.tsx index 11b9c060c7..8fbaf40e9e 100644 --- a/app/ui/lib/FileInput.tsx +++ b/app/ui/lib/FileInput.tsx @@ -6,7 +6,6 @@ * Copyright Oxide Computer Company */ import cn from 'classnames' -import { filesize } from 'filesize' import { useRef, useState, @@ -20,6 +19,7 @@ import { mergeRefs } from 'react-merge-refs' import { Document16Icon, Error16Icon } from '@oxide/design-system/icons/react' import { Truncate } from '~/ui/lib/Truncate' +import { formatBytes } from '~/util/units' export type FileInputProps = Omit, 'type' | 'onChange'> & { onChange: (f: File | null) => void @@ -100,7 +100,7 @@ export function FileInput({
- ({filesize(file.size, { base: 2, pad: true })}) + ({formatBytes(file.size, { pad: true })})