Sanity error "Unexpected token" after deleting orderings and preview from schema

1 replies
Last updated: Aug 16, 2020
Hello!:)
I was doing some work with
orderings
and
preview
. I deleted it in the schema and now I’m not capable of seeing any content for that post type. Instead I see the following error:
An error occurred while loading items:

Unexpected token "0.", expected expression

Any help/doc is appreciated. Thanks in advance!
AI Update

Based on the error message you're seeing, this is a common issue related to GROQ syntax in your preview or orderings configuration. The error "Unexpected token '0.', expected expression" typically occurs when you're trying to access an array element using dot notation incorrectly.

The problem likely stems from how you were referencing array items in your preview.select or orderings configuration before deleting them. Even though you've removed the configuration, Sanity Studio might be caching the old settings or there might be remnants in your schema causing the issue.

Common Causes

This error usually happens when you have syntax like:

  • authors.0.name (incorrect)
  • categories.0.title (incorrect)
  • images.0.asset (incorrect)

In GROQ (which powers preview select and orderings), you need to use bracket notation for array indices, not dot notation.

How to Fix It

  1. Check your schema files for any remaining preview or orderings configurations. Look for patterns like .0. or .1. in your select statements.

  2. Correct array syntax should use brackets:

    preview: {
      select: {
        authorName: 'authors[0].name',    // ✅ Correct
        categoryTitle: 'categories[0].title'  // ✅ Correct
      }
    }
  3. Clear Studio cache - Sometimes the old configuration persists in cache:

    • Delete your .sanity folder in your Studio directory
    • Run sanity dev or sanity start again
    • Or try rm -rf node_modules/.sanity && sanity dev
  4. Check for orderings configuration - If you had custom orderings, make sure they're either properly formatted or completely removed:

    orderings: [
      {
        title: 'Author Name',
        name: 'authorName',
        by: [
          {field: 'authors[0].name', direction: 'asc'}  // ✅ Correct bracket notation
        ]
      }
    ]
  5. Restart your development server after making changes.

Additional Notes

As mentioned in the preview configuration documentation, when working with arrays in preview select, you should use the correct GROQ syntax with brackets for array indices. The same applies to orderings.

If you've completely removed the preview and orderings configuration and are still seeing the error, there might be a cached version of your schema. Try clearing your browser cache as well, or open Studio in an incognito/private window to rule out browser caching issues.

Show original thread
1 reply
Figured it out.
Looks like even though the
orderings
were removed, it stayed selected in the
sort by
dropdown. Changing the sort by to a default option caused the data to show again.

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?