Repository navigation
[progress] Fix custom min/max semantics to match the indicator - #5095
Conversation
commit: |
Bundle size
PerformanceTotal duration: 1,179.36 ms -63.42 ms(-5.1%) | Renders: 78 (+0) No significant changes — details Check out the code infra dashboard for more information about this PR. |
✅ Deploy Preview for base-ui ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
flaviendelangle
left a comment
There was a problem hiding this comment.
PR review
This is a clean, well-scoped fix that makes Progress.Root normalize value/percentage once and use it everywhere, mirroring the Meter fix (#4904). For the common default range (min=0, max=100) the output is byte-for-byte identical to before (clamp(valueToPercent(v,0,100),0,100) === v for in-range v), so there's no regression on the hot path; the changes only affect custom ranges and overshoot, which is the intended fix. The useValueAsRef removal genuinely fixes the one-commit format lag (confirmed: useValueAsRef updates .current in a layout effect, so the render reading .current sees the stale value). Tests cover the new cases, and no orphaned references to the removed formatNumberValue remain in source. Nothing is merge-blocking.
Bugs (0)
No findings.
Tests (0)
No findings.
Simplifications (0)
No findings.
Docs (1)
1. ℹ️ ${value}% fallback in getDefaultAriaValueText is now unreachable and would be wrong for custom ranges
Location: packages/react/src/progress/root/ProgressRoot.tsx:16
function getDefaultAriaValueText(formattedValue: string | null, value: number | null) {
if (value == null) {
return 'indeterminate progress';
}
return formattedValue || `${value}%`;
}After this PR formattedValue is always a non-empty string for any finite value (it's a percent or formatted number), and value == null returns early — so the `${value}%` branch is dead. It's pre-existing and harmless, but it's now also semantically stale: it hard-codes the old "raw value as percent" assumption the PR deliberately moves away from, so if it ever did fire on a custom range it'd contradict the indicator. Not introduced by this PR and safe to leave; worth dropping to return formattedValue while this file is being touched.
Failure scenario: Future refactor that allows an empty formattedValue would silently resurrect the inconsistent 30%-style text this PR fixed.
Fix: Simplify to return formattedValue; (the value == null guard already handles the only empty case).
Verdict
Approve — correctness-improving fix with matching tests; no 🔴 or 🟡 findings, only one optional dead-code cleanup. I reasoned through the behavior rather than executing the suite (the working tree is on master, so the PR's new tests can't run against the unmodified source locally); the logic and the Meter parity check out.
🤖 Review generated with Claude Code
…st, WebKit abort wording) (#955) * chore(deps): @base-ui/react 1.4.1 → 1.8.0 (root + packages/ui) The only breaking changes in 1.5–1.8 are the OTP Field renames, unused here. Observable changes (controlled-open detection, submenu hover-open, Form focusing the first invalid field, Dialog/Popover ignoring outside clicks from presses that began before open, Select/Menu a11y tree) are why this PR runs the full visual + conformance lanes. Base UI's BASE_UI_ANIMATIONS_DISABLED switch (PR 1) is unchanged in 1.8 and the teeth test passes. SDK UI reachable bytes +5 KB; ratchet + embedded manifest regenerated. TODO row 5 ticked. Refs #760 Co-Authored-By: Claude Fable 5.1 <[email protected]> * test(build): assert Base UI modules are unique per chunk, not "one chunk total" The split-vendor test took "the data-base-ui string appears in exactly one chunk" as its no-duplication check. Base UI 1.8's Tooltip module introduces data-base-ui-tooltip-trigger and bun's splitter places that module in a different shared chunk from the core Base UI chunk — spread, not duplicated (every data-base-ui-* attribute still lives in exactly one chunk). The test now checks three Base UI module markers each appear in exactly one chunk, which is the property #422 guards. Refs #760 Co-Authored-By: Claude Fable 5.1 <[email protected]> * chore(ui): re-capture five snapshots for Base UI 1.8; sweep log for PR 6 feedback-progress-markers (desktop + mobile): the story's bar is value=140 max=200 — 1.4's Progress.Value printed "140%" over a 70 % fill; 1.8 formats the real percentage ("70%"; Base UI 1.7.0 "Fix custom min/max semantics to match the indicator", mui/base-ui#5095). The old baseline encoded the bug. collection-same-records (desktop + mobile): row-menu triggers moved by a pixel. overlays-tooltip (mobile): sub-pixel popup shift. All rendered in the canonical container; four other sub-threshold rewrites left as committed. Refs #760 Co-Authored-By: Claude Fable 5.1 <[email protected]> * test(ui): accept WebKit's wording for navigation-cancelled lazy chunks The story-smoke behavior tests already treat navigation-cancelled chunk loads as non-errors (NS_BINDING_ABORTED, net::ERR_ABORTED); WebKit reports the same event as "Load request cancelled" and tripped once on the axe chunk during a story navigation. All 27 copies of the handler now carry the third wording. WebKit lane re-run: 57 passed. Refs #760 Co-Authored-By: Claude Fable 5.1 <[email protected]> --------- Co-authored-by: Claude Fable 5.1 <[email protected]>
Summary
Progress.Indicatoralready normalized the value againstmin/max(valueToPercent), but the rest ofProgress.Rootused the raw value, so custom-range progress bars were inconsistent. Withmin={20} max={40} value={30}the indicator filled to 50% whileProgress.Valueandaria-valuetextreported30%.This mirrors the fix Meter already shipped (#4904): compute a single clamped value and normalized percentage once in the Root and use it everywhere.
What changed
ProgressRoot.tsx— for finite values, compute oneclampedValueand one clampedpercentageValue, then use them consistently:clampedValue === max(an overshoot likevalue=45, max=40correctly reportscompleteinstead ofprogressing);aria-valuenowisclampedValue, so it can no longer fall outsidearia-valuemin/aria-valuemax;aria-valuetextuseformatNumber(percentageValue / 100, …, { style: 'percent' })when noformatis given, so they match the indicator for any range;formatis read directly instead of throughuseValueAsRef, removing the one-commit lag whenformatchanges.ProgressRootContext.tsx— exposespercentageValue(clamped,nullwhile indeterminate).ProgressIndicator.tsx— readspercentageValuefrom context instead of recomputing it, making the Root the single source of truth (this also clamps the indicator width).formatNumber.ts— removed the now-unusedformatNumberValuehelper that hard-codedvalue / 100and ignoredmin/max.value={null}(indeterminate) behavior is unchanged.Tests
Added regression tests in
ProgressRoot.test.tsx(verified failing before the fix, passing after):min=20 max=40 value=30normalizes the value text,aria-valuetext, and indicator width to 50%;aria-valuenowis clamped tomaxwhen the value overshoots;completeis reported when the value reaches/exceedsmax;formatchange is reflected immediately (no stale-ref lag).Full
ProgressandMeterjsdom suites pass;pnpm typescript,pnpm eslint, andpnpm prettierare clean.