Skip to content

Assist Field Action fails with "Schema for schemaId 'page' could not be found" #662

@diegobp99

Description

@diegobp99

Describe the bug

When using @sanity/assist to define a field action, the client fails to find the schemaId for documents. Hardcoding the schemaId to "page" or using the one provided in props (_.schemas.ww) always results in a Not Found error.

To Reproduce

Steps to reproduce the behavior:

  1. Install @sanity/assist and @sanity/document-internationalization plugins.
  2. Use the following field action configuration:
fieldActions: {
  title: "SEO Actions",
  useFieldActions: (props) => {
    const {
      actionType,
      schemaId,
      documentIdForAction,
      path,
      getConditionalPaths,
    } = props;
    const client = useClient({ apiVersion: "vX" });

    return useMemo(() => {
      if (actionType === "field") {
        if (path[0] !== "seo") return [];

        return [
          defineAssistFieldAction({
            title: "Generate SEO",
            onAction: async () => {
              await client.agent.action.generate({
                schemaId, // or hardcoded "page"
                documentId: documentIdForAction,
                instruction: `
                  Generate SEO metadata for this document's SEO field.
                `,
                instructionParams: {
                  doc: { type: "document" },
                  field: { type: "field", path },
                },
                target: { path },
                conditionalPaths: { paths: getConditionalPaths() },
              });
            },
          }),
        ];
      }
      return [];
    }, [actionType, path, client, schemaId, documentIdForAction, getConditionalPaths]);
  },
}
  1. Attempt to trigger the action on a page document in the studio.

Expected behavior

The action should execute and generate SEO metadata without errors.

Observed behavior

Error thrown:

Failed to execute action
ClientError: Not Found - Schema for schemaId 'page' could not be found

Even hardcoding the schemaId does not resolve the issue.

Additional context

  • Using the documentInternationalization plugin.
  • Project has two datasets: production and staging.
  • I18N_DOCUMENT_TYPES = ["footer", "home", "menu", "page"].
  • The documentIdForAction exists and is valid.
  • Using React 18 and latest Sanity v4 CLI + studio.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions