Discussion about issues with the Orderable Document List plugin and querying in Sanity Studio

12 replies
Last updated: Jan 11, 2022
This is an open question since it's Official plugin but, as a plugin, maybe not considered for Support ( I am still on a free plan as well )
I worked up the Orderable Document List and it works amazingly well, truly, in the Studio itself, and even in queries -- but when my documents change order, that change isn't reflected in front page code. At first I thought, maybe caching? But

• the array inside the document (reordering lists of references) updates instantly, and
• I can confirm no caching is set in my Client or the hosting service for the front end.
I am wondering what I should be looking for where even GROQ thinks it's fine but the returned query results aren't. The array comes to me not reflecting the change, and since it's a unique order of their choosing I can't correct for it once received.


EDIT: Thanks to Geoff I learned that I needed to include the ordering field from the schema in the list of returned projections, instead of just calling for it in the order() function. Thought I'd post an update for anyone else learning.
AI Update

Great question! You've actually discovered a common gotcha with GROQ queries and ordering fields. The solution you found with Geoff's help is exactly right, and it's worth explaining why this happens.

When you use the order() function in GROQ, the ordering happens on the backend, but GROQ doesn't automatically include the field you're ordering by in your projection. This is particularly important with the Orderable Document List plugin, which uses a special orderRank field to maintain custom ordering.

The Problem

The orderRank field exists in your documents and GROQ can use it for sorting, but if you don't explicitly include it in your projection, it won't be returned in the results. This can cause issues with:

  • Live queries: When the order changes, the query re-runs and returns results in the new order, but without orderRank in your projection, you might not see consistent ordering
  • Caching layers: Some systems cache based on the returned data structure, and without orderRank, they can't detect that ordering has changed

The Solution

You need to include the orderRank field (or whatever ordering field your schema uses) in your projection, not just in the order() function:

// ❌ Won't reliably reflect order changes
*[_type == "myDocument"] | order(orderRank) {
  _id,
  title,
  // orderRank not included
}

// ✅ Properly includes ordering field
*[_type == "myDocument"] | order(orderRank) {
  _id,
  title,
  orderRank  // Include this!
}

This ensures that:

  1. The ordering field is part of your returned data structure
  2. Changes to document order are reflected in the actual field values
  3. Any caching or change detection mechanisms can properly identify when order has changed

Why This Matters

As noted in the GROQ pipeline components documentation, the order component sorts array elements, but projections define which fields to return. These are separate operations, and the order component doesn't automatically modify your projection to include the ordering field.

Thanks for posting your solution as an edit—this will definitely help others who run into the same issue with the Orderable Document List plugin or any custom ordering fields!

Hi Vincent. The order of documents in your studio won’t be related to how they render on the front end. You can specify an order in your GROQ query using order() .
In fact, I believe that plugin adds a field to your documents. If you order by that field in ascending order, you should get the same order.
In fact, I believe that plugin adds a field to your documents. If you order by that field in ascending order, you should get the same order.
My query has the same
| order(orderRank)
as the documentation, and adding and removing it changes the results in GROQ like I'd expect. The only place it's different is the response as received on the webpage.
What does your web page’s query look like?
Thanks for the quick response! 😃 I was just about to show you in case my other choices are borking it.
(side note that getting to declare my own keys and feeding them results is aaamaaazingly nice)
With that query, if I re-order the documents, Vision will say that it sees the change. But visiting the live webpage that seems to understand and reflect every other change, misses that one ( I thought it was my looping code but the raw array is like that too)
I just found the Github for the plugin and it seems similar -- as of November not yet closed off https://github.com/sanity-io/orderable-document-list/issues/4 ( I am on 2.23.2 it seems, so ahead of them)
I don’t have this plugin installed but can try after dinner, or if you want you can DM your project ID or the query URL near the top in Vision (if the dataset is public).
I have a colleague evaluating the back end soon and I can't get in touch with him at the moment to let him know someone would be coming and I don't wanna spook him but otherwise I would. It's public. If you'd be so kind to check in after dinner I'd be genuinely grateful.
I know you guys probably don't accept tips or donations here but I should probably start pay as you go even though I don't need overages yet just so I'm contributing something :)
Oh I'm dumb you mean for query building not for going in the back end. Yes I'll grab that once I get home in about fifteen minutes

Sanity – Build the way you think, not the way your CMS thinks

Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.

Was this answer helpful?