Repository navigation
Conversation
The fields drawer passed one callback as both onChange and beforeSubmit, and
that callback aborts and replaces a single shared AbortController ref before
each form-state request. Pressing Save while the submit's form-state request
was still in flight let the debounced onChange (≈250ms after the last
keystroke) abort the submit's request. getFormState then resolved to
{ state: null }, the callback fell back to the client state carrying the last
completed validation's `valid` flag, and Form.submit returned early on
!isValid, so the drawer stayed open and Save silently did nothing (payloadcms#19385).
Give beforeSubmit its own AbortController so a debounced onChange can never
abort a submit's request. onChange keeps its behaviour, where a newer change
aborts an older one.
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
What?
The Lexical fields drawer (
DrawerContent, used by the link drawer and the otherlexical_internal_featuredrawers) passed one callback as bothonChangeandbeforeSubmit, and that callback aborts and replaces a single sharedAbortControllerref before each form-state request.When the user presses Save while the submit's
beforeSubmitform-state request is still in flight, the Form's debouncedonChange(≈250 ms after the last keystroke) calls the same callback and aborts the submit's request.getFormStateresolves to{ state: null }, so the callback falls back to the client form state, which still carries thevalidflag from the last completed server validation rather than the value just typed. When that flag was invalid (for example the toolbar'shttps://placeholder under avalidateon the linkurl),Form.submitreturns early on!isValid: the drawer stays open, no field error shows, and the link is not applied. A second Save works, so it reads as "Save does nothing sometimes".Why?
beforeSubmitand the debouncedonChangeare independent flows and should not share one abort controller. Fixes #19385.How?
DrawerContent.tsxnow keeps a secondAbortControllerref forbeforeSubmit.onChangetakes the ref to use (defaulting to the existingonChangeref), andbeforeSubmitcalls it with the newbeforeSubmitref, so a debounced change can never abort a submit's request.onChangekeeps its existing behaviour, where a newer change aborts an older one, and both controllers are aborted on unmount.Fixes #19385
The failure is a timing race between a 250 ms debounce and an in-flight form-state request, which I was not able to turn into a deterministic unit test; the drawer has no unit test harness and this area is covered by e2e. Happy to add an e2e case if you can point me at the right
test/directory for it. The reporter confirmed the exact abort sequence by instrumentingAbortController.prototype.abort.