From 15f400998c40a6140d9a190cd0dc62bd44299bc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rge=20N=C3=A6ss?= Date: Thu, 31 Oct 2024 20:33:13 -0400 Subject: [PATCH] fix: fetch either draft of published when adding document to release --- .../store/release/createReleaseOperationStore.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/packages/sanity/src/core/store/release/createReleaseOperationStore.ts b/packages/sanity/src/core/store/release/createReleaseOperationStore.ts index ebaafe1612aa..eba4899fc890 100644 --- a/packages/sanity/src/core/store/release/createReleaseOperationStore.ts +++ b/packages/sanity/src/core/store/release/createReleaseOperationStore.ts @@ -7,7 +7,7 @@ import { import {type User} from '@sanity/types' import {getBundleIdFromReleaseDocumentId} from '../../releases' -import {getVersionId} from '../../util' +import {getDraftId, getPublishedId, getVersionId} from '../../util' import {RELEASE_METADATA_TMP_DOC_PATH, RELEASE_METADATA_TMP_DOC_TYPE} from './constants' import {type EditableReleaseDocument} from './types' @@ -141,13 +141,18 @@ export function createReleaseOperationsStore(options: { } const handleCreateVersion = async (releaseId: string, documentId: string) => { + const [draftId, publishedId] = [getDraftId(documentId), getPublishedId(documentId)] // fetch original document - const document = await client.getDocument(documentId) + const [draft, published] = await client.getDocuments([publishedId, draftId]) - if (!document) { + if (!draft && !published) { throw new Error(`Document with id ${documentId} not found`) } - const versionDocument = {...document, _id: getVersionId(documentId, releaseId)} + + const versionDocument = { + ...(draft || published), + _id: getVersionId(documentId, releaseId), + } as IdentifiedSanityDocumentStub await (IS_CREATE_VERSION_ACTION_SUPPORTED ? requestAction(client, [