Missing Unpublish Option in Sanity Studio v2.25

7 replies
Last updated: Feb 17, 2022
Hi all, I'm trying to unpublish a document in Sanity studio but I don't seem to have the option to do so?Dependencies and versions:

    "@sanity/base": "^2.25.4",
    "@sanity/color-input": "^2.25.4",
    "@sanity/components": "^2.14.0",
    "@sanity/core": "^2.25.0",
    "@sanity/default-layout": "^2.25.4",
    "@sanity/default-login": "^2.24.1",
    "@sanity/desk-tool": "^2.25.4",
    "@sanity/vision": "^2.25.4",
This is what my options look like:
AI Update

I can see you're on Sanity Studio v2 and missing the unpublish option! This is almost certainly because you have liveEdit: true set in your document schema.

When a document schema has liveEdit: true, Sanity treats it as "live only" - meaning changes are saved directly to the published version without creating drafts. Since there's no draft/published distinction for these documents, the unpublish action doesn't appear in the document menu.

To fix this:

Check your schema definition for the document type you're trying to unpublish. Look for something like this:

export default {
  name: 'yourDocumentType',
  type: 'document',
  liveEdit: true,  // <-- This is the culprit
  fields: [
    // your fields
  ]
}

Remove or set liveEdit: false:

export default {
  name: 'yourDocumentType',
  type: 'document',
  // liveEdit: false is the default, so you can just remove the line
  fields: [
    // your fields
  ]
}

After removing liveEdit: true and restarting your Studio, you should see the unpublish option appear in the document menu. The document will now use Sanity's draft system, where changes are saved as drafts (with drafts. prefix) before being published.

Important notes:

  • If you have existing live-edit documents, they'll continue to work after you change the schema, but new edits will create draft versions that need to be published.
  • The liveEdit option is useful for certain use cases where you want immediate updates without a publish step, but it does remove the unpublish functionality since there's no separate published state to revert from.
  • In Studio v2, this is a schema-level setting. If you need drafts disabled globally, you'd need to add liveEdit: true to each document type individually.

The unpublish button will reappear once you've removed the liveEdit: true setting from your schema!

Show original thread
7 replies
I don't think so. There's another document that does allow me to unpublish it, a location group that is referenced by the above document I am trying to unpublish. This location group document is published, and it only prevents me from unpublishing it due to it being referenced by the location document.
Thanks for that additional context. I also edited my comment above as you’re right—it is published.
What does your document actions file look like for the top case?
This what it looks like:
import defaultResolve, {
  PublishAction,
  DiscardChangesAction,
  DeleteAction,
  DuplicateAction,
} from "part:@sanity/base/document-actions";
import { FiEye } from "react-icons/fi";

const previewSecret = process.env.SANITY_STUDIO_PREVIEW_SECRET;
const localURL = "<http://localhost:3000>";
const baseUrl = window.location.hostname === "localhost" ? localURL : "<https://ivee.vercel.app>";

const singletons = ["pageHome", "jobsPage", "blogIndex", "settingsGeneral", "settingsSeo", "emailModal"];
const editAndDelete = ["person", "service", "page", "pageCollection", "blogPost", "location", "service"];
const previews = [
  "pageHome",
  "job",
  "jobsPage",
  "blogIndex",
  "service",
  "page",
  "location",
  "pageCollection",
  "blogPost",
];

const PreviewAction = (props) => {
  const slug = props.draft
    ? props.draft.content?.slug?.current || props.draft.slug?.current
    : props.published?.content?.slug?.current || props.published?.slug?.current;

  return {
    label: "Open Preview",
    icon: FiEye,
    onHandle: () => {
      window.open(`${baseUrl}/api/preview?token=${previewSecret}&type=${props.type}&slug=${slug || ""}`);
    },
  };
};

export default function resolveDocumentActions(props) {
  const isSingle = singletons.indexOf(props.type) > -1;
  const canEditDelete = editAndDelete.indexOf(props.type) > -1;
  const canPreview = previews.indexOf(props.type) > -1;

  if (isSingle) {
    return [PublishAction, DiscardChangesAction, ...(canPreview ? [PreviewAction] : [])];
  }

  if (canEditDelete) {
    return [PublishAction, DiscardChangesAction, DuplicateAction, DeleteAction, ...(canPreview ? [PreviewAction] : [])];
  }

  return [...defaultResolve(props), ...(canPreview ? [PreviewAction] : [])];
}
I believe you’ll want to import UnpublishAction and add it to your arrays at the bottom. See here for an example.
Thank you for the help! I'm still fairly new to Sanity and am working within this already existing codebase. That is indeed the fix :)
That’s great! 🎉
Unless you have a good reason to do so, you might want to spread
defaultResolve(props)
and then add your additional actions, such as is done here . That way, you don’t need to worry if Sanity updates the defaults. Of course, there are good cases for listing them out manually, too. 🙂

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?