-
Notifications
You must be signed in to change notification settings - Fork 450
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom document action for publish, fails to publish #8630
Comments
I came to report the exact same issue. I have a more or less identical custom action as the above. Some consistent patterns I have noticed: In my document I have an array of images that seem to be central:
In the network tab, I can see that in step 2 above, there is no POST to the Skjermopptak.2025-02-14.kl.14.45.52.mov |
I managed to track it down this line in the
|
@georgibakken I wonder if your case might be slightly different to mine. Could it be that yours is a race condition of sorts? I think you need to EDIT: ok, seems like |
Here's my custom publish action for reference export function createSetPublishedAtPublishAction(originalAction: any, context: any) {
const client = context.getClient({ apiVersion: '2025-01-29' })
const setPublishedAtPublishAction = (props: any) => {
const originalResult = originalAction(props)
return {
...originalResult,
onHandle: async () => {
const { draft } = props
if (draft.publishedAt === undefined) {
await client
.patch(draft._id)
.setIfMissing({ publishedAt: new Date().toISOString() })
.commit()
}
originalResult.onHandle()
},
}
}
return setPublishedAtPublishAction
} |
Interestingly, replacing import { useDocumentOperation } from "sanity";
export function createSetPublishedAtPublishAction(originalAction: any, context: any) {
const setPublishedAtPublishAction = (props: any) => {
const { patch } = useDocumentOperation(props.id, props.type);
const originalResult = originalAction(props)
return {
...originalResult,
onHandle: async () => {
const { draft } = props
if (draft.publishedAt === undefined) {
patch.execute([{ set: { publishedAt: new Date().toISOString() } }]);
}
originalResult.onHandle()
},
}
}
return setPublishedAtPublishAction
}```
🤷 |
Running into the exact same problem. Does seem strange to me that I cannot |
Thanks @jorngeorg for your input! Originally I had some I agree @cwojcik-ifthen - There is however this note in the documentation
|
Describe the bug
When using custom document actions to extend the publish action, sometimes the document is not published.
It doesn't happen in a specific pattern, but more at random. Looking in the network tab, the
POST
publish call is not sent when this happens. When it manages to publish, thePOST
is sent. There is no error in the console.To Reproduce
Steps to reproduce the behavior:
sanity.config.ts
Screenshots
publish-sanity-bug.mov
Which versions of Sanity are you using?
What operating system are you using?
MacOS. Also experiencing this on our deployed studio
Which versions of Node.js / npm are you running?
❯ npm -v && node -v 10.7.0 v22.2.0
Additional context
I have tried the different examples in custom document actions with no luck.
The text was updated successfully, but these errors were encountered: