Skip to content

fix(ui): call useQueue's beforeProcess before every task, so autosave keeps edits made during a queued save - #18349

Closed
adrian-baker wants to merge 1 commit into
payloadcms:mainfrom
adrian-baker:fix/use-queue-before-process
Closed

adrian-baker wants to merge 1 commit into
payloadcms:mainfrom
adrian-baker:fix/use-queue-before-process

Conversation

@adrian-baker

@adrian-baker adrian-baker commented Sep 28, 2026 •

Copy link
Copy Markdown

What?

useQueue now calls beforeProcess before each task it runs, instead of once before its loop. afterProcess already runs after each task, so the two now pair up for every task.

Why?

Autosave uses the two callbacks to set the form's background processing flag on and off. When a second autosave was queued behind the first, it ran after afterProcess had turned the flag off, and nothing turned it back on. An edit made during that save then wasn't recorded as "modified while processing", the save's response reset modified to false, and the autosave for that edit found nothing to save. The editor's last edit was lost, although the field showed it. Fixes #18348, which has the full sequence.

How?

The beforeProcess check moves to the top of the while loop. Returning false still stops processing and leaves the queue as it was, as it did before the loop. The doc comment on beforeProcess says it's called before each function.

useQueue.spec.tsx covers both: a task queued while another runs gets its own beforeProcess, and a false from beforeProcess stops the task from running. The first test fails without the change, with beforeProcess recorded once instead of twice.

The same change applies unchanged to 3.x, where useQueue.ts is identical. The 3.x fix is #18350, without the spec, because that branch has no browser test project.

🤖 Generated with Claude Code

afterProcess already runs after every task, so a task queued behind another ran after afterProcess and without a beforeProcess of its own. Autosave uses the pair to set the form's background processing flag, so an edit made during a queued autosave wasn't recorded as modified while processing, and the autosave for that edit was skipped.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jacobsfletch

Copy link
Copy Markdown
Member

Hey @adrian-baker - really appreciate the contribution here. We're actively refactoring the entire useQueue hook in #19203, which should cover this. I added a regression test based on the linked issue's specific repro steps.

The refactor enables background processing when each autosave starts, so queued saves re-enable it after the previous save clears it. Edits made during those saves stay marked as unsaved, so the next autosave picks them up.

@adrian-baker

Copy link
Copy Markdown
Author

Excellent, thank you, I'll keep an eye on #19203.

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.

Autosave drops an edit made while a queued autosave is in flight

2 participants