Skip to content

Custom document action for publish, fails to publish #8630

Open
@georgibakken

Description

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, the POST is sent. There is no error in the console.

To Reproduce

Steps to reproduce the behavior:

  1. Implement extension of document action
export function publishAction(originalAction, context) {
  const BetterAction = (props) => {
    const { patch } = useDocumentOperation(props.id, props.type);
    const originalResult = originalAction(props);
    return {
      ...originalResult,
      onHandle: async () => {
       

        if (props.draft.publishedAt === undefined) {
          patch.execute([{ set: { publishedAt: new Date().toISOString() } }]);
        }

        patch.execute([{ set: { lastPublishedAt: new Date().toISOString() } }]);

        originalResult.onHandle();
      },
    };
  };
  return BetterAction;
}
  1. Add it to sanity.config.ts
...
      prev.map((originalAction) => {
        if (originalAction.action === "publish") {
          return publishAction(originalAction, context);
        }
...
  1. Try publishing a document in Sanity Studio, sometimes it doesn't get published (after 5-6 times perhaps, and sometimes straight away)

Screenshots

publish-sanity-bug.mov

Which versions of Sanity are you using?

❯ sanity versions
@sanity/cli (global)          3.46.0 (latest: 3.75.0)
@sanity/dashboard              4.1.2 (up to date)
@sanity/eslint-config-studio   5.0.1 (up to date)
@sanity/icons                  3.5.7 (up to date)
@sanity/types                 3.75.0 (up to date)
@sanity/ui                    2.12.3 (latest: 2.12.4)
@sanity/vision                3.75.0 (up to date)
sanity                        3.75.0 (up to date)

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions