Skip to content

fix(richtext-lexical): give the drawer submit its own abort controller - #19386

Open
Vivek1898 wants to merge 1 commit into
payloadcms:mainfrom
Vivek1898:fix/19385-lexical-drawer-save-abort
Open

Vivek1898 wants to merge 1 commit into
payloadcms:mainfrom
Vivek1898:fix/19385-lexical-drawer-save-abort

Conversation

@Vivek1898

Copy link
Copy Markdown

What?

The Lexical fields drawer (DrawerContent, used by the link drawer and the other lexical_internal_feature drawers) passed one callback as both onChange and beforeSubmit, and that callback aborts and replaces a single shared AbortController ref before each form-state request.

When the user presses Save while the submit's beforeSubmit form-state request is still in flight, the Form's debounced onChange (≈250 ms after the last keystroke) calls the same callback and aborts the submit's request. getFormState resolves to { state: null }, so the callback falls back to the client form state, which still carries the valid flag from the last completed server validation rather than the value just typed. When that flag was invalid (for example the toolbar's https:// placeholder under a validate on the link url), Form.submit returns 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?

beforeSubmit and the debounced onChange are independent flows and should not share one abort controller. Fixes #19385.

How?

DrawerContent.tsx now keeps a second AbortController ref for beforeSubmit. onChange takes the ref to use (defaulting to the existing onChange ref), and beforeSubmit calls it with the new beforeSubmit ref, so a debounced change can never abort a submit's request. onChange keeps 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 instrumenting AbortController.prototype.abort.

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.
@coderabbitai

coderabbitai Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

DrawerContent now uses separate abort controllers for form-state requests started by onChange and beforeSubmit. Unmount cleanup aborts both controllers.

Changes: Drawer form requests

Layer / File(s) Summary
Form-state request cancellation
packages/richtext-lexical/src/utilities/fieldsDrawer/DrawerContent.tsx
onChange can use a specified controller ref, while beforeSubmit uses a dedicated controller. Unmount cleanup aborts both request controllers.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Possibly related PRs

  • payloadcms/payload#19343: This PR moves form-state requests and cancellation into Form, which is related to the request handlers changed here.

Suggested reviewers: alessiogr

Merge Risk: Low · up to 61d1a

A timing race can hide a link validation error while leaving the drawer open. Retrying after requests settle restores validation.

Pre-merge checks: Passed 5

Check name Status Explanation
Title check Passed The title accurately describes the separate abort controller for drawer submission.
Description check Passed The description explains the abort race and the separate controllers used to fix it.
Linked Issues check Passed [#19385] DrawerContent uses a separate controller for beforeSubmit. Debounced onChange requests cannot abort it, and newer onChange requests still abort older ones. Both controllers are aborted on unm…
Out of Scope Changes check Passed [#19385] The DrawerContent changes isolate and clean up the request controllers. These changes support the linked issue.
Docstring Coverage Passed 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…
Full details: Linked Issues check

Explanation

[#19385] DrawerContent uses a separate controller for beforeSubmit. Debounced onChange requests cannot abort it, and newer onChange requests still abort older ones. Both controllers are aborted on unmount. The PR adds no automated regression test; the issue does not explicitly require one.

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 1 files.

Finishing Touches

Generate unit tests (beta)

  • 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.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between fac8196 and 61d1a87.

Files selected for processing: 1

  • packages/richtext-lexical/src/utilities/fieldsDrawer/DrawerContent.tsx

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Lexical fields drawer: Save is silently refused when the debounced onChange aborts the submit's form-state request

1 participant