Skip to content

Successful autosave clears validation error state after a failed publish (setSubmitted(false) on skipValidation submits) #18300

Open

Description

@pehlert

Describe the Bug

When a publish fails validation, the form correctly enters the submitted state and shows error indicators (red fields, ErrorPill on collapsed blocks/arrays, tab badges). The very next edit triggers autosave, which submits a draft with skipValidation: true. That request succeeds, and the success branch of Form.submit unconditionally calls setSubmitted(false), which removes every error indicator while the document is still invalid.

The net effect for editors on a collection with drafts.autosave (and no drafts.validate): validation highlights are visible for exactly autosave.interval milliseconds after the first keystroke, then vanish. On large pages with nested blocks it is very hard to find what actually blocks publishing.

Relevant code (v3.90.2):

  • packages/ui/src/forms/Form/index.tsx, success branch of submit:
    if (res.status < 400) {
      // ...
      setSubmitted(false)
      setProcessing(false)
  • packages/ui/src/elements/Autosave/index.tsx calls that same submit with overrides: { _status: 'draft' }, skipValidation: !validateOnDraft.

A submit that skipped validation cannot know the form is valid, so it should not clear the submitted/error state. Suggested fix: keep submitted untouched when the submit ran with skipValidation (or let Autosave pass an explicit flag), e.g.

if (!skipValidation) {
  setSubmitted(false)
}

The existing guard in Autosave (skipSubmission = submitted && !valid && validateOnDraft) only protects the drafts.validate: true case; without validate: true there is no protection.

Link to the code that reproduces this issue

Reproducible with the repository's own test suite: test/versions, collection autosave-posts (test/versions/collections/Autosave.ts: autosave.interval: 100, required title and description).

Reproduction Steps

  1. pnpm dev versions, log in, open Autosave Posts, create a document, fill title and description, publish.
  2. Clear description (required). Wait for autosave (draft saves fine, drafts are not validated).
  3. Click Publish changes. Validation fails, description is highlighted and the toast "Please correct invalid fields" appears. Expected so far.
  4. Type one character into title.
  5. After ~100 ms autosave runs, succeeds, and the highlight on description disappears. The document is still not publishable, but nothing in the UI indicates why or where.

Same behaviour with server-side errors (e.g. a select value no longer in options inside a collapsed block): the block shows 1 Error after publish, then loses it on the next autosave.

Expected: error indicators from a failed publish stay until the fields are actually valid (i.e. until a validated submit succeeds), regardless of intermediate draft autosaves.

Which area(s) are affected?

area: ui

Environment Info

payload: 3.90.2
next: 16.3.6
@payloadcms/db-mongodb: 3.90.2
@payloadcms/ui: 3.90.2
react: 19.2.3
node: 22 / 26 (reproduced on both)
pnpm: 10.22.0
Platform: darwin arm64

Activity

  1. added
    area: ui
    on Sep 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Bugarea: ui

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions