Skip to content

[progress][meter] De-duplicate formatValue function#3805

Merged
sai6855 merged 5 commits into
mui:masterfrom
sai6855:deduplicate-formatvalue
Jan 21, 2026
Merged

[progress][meter] De-duplicate formatValue function#3805
sai6855 merged 5 commits into
mui:masterfrom
sai6855:deduplicate-formatvalue

Conversation

@sai6855

@sai6855 sai6855 commented Jan 21, 2026

Copy link
Copy Markdown
Member

I was going through this issue #3688 and this comment #3709 (comment), changes in this PR reduced size by 68B without hurting readability. Felt it as quick win

image

@sai6855 sai6855 added type: enhancement It’s an improvement, but we can’t make up our mind whether it's a bug fix or a new feature. component: progress Changes related to the progress component. labels Jan 21, 2026
@pkg-pr-new

pkg-pr-new Bot commented Jan 21, 2026

Copy link
Copy Markdown
  • vite-css-base-ui-example

    pnpm add https://pkg.pr.new/mui/base-ui/@base-ui/react@3805
    
    pnpm add https://pkg.pr.new/mui/base-ui/@base-ui/utils@3805
    

commit: 3cf9672

@mui-bot

mui-bot commented Jan 21, 2026

Copy link
Copy Markdown

Bundle size report

Bundle Parsed size Gzip size
@base-ui/react ▼-68B(-0.02%) ▼-24B(-0.02%)

Details of bundle changes


Check out the code infra dashboard for more information about this PR.

@netlify

netlify Bot commented Jan 21, 2026

Copy link
Copy Markdown

Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit 0cf68d5
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/6970981027328e0008387177
😎 Deploy Preview https://deploy-preview-3805--base-ui.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@sai6855 sai6855 requested review from LukasTy and mj12albert January 21, 2026 09:18
@sai6855 sai6855 marked this pull request as ready for review January 21, 2026 09:18
Copilot AI review requested due to automatic review settings January 21, 2026 09:18

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR de-duplicates the formatValue function that was identically implemented in both the Progress and Meter components by extracting it to a shared utility module. This refactoring reduces bundle size by 68 bytes without affecting functionality or readability, supporting the ongoing effort to optimize Base UI's bundle size (issue #3688).

Changes:

  • Extracted the formatValue function to utils/formatNumber.ts as a shared utility
  • Updated ProgressRoot and MeterRoot to import the shared function instead of maintaining local copies

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
packages/react/src/utils/formatNumber.ts Added the shared formatValue function that handles value formatting with optional locale and format options
packages/react/src/progress/root/ProgressRoot.tsx Removed local formatValue function and imported the shared version from utils
packages/react/src/meter/root/MeterRoot.tsx Removed local formatValue function and imported the shared version from utils

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@greptile-apps

greptile-apps Bot commented Jan 21, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

Deduplicates the formatValue function from MeterRoot and ProgressRoot components by moving it to the shared utils/formatNumber.ts module, achieving a 68B bundle size reduction.

  • The original implementations in both components were nearly identical, differing only in the first parameter's type (number in MeterRoot vs number | null in ProgressRoot)
  • The new shared implementation uses number | null to accommodate both use cases
  • Type safety is maintained since MeterRoot's value prop is typed as number (non-nullable), preventing null values from being passed
  • The change aligns with the goal of reducing Base UI's bundle size to be more competitive with Radix (currently 20KB larger)

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The refactoring is straightforward and maintains backward compatibility. The shared implementation is identical to ProgressRoot's original version and handles both nullable and non-nullable values correctly. Type safety ensures MeterRoot will never pass null values despite the function accepting them.
  • No files require special attention

Important Files Changed

Filename Overview
packages/react/src/utils/formatNumber.ts Added shared formatValue function to deduplicate identical logic from MeterRoot and ProgressRoot
packages/react/src/meter/root/MeterRoot.tsx Removed local formatValue function and imported the shared utility from formatNumber.ts
packages/react/src/progress/root/ProgressRoot.tsx Removed local formatValue function and imported the shared utility from formatNumber.ts

@greptile-apps

greptile-apps Bot commented Jan 21, 2026

Copy link
Copy Markdown
Contributor

Greptile's behavior is changing!

From now on, if a review finishes with no comments, we will not post an additional "statistics" comment to confirm that our review found nothing to comment on. However, you can confirm that we reviewed your changes in the status check section.

This feature can be toggled off in your Code Review Settings by deselecting "Create a status check for each PR".

@LukasTy LukasTy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice optimization. 👍

});
}

export function formatValue(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: Given that this is now a more global util, I feel like formatNumberValue might be a more precise name for it. 🤔
WDYT?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, makes sense. I'll update and merge

@netlify

netlify Bot commented Jan 21, 2026

Copy link
Copy Markdown

Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit 3cf9672
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/6970a6ddc53c5600086ede14
😎 Deploy Preview https://deploy-preview-3805--base-ui.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@sai6855 sai6855 merged commit 5793bd6 into mui:master Jan 21, 2026
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component: progress Changes related to the progress component. performance type: enhancement It’s an improvement, but we can’t make up our mind whether it's a bug fix or a new feature.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants