diff --git a/apps/web/src/actions/documents/updateContent.ts b/apps/web/src/actions/documents/updateContent.ts index a8017c163..62539f29b 100644 --- a/apps/web/src/actions/documents/updateContent.ts +++ b/apps/web/src/actions/documents/updateContent.ts @@ -1,5 +1,6 @@ 'use server' +import { BadRequestError } from '@latitude-data/core/lib/errors' import { CommitsRepository, DocumentVersionsRepository, @@ -38,6 +39,14 @@ export const updateDocumentContentAction = withProject document, content: input.content, }) + const updatedDocument = result.unwrap() - return result.unwrap() + // This should never happen but it does happen sometimes + if (!updatedDocument) { + throw new BadRequestError( + 'Could not update document, if the issue persists please contact support.', + ) + } + + return updatedDocument }) diff --git a/apps/web/src/stores/documentVersions.ts b/apps/web/src/stores/documentVersions.ts index e54833025..4114d270f 100644 --- a/apps/web/src/stores/documentVersions.ts +++ b/apps/web/src/stores/documentVersions.ts @@ -207,6 +207,7 @@ export default function useDocumentVersions( { onSuccess: ({ data: document }) => { const prevDocuments = data || [] + mutate( prevDocuments.map((d) => d.documentUuid === document.documentUuid ? document : d,