Skip to content

Commit 578a368

Browse files
authoredMar 14, 2025··
fix(core): releases screen should not crash if schema type is unknown (#8942)
1 parent 4c455ec commit 578a368

File tree

3 files changed

+29
-18
lines changed

3 files changed

+29
-18
lines changed
 

‎packages/sanity/src/core/i18n/bundles/studio.ts

+3
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,9 @@ export const studioLocaleStrings = defineLocalesResources('studio', {
379379
/** Label to show in the document footer indicating the revision from date of the document */
380380
'document-status.revision-from': 'Revision from <em>{{date}}</em>',
381381

382+
/** Label to indicate that a document type was not found */
383+
'document.type.not-found': 'Document type "{{type}}" not found',
384+
382385
/** The value of the <code>_key</code> property must be a unique string. */
383386
'form.error.duplicate-keys-alert.details.additional-description':
384387
'The value of the <code>_key</code> property must be a unique string.',

‎packages/sanity/src/core/releases/tool/detail/ReleaseSummary.tsx

+2-8
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ export function ReleaseSummary(props: ReleaseSummaryProps) {
5555
const [pendingAddedDocument, setPendingAddedDocument] = useState<BundleDocumentRow[]>([])
5656

5757
const {t} = useTranslation(releasesLocaleNamespace)
58-
const {t: tCore} = useTranslation()
5958

6059
const releaseId = getReleaseIdFromReleaseDocumentId(release._id)
6160

@@ -74,14 +73,9 @@ export function ReleaseSummary(props: ReleaseSummaryProps) {
7473
if (!isBundleDocumentRow(rowProps.datum)) return null
7574
if (rowProps.datum.isPending) return null
7675

77-
return (
78-
<DocumentActions
79-
document={rowProps.datum}
80-
releaseTitle={release.metadata.title || tCore('release.placeholder-untitled-release')}
81-
/>
82-
)
76+
return <DocumentActions document={rowProps.datum} />
8377
},
84-
[release.metadata.title, release.state, tCore],
78+
[release.state],
8579
)
8680

8781
const documentTableColumnDefs = useMemo(

‎packages/sanity/src/core/releases/tool/detail/documentTable/DocumentActions.tsx

+24-10
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {memo, useMemo, useState} from 'react'
44

55
import {MenuButton, MenuItem} from '../../../../../ui-components'
66
import {ContextMenuButton} from '../../../../components/contextMenuButton'
7+
import {useSchema} from '../../../../hooks'
78
import {useTranslation} from '../../../../i18n'
89
import {useDocumentPairPermissions} from '../../../../store/_legacy/grants/documentPairPermissions'
910
import {getPublishedId, getVersionFromId} from '../../../../util/draftUtils'
@@ -13,14 +14,8 @@ import {releasesLocaleNamespace} from '../../../i18n'
1314
import {isGoingToUnpublish} from '../../../util/isGoingToUnpublish'
1415
import {type BundleDocumentRow} from '../ReleaseSummary'
1516

16-
export const DocumentActions = memo(
17-
function DocumentActions({
18-
document,
19-
releaseTitle,
20-
}: {
21-
document: BundleDocumentRow
22-
releaseTitle: string
23-
}) {
17+
const DocumentActionsInner = memo(
18+
function DocumentActionsInner({document}: {document: BundleDocumentRow}) {
2419
const [showDiscardDialog, setShowDiscardDialog] = useState(false)
2520
const [showUnpublishDialog, setShowUnpublishDialog] = useState(false)
2621
const {t: coreT} = useTranslation()
@@ -124,6 +119,25 @@ export const DocumentActions = memo(
124119
</>
125120
)
126121
},
127-
(prev, next) =>
128-
prev.document.memoKey === next.document.memoKey && prev.releaseTitle === next.releaseTitle,
122+
(prev, next) => prev.document.memoKey === next.document.memoKey,
129123
)
124+
125+
export const DocumentActions = memo(function GuardedDocumentActions(props: {
126+
document: BundleDocumentRow
127+
}) {
128+
const schema = useSchema()
129+
const type = schema.get(props.document.document._type)
130+
const {t} = useTranslation()
131+
if (!type) {
132+
return (
133+
<ContextMenuButton
134+
disabled
135+
tooltipProps={{
136+
content: t('document.type.not-found', {type: props.document.document._type}),
137+
}}
138+
/>
139+
)
140+
}
141+
142+
return <DocumentActionsInner {...props} />
143+
})

0 commit comments

Comments
 (0)
Please sign in to comment.