Repository navigation
[field][form][fieldset] Reduce bundle size - #5225
Conversation
commit: |
Bundle size
PerformanceTotal duration: 1,256.94 ms -76.39 ms(-5.7%) | Renders: 78 (+0) | Paint: 1,949.55 ms -122.27 ms(-5.9%)
12 tests within noise — 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. |
3518aef to
0bdd1e5
Compare
There was a problem hiding this comment.
Pull request overview
This PR reduces shipped bundle size across the Field/Form/Fieldset family by removing redundant internal code paths and simplifying registration/validation logic while aiming to keep behavior unchanged (and adding regression tests for key flows).
Changes:
- Simplifies internal registration/ID plumbing (moving to
useRefWithInit, ref-based field ID tracking, and trimmingFieldRootContextsurface area). - Refactors
<Form />submission/focus behavior to focus the first invalid control consistently and streamlines error clearing / form value collection. - Adjusts field validation logic around native validity revalidation and adds tests to cover the updated behavior.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/react/src/internals/labelable-provider/useLabelableId.ts | Removes the Symbol description string to reduce bytes. |
| packages/react/src/internals/field-root-context/FieldRootContext.ts | Trims unused context fields/defaults to reduce dead exports and surface area. |
| packages/react/src/internals/field-register-control/useRegisterFieldControl.ts | Uses useRefWithInit for stable per-control symbols and simplifies guards/deps. |
| packages/react/src/internals/field-register-control/useFieldControlRegistration.ts | Removes fallback refs and switches registered field ID tracking to a ref. |
| packages/react/src/form/Form.tsx | Refactors submit/focus flow and error handling; uses Object.hasOwn for own-property checks. |
| packages/react/src/form/Form.test.tsx | Adds coverage for focusing first invalid field, external error replacement, and Strict Mode registration targeting. |
| packages/react/src/fieldset/root/FieldsetRootContext.ts | Tightens context typing for disabled to always be boolean. |
| packages/react/src/fieldset/legend/FieldsetLegend.tsx | Aligns legend state with new non-optional disabled context value. |
| packages/react/src/field/validity/FieldValidity.tsx | Documents memoization rationale for the render-prop state object identity. |
| packages/react/src/field/validity/FieldValidity.test.tsx | Adds coverage for deferring stale custom errors across validation boundaries. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
d8e0274 to
db9892c
Compare
Removes dead and redundant code from Field, Form, and Fieldset. The bundle bot is authoritative for the current size impact.
The previously ineffective only-
valueMissingrevalidation bail now works as intended, deferring stale coexisting errors until blur or submit;FieldValidityregression tests pin this behavior.