Skip to content

Commit 4afdef4

Browse files
authored
Merge pull request #419 from Harbour-Enterprises/nick/har-9353-re-imported-comments
HAR-9353 - Prevent trying to convert empty comment json
2 parents 6e255c0 + 8027d27 commit 4afdef4

1 file changed

Lines changed: 19 additions & 8 deletions

File tree

packages/superdoc/src/stores/comments-store.js

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,9 @@ export const useCommentsStore = defineStore('comments', () => {
447447
if (__IS_DEBUG__) console.debug('[processLoadedDocxComments] processing comments...', comments);
448448

449449
comments.forEach((comment) => {
450+
const htmlContent = getHTmlFromComment(comment.textJson);
451+
if (!htmlContent) return;
452+
450453
const importedName = `${comment.creatorName.replace('(imported)', '')} (imported)`
451454
const newComment = useComment({
452455
fileId: documentId,
@@ -522,14 +525,22 @@ export const useCommentsStore = defineStore('comments', () => {
522525
* @returns {string} The HTML content
523526
*/
524527
const getHTmlFromComment = (commentTextJson) => {
525-
const editor = new Editor({
526-
mode: 'text',
527-
isHeadless: true,
528-
content: commentTextJson,
529-
loadFromSchema: true,
530-
extensions: getRichTextExtensions(),
531-
});
532-
return editor.getHTML();
528+
// If no content, we can't convert and its not a valid comment
529+
if (!commentTextJson.content?.length) return;
530+
531+
try {
532+
const editor = new Editor({
533+
mode: 'text',
534+
isHeadless: true,
535+
content: commentTextJson,
536+
loadFromSchema: true,
537+
extensions: getRichTextExtensions(),
538+
});
539+
return editor.getHTML();
540+
} catch (error) {
541+
console.warn('Failed to convert comment', error);
542+
return;
543+
};
533544
};
534545

535546
return {

0 commit comments

Comments
 (0)