Repository navigation
fix(ui): send a follow-up form state refresh when a change races a pending answer - #19844
theguysudo wants to merge 1 commit into
Conversation
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
…ms debounce A change made while a form state refresh request was pending never reached the server: the merged answer set prevFormStateRef to a state that already included the unsent edits, so the debounced effect compared the merged state with itself and skipped the follow-up refresh. Conditions dependent on the change stayed hidden and array rows added meanwhile kept their loading state until the next edit. Only apply the answer to prevFormStateRef when the fields the request was built from are unchanged; otherwise leave the baseline alone so the debounced effect sees the difference and queues one more refresh. Save, validate, reset and autosave answers are unaffected.
1eab969 to
d9bfbe6
Compare
|
Rebased onto the latest I re-applied the fix on top of the refactor and re-verified it:
|
What?
A field change made while a form-state refresh answer is pending is now still sent in a follow-up refresh. Previously such a change could silently never reach the server, leaving
admin.conditionfields hidden and array rows added during the race stuck in their loading state until the next edit.Why?
Formqueues a refresh 250 ms after the last change, but only whenformStatediffers fromprevFormStateRef. When a refresh answer arrives,MERGE_SERVER_STATEsetsprevStateRef.currentto the merged state — and that state already includes local changes made while the request was pending. If the answer arrives within 250 ms after such a change, the debounced effect later compares the merged state with itself, finds no difference, and never queues the refresh for that change.How?
In
refreshFormState(packages/ui/src/forms/Form/useFormState.ts), keep a reference tocontextRef.current.fieldsas it was when the request was built (fieldsAtRequest). On arefreshanswer, only passprevStateReftoMERGE_SERVER_STATEifcontextRef.current.fieldsis still that reference. Otherwise leaveprevFormStateRefunchanged, so the debounced effect sees the difference and queues one more refresh carrying the unsent change. Save (afterSave), validate, reset and autosave answers are untouched — the condition only applies torefreshanswers.Verification
Added
packages/ui/src/forms/Form/Form.spec.tsx(browser-mode component test, mockedgetFormStateserver function):unit: 'km') while it is pending, then resolves the answer within the 250 ms debounce window. Before this fix the test fails ("expected to be called 2 times, but got 1 times" — the change is never sent); after the fix a second refresh is sent carryingunit: 'km', and no further refresh is queued once it settles.Fixes #19842
Transparency note: this fix was developed with AI assistance (an AI coding agent driven by the repo owner). The race was reproduced locally and tests were run before submission.