Go Behind the Experience to see how Tecovas brings the West to life with Sanity 🤠 July 18th

Issues with publishing and deleting documents using Sanity's Document Internationalization Plugin

8 replies
Last updated: Nov 7, 2022
Hi all! I’m having trouble with the Document Internationalization Plugin. When I create translations from an unpublished base document, I can no longer publish or delete the base document. The translated document can be published as per usual.
My company’s workflow is that our English and French pages need to be published at the same time. So we usually create and QA our pages in draft/unpublished mode until they get approved and then we publish.

The only workaround we have found is creating a duplicate of the base document (leaving the OG base document unpublished) but this is leaving us with a lot of documents that are stale and can’t be deleted. Looking for any advice on how to resolve this issue and any suggestions!

Here are some of errors that we have gotten:

When trying to publish the base document: 
An error occurred during publish Details Mutation(s) failed with 1 error(s)

When trying to delete the base document: 
An error occurred while attempting to delete this document. This usually means that there are other documents that refers to it. ClientError: Mutation(s) failed with 1 error(s)
Thank you!
Nov 2, 2022, 8:53 PM
Hey Andrea! If you change your reference behavior in the plugin's config to
weak
, you'll be able to delete documents that have references to it. Note: you will have to run a mutation on existing data to add
_weak: true
to the fields, though.
Nov 2, 2022, 9:35 PM
Hi
user M
! Thanks for your help! I've had the reference behaviour set to weak since the beginning of the project 🤔 Here's my config file:
{
    "idStructure": "subpath",
    "referenceBehavior": "weak",
    "base": "en",
    "languages": ["en", "fr"]
}
I'm not sure I understand when you say to run a mutation. If there is any docs or resources that you could point me to that would be most appreciated!
Nov 3, 2022, 7:37 PM
Hmm, are there documents besides translations referencing the base document?
In terms of of mutations, there's some documentation on doing it
here (specifically patches). You can also do it with the JS client .
Nov 3, 2022, 7:54 PM
I don't think there are any other references. I've been debugging on a test base page and it works as expected until I try to add the translations.
Thank you for the docs!
Nov 3, 2022, 7:58 PM
This is an unfortunate quirk with the current plug-in, it writes references linking both docs meaning they need to both be published deleted in a single operation. Which the Delete action from the plug-in should be doing … if not you might want to create a new document action that can take the current id, it’s translations and delete them together.
Nov 4, 2022, 6:41 PM
Thanks
user T
for your response! Good to know there is some quirkiness. I will look into the document actions. Do you know if it would be possible to create a document action that would publish the docs at the same time? Or is only possible to delete?
Nov 4, 2022, 8:22 PM
Ah I misspoke above. I meant the plugin should provide an action that would delete them both in one mutation.
Unfortunately bulk “publishing” isn’t entirely supported either. A “publish” operation in the Studio is a few different actions (copying the draft contents to a new or existing published document and then deleting the draft). There’s the sanity react-hooks package that exposes a publish function, but it only takes a single document at a time.

There is a (relatively new) API endpoint for bulk publishing among the scheduled publishing API’s … and is available on Team plans or higher:

https://www.sanity.io/docs/scheduling-api#dcb47be520d0
Nov 4, 2022, 8:40 PM
Thanks for explaining,
user T
! Really helpful to have the context. We are actually using the scheduling API already so I will see if we can use it as a workaround. Thanks again!
Nov 7, 2022, 4:22 PM

Sanity– build remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?