Skip to content

Commit f44786c

Browse files
ryanbonialricokahler
authored andcommitted
fix(core): Fix Title in "Untitled was published" toast (#7473)
* fix(core): Fix Title in "Untitled was published" toast * PR feedback: refactor to useMemo
1 parent 23086e2 commit f44786c

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

packages/sanity/src/structure/panes/document/DocumentOperationResults.tsx

+17-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {useToast} from '@sanity/ui'
2-
import {memo, useEffect, useRef} from 'react'
2+
import {memo, useEffect, useMemo, useRef} from 'react'
33
import {Translate, useDocumentOperationEvent, useTranslation} from 'sanity'
44

55
import {usePaneRouter} from '../../components'
@@ -11,13 +11,27 @@ const IGNORE_OPS = ['patch', 'commit']
1111

1212
export const DocumentOperationResults = memo(function DocumentOperationResults() {
1313
const {push: pushToast} = useToast()
14-
const {documentId, documentType} = useDocumentPane()
15-
const {title} = useDocumentTitle()
14+
const {documentId, documentType, value: documentPaneValue} = useDocumentPane()
15+
const documentTitleInfo = useDocumentTitle()
16+
const titleError = documentTitleInfo.error
1617
const event: any = useDocumentOperationEvent(documentId, documentType)
1718
const prevEvent = useRef(event)
1819
const paneRouter = usePaneRouter()
1920
const {t} = useTranslation(structureLocaleNamespace)
2021

22+
const title = useMemo(() => {
23+
// If title isn't set from document preview, use the title from the document pane value
24+
if (
25+
!documentTitleInfo.title &&
26+
!titleError &&
27+
!IGNORE_OPS.includes(event?.op) &&
28+
typeof documentPaneValue.title === 'string' &&
29+
event?.type === 'success'
30+
) {
31+
return documentPaneValue.title
32+
}
33+
return documentTitleInfo.title
34+
}, [documentTitleInfo.title, titleError, event, documentPaneValue.title])
2135
//Truncate the document title and add "..." if it is over 25 characters
2236
const documentTitleBase = title || t('panes.document-operation-results.operation-undefined-title')
2337
const documentTitle =

0 commit comments

Comments
 (0)