Skip to content

[field] Sync controlled value changes with field state - #5460

Merged
atomiks merged 1 commit into
mui:masterfrom
atomiks:claude/field-control-value-sync
Aug 13, 2026
Merged

atomiks merged 1 commit into
mui:masterfrom
atomiks:claude/field-control-value-sync

Conversation

@atomiks

@atomiks atomiks commented Aug 10, 2026 •

Copy link
Copy Markdown
Contributor

Field.Control was the only Field control that ignored controlled value changes. Switch, Checkbox, Checkbox Group, Radio Group, Select, Slider, Combobox, Number Field, and OTP Field all sync through useValueChanged already. Field.Control instead drove every field concern from the DOM change event, so a value set from code had no path at all.

Two bugs followed.

Dirty state never cleared for non-string values. The dirty check compares the input's string value against a baseline captured from the value prop. With value={5} the baseline was the number 5, so "5" !== 5 held forever and data-dirty stayed set even after the user returned the field to its initial value. Array values failed the same way by reference. The control now registers the serialized value, so the baseline and the comparison agree.

Programmatic changes left the field stale. Setting the value from code, such as a clear button or a form library reset, updated the input text but not filled, dirty, or validity, so a resolved error stayed visible and a pending async validator for the old value could still publish.

The fix gives each mode one owner instead of running two sync paths at once. useValueChanged owns the controlled path, onChange owns the uncontrolled path, and onChange returns early when controlled. Field.Control now has the same shape as its siblings, with the residual difference being the mount-time DOM read that its uncontrolled mode requires.

Two smaller fixes ride along:

  • details.cancel() in onValueChange now stops the internal handling. It was ignored.
  • A controlled value the consumer rejects or rewrites no longer reaches the field state, matching Combobox, Number Field and OTP Field.

Performance

Renders per keystroke for a controlled input, counted in jsdom (mount, then four keystrokes):

Validation mode Base This PR Number Field
onSubmit 1 per keystroke 2 on the first, then 1 2 on the first, then 1
onChange 1 per keystroke 2 per keystroke 2 per keystroke

Moving the work into a layout effect costs one extra render per keystroke in onChange mode. That is the cost every sibling control already pays, and Field.Control now matches Number Field exactly. The base column achieved one render by doing the work synchronously in the change handler, which is the second sync path this PR removes.

@atomiks atomiks added type: bug It doesn't behave as expected. component: field Changes related to the field component. labels Aug 10, 2026
@pkg-pr-new

pkg-pr-new Bot commented Aug 10, 2026 •

Copy link
Copy Markdown
  • base-ui-tanstack-start

  • vite-css-base-ui-example

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

commit: 14d39e5

@code-infra-dashboard

code-infra-dashboard Bot commented Aug 10, 2026 •

Copy link
Copy Markdown

Bundle size

Bundle Parsed size Gzip size
@base-ui/react 🔺+88B(+0.02%) 🔺+26B(+0.02%)

Details of bundle changes

Performance

Total duration: 1,304.84 ms +140.41 ms(+12.1%) | Renders: 76 (+0) | Paint: 2,052.24 ms +211.60 ms(+11.5%)

Test Duration Renders
Menu open (500 items) 84.59 ms 🔺+25.80 ms(+43.9%) 11 (+0)
Select open (500 options) 53.81 ms 🔺+11.93 ms(+28.5%) 14 (+0)
Dialog mount (300 instances) 60.02 ms 🔺+11.22 ms(+23.0%) 1 (+0)
Combobox type — 500 items, narrows to ~11 (type "Row 25") 44.12 ms 🔺+9.71 ms(+28.2%) 15 (+0)
Combobox open — 500 items 49.39 ms 🔺+9.39 ms(+23.5%) 4 (+0)

…and 1 more (+9 within noise) — details

Metric alarms

Test Metric Change
Menu open (500 items) bench:paint 🔺 +41.88 ms
Menu open (500 items) bench:paint#menu-open 🔺 +41.88 ms
Select open (500 options) bench:paint 🔺 +24.02 ms
Select open (500 options) bench:paint#select-open 🔺 +24.02 ms
Dialog mount (300 instances) bench:paint 🔺 +17.59 ms

…and 6 more metric alarms — details


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

@netlify

netlify Bot commented Aug 10, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit 14d39e5
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/6a79d3492e4ceb00088cc7a5
😎 Deploy Preview https://deploy-preview-5460--base-ui.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

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

@atomiks
atomiks force-pushed the claude/field-control-value-sync branch from 6a40cf1 to 14d39e5 Compare August 10, 2026 13:33
@atomiks
atomiks marked this pull request as ready for review August 13, 2026 11:23
@atomiks
atomiks merged commit 5c12af1 into mui:master Aug 13, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component: field Changes related to the field component. type: bug It doesn't behave as expected.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant