You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
However, this triggers the following error in the studio:
An error occurred during publish
Details
the mutation(s) failed: Document "3978c05e-c447-4fc5-94fe-3e6867d23a90" has unexpected revision ID ("9by72vG2l204L0eD67v5lE"), expected "xnBg0xhUDzo561jnWkyoBy"
I assume that the patch creates a new version of the document, which causes the mismatch in the IDs.
The full code for context
import{useState,useEffect}from'react';import{useDocumentOperation}from'@sanity/react-hooks';importsanityClientfrom'part:@sanity/base/client';importslugifyfrom'@sindresorhus/slugify';import{updateIntlFieldsForDocument}from'sanity-plugin-intl-input/lib/utils';constpathLangPrefixes={de: '',en: '/en'}exportdefaultfunctionSetSlugAndPublishAction({ id, type, draft, onComplete }){const{ patch, publish }=useDocumentOperation(id,type);const[isPublishing,setIsPublishing]=useState(false);useEffect(()=>{// if the isPublishing state was set to true and the draft has changed// to become `null` the document has been publishedif(isPublishing&&!draft){setIsPublishing(false);}},[draft]);return{disabled: publish.disabled,label: isPublishing ? 'Publishing…' : 'Publish',onHandle: async()=>{setIsPublishing(true);if(draft._type==('modularPage'||'blogPost')){constclient=sanityClient.withConfig({apiVersion: `2022-01-10`});constbase=draft.pageBase;letslug=slugify(base.slugBase?.current??'');constquery=`*[_id == $ref][0]{"parentSlug": pageBase.slugBase.current}`;if(base.inheritedParent||base.parent){constparams={ref: base.inheritedParent?._ref??base.parent?._ref};const{ parentSlug }=awaitclient.fetch(query,params);slug=`${parentSlug}/${slug}`;}slug=`${pathLangPrefixes[draft?.__lang??'de']}/${slug}`patch.execute([{set: {'pageBase.fullSlug': slug}}]);}publish.execute();awaitupdateIntlFieldsForDocument(id,type);if(onComplete)onComplete();}}}
Is there a way to fix this problem?
The text was updated successfully, but these errors were encountered:
The problem is that the executable studio actions (like patch.execute) are not awaitable and async. This means the changes happen in the background but the updateIntlFieldsForDocument function will get called right away before the patch has even fully executed. The only way around this would be to manually patch the document using the studio accessible Sanity client and await.
I'm using a custom publish action to add a custom slug to documents when publishing using a patch:
After that I trigger the publish and call
updateIntlFieldsForDocument()
, as described here:However, this triggers the following error in the studio:
I assume that the patch creates a new version of the document, which causes the mismatch in the IDs.
The full code for context
Is there a way to fix this problem?
The text was updated successfully, but these errors were encountered: