Skip to content

orderRank initialValue not applied when documents are created outside of Sanity Studio #922

Description

@francohooman

Which plugin is affected?

@sanity/orderable-document-list

Describe the bug

The orderRankField defines an async initialValue that fetches the last
rank and assigns the next one. However, this initialValue is not applied in
certain document creation flows, resulting in documents missing the orderRank field
entirely.

Affected scenarios:

  • Documents that existed before the plugin was installed
  • Documents published without fully opening the edit form first
  • Documents created programmatically or via import
  • Documents created via the Sanity HTTP API or MCP tools (e.g. AI assistants using Sanity's MCP server), since initialValue is a Studio-only concept and is never invoked in those flows. In this case, the user is required to manually press "Reset Order" in the Studio after the document is created to assign a rank.

To reproduce

  1. Add orderRankField({ type: 'yourType' }) to a schema
  2. Create a document without opening the full edit form (e.g. via the "Create
    new" button in the orderable list but publish immediately)
  3. Observe the document is saved without an orderRank value
  4. The document appears out of order or breaks the orderable list

Expected behavior

initialValue should be applied on every new document creation flow, ensuring orderRank is always set before the first save.

Environment

  • Sanity Studio version: 3.x
  • Plugin version: 1.5.1
  • Browser: Chrome
  • Operating system: macOS

Additional context

As a workaround, we added a custom document action that detects when orderRankis missing and patches both the draft and published document client-side usingthe Sanity client.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions