Skip to content

Commit

Permalink
feat(sanity): add call to config from Structure
Browse files Browse the repository at this point in the history
  • Loading branch information
RitaDias committed Sep 30, 2024
1 parent 92b6071 commit a6082ae
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const DocumentTitle = (props: {documentId: string; documentType: string}) => {
document.title = newTitle
}, [documentTitle, settled, newTitle])

throw new Error('This is an error from the structure tool')
return null
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {ErrorBoundary} from '@sanity/ui'
import {useEffect, useState} from 'react'
import {useCallback, useEffect, useState} from 'react'
import {SourceProvider, type Tool, useWorkspace} from 'sanity'

import {setActivePanes} from '../../getIntentState'
Expand All @@ -25,11 +25,24 @@ export function StructureToolBoundary({tool: {options}}: StructureToolBoundaryPr
}, [])

const [{error}, setError] = useState<{error: unknown}>({error: null})

const handleCatchError = useCallback(
({error: caughtError, info: caughtInfo}: {error: Error; info: React.ErrorInfo}) => {
setError({error: caughtError})
const {onStudioError} = firstSource

if (onStudioError) {
onStudioError(caughtError, caughtInfo)
}
},
[firstSource],
)

// this re-throws if the error it catches is not a PaneResolutionError
if (error) return <StructureError error={error} />

return (
<ErrorBoundary onCatch={setError}>
<ErrorBoundary onCatch={handleCatchError}>
<SourceProvider name={source || firstSource.name}>
<StructureToolProvider defaultDocumentNode={defaultDocumentNode} structure={structure}>
<StructureTool onPaneChange={setActivePanes} />
Expand Down

0 comments on commit a6082ae

Please sign in to comment.