Uh oh!
There was an error while loading. Please reload this page.
fix(form): stop form.reset() wiping user input on identity churn (real "Create does nothing" root cause) - #1525
Merged
Conversation
The form renderer reset react-hook-form on every defaultValues *identity*
change. Callers pass a fresh defaultValues object each render, so an
unrelated parent re-render wiped typed input. This was the root of
master-detail "Create does nothing": a re-render between the submit click
and the deferred requestSubmit blanked the form, RHF failed required
validation on the empty fields, and no batch was sent.
Now resets only when defaultValues changes by value (JSON-compared), so
edit-mode record loads still reset while identity churn is ignored.
Also strengthens the master-detail live e2e: assert the submit POSTs
/api/v1/batch with the populated parent payload (name/account/status) and a
child op referencing the parent via {$ref:0} — a real guard, replacing the
prior form-reset check that passed even when the form had been wiped.
Verified: components suite 3382 pass; live e2e 2/2 (batch now fires with full
data — previously it validated an empty form and never posted).
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>The latest updates on your projects. Learn more about Vercel for GitHub. |
Contributor
✅ Console Performance Budget
📦 Bundle Size Report
Size Limits
|
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
Sign up for freeto join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The bug
Clicking Create on the master-detail form persisted nothing (verified live:
created=0), even though the inputs were visibly filled. This is the real root of the "点了没反应 / click Create, nothing happens" report — deeper than the earlierrequestSubmitwork (#1521), which only made the submit fire.Root cause
The form renderer reset react-hook-form on every
defaultValuesobject-identity change:Callers build a fresh
defaultValuesobject each render. So a re-render between the submit click and the deferredrequestSubmit(e.g.MasterDetailForm'ssetSaving(true)) fired this effect →form.reset()→ wiped the user's input. RHF then validated blank required fields →onInvalid→ the batch was never sent.Live trace that pinned it:
[MD_SAVE]fires with the form full →setSaving(true)re-render → by the deferred submit,nameVal=""(form wiped) → RHF errorsname/account/status: required→ no POST.The fix
Reset only when
defaultValuesactually changes by value (JSON-compared), ignoring identity churn. A genuine change (edit-mode record finishing loading) still resets.Verification
POST /api/v1/batchwith the populated parent payload (name/account/status) and a child op{$ref:0}— previously it validated an empty form and never posted. The master-detail live spec is rewritten to assert this real behaviour (the prior form-reset assertion was a false positive — it passed because the form had been wiped).🤖 Generated with Claude Code