-
-
Couldn't load subscription status.
- Fork 535
fix(form-core): fix deleteField method #1809
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
|
| Command | Status | Duration | Result |
|---|---|---|---|
nx affected --targets=test:sherif,test:knip,tes... |
❌ Failed | 1m 55s | View ↗ |
nx run-many --target=build --exclude=examples/** |
✅ Succeeded | 24s | View ↗ |
☁️ Nx Cloud last updated this comment at 2025-10-14 18:17:41 UTC
|
Blocked by #1729 . This seems critical to test with the linked PR. |
🎯 Changes
Fixes: #1808
If this idea make sense, I will add tests
After calling
form.deleteField('fieldName'), the field is removed fromform.state.values, but after a moment it returns with defaultValue and appears at the end of the values object.The problem occurred due to React lifecycle and the logic in
FieldApi.mount()Sequence of events:
delete->form.deleteField('field')executes -> value is remo ved fromform.state.values-> field metadata is removed - cool, butFieldApi.update()or lifecycle hooks -> this callssetFieldValueFieldApi.mount()there was logic:I think this uncoditionally restored
defaultValueon every mount.updatePS: Even if we add a check in
mount()-setFieldValuecan be called from other places (e.g., fromFieldApi.update()during React lifecycle).I added a mechanism for tracking intentionally deleted fields to prevent their their accidental restoration.
_deletedFields: Set<string>inFormApi- it stores names of fields that were intentionally deleted by the userdeleteField()adds the field to_deletedFieldssetFieldValue()blocks operations on deleted fields✅ Checklist
pnpm test:pr.🚀 Release Impact