You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
refactor(ui): extract form state into useFormState - #19384
This moves field updates, validation, and resets out of the Form component. Callers continue to handle form-state requests through the existing callbacks; #19343 moves the complete request lifecycle into the form.
Requires #19307.
Prerequisite for #19343.
Extracts form state and its related methods from the `Form` component into a new `useFormState` hook. No behavior change.
```tsx
const {
formState,
isModified,
isValid,
resetFormState,
validateForm,
// ...
} = useFormState({
// ...form context and props
})
```
This moves field updates, validation, and resets out of the `Form` component. Callers continue to handle form-state requests through the existing callbacks; #19343 moves the complete request lifecycle into the form.
Reviewing files that changed from the base of the PR and between 3a48a36 and 8015edf.
You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.
Use the checkbox below for a quick retry:
Trigger review
No actionable comments were generated in the recent review.
Walkthrough
Form delegates field-state management, validation, reset, and previous-state tracking to the new useFormState hook. The hook initializes and validates field state, handles reset requests, and provides controls and status values to the form.
Changes: Form state management
Layer / File(s)
Summary
Initialize and validate form state packages/ui/src/forms/Form/useFormState.ts
The new hook initializes field state from initialState, validates eligible fields with form and document context, and returns state controls and status values.
Reset form state packages/ui/src/forms/Form/useFormState.ts
The hook fetches document preferences and server-generated state during reset, preserves disabled, and aborts the reset operation during cleanup.
Connect Form to useFormState packages/ui/src/forms/Form/index.tsx
Form uses the hook for field state, validation, reset, and previous-state tracking. It removes the corresponding inline implementation and passes the hook’s state and dispatch to FormFieldsContext.
payloadcms/payload#19307: Extracts form submission into useFormSubmission, which this change builds on.
payloadcms/payload#19203: Changes validation, reset, and refresh handling around the form-state lifecycle.
Suggested reviewers:alessiogr
Merge Risk: Low · previous review 3a48a
In a narrow reset race, the fields can reset while the form remains marked modified. The change is mergeable with awareness of this edge case.
Pre-merge checks: 5
Check name
Status
Explanation
Title check
The title clearly describes the extraction of form state into useFormState.
Description check
The description matches the extraction of field updates, validation, and resets into useFormState.
Docstring Coverage
No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage
Explanation
No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 0 functions across 2 files.
Finishing Touches
Generate docstrings
Commit to this branch
Create a new PR
Generate unit tests (beta)
Commit to this branch
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Reviewing files that changed from the base of the PR and between f0bae2f and 3a48a36.
Files selected for processing: 2
packages/ui/src/forms/Form/index.tsx
packages/ui/src/forms/Form/useFormState.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Requires #19307.
Prerequisite for #19343.
Extracts form state and its related methods from the
Formcomponent into a newuseFormStatehook. No behavior change.This moves field updates, validation, and resets out of the
Formcomponent. Callers continue to handle form-state requests through the existing callbacks; #19343 moves the complete request lifecycle into the form.