Skip to content

DOCX comment bookmarks cause Unknown node type: bookmarkStart and drop comments #3828

Description

@ohcedar

Summary

DOCX comments containing w:bookmarkStart / w:bookmarkEnd nodes fail during comment HTML conversion with:

RangeError: Unknown node type: bookmarkStart
Failed to convert comment

The affected comment is then omitted from the loaded comments list.

Minimal shape

A comment containing an invisible bookmark pair around visible mention text is sufficient:

<w:comment w:id="1">
  <w:p>
    <w:r><w:t>Before mention </w:t></w:r>
    <w:bookmarkStart w:id="42" w:name="_mention"/>
    <w:r><w:t>@Person</w:t></w:r>
    <w:bookmarkEnd w:id="42"/>
  </w:p>
</w:comment>

Root cause

The full DOCX editor schema includes bookmarkStart and bookmarkEnd, so the comment XML is converted to valid DOCX-schema JSON.

During processLoadedDocxComments, getHtmlFromComment normalizes that JSON and creates a headless text editor using getRichTextExtensions(). That smaller schema does not include bookmark nodes, but normalizeCommentForEditor currently passes them through. schema.nodeFromJSON throws, the catch returns no HTML, and this guard skips the non-tracked comment:

if (!htmlContent && !comment.trackedChange) {
  return;
}

Expected behavior

Invisible bookmark boundary nodes should not prevent the visible comment content from importing.

Suggested narrow fix

Ignore only bookmark boundary nodes while producing the comment's display HTML:

if (node.type === 'bookmarkStart' || node.type === 'bookmarkEnd') {
  return null;
}

This leaves the original docxCommentJSON unchanged, so the imported DOCX representation still retains the bookmark metadata. In a local reproduction with two affected comments, both comments imported successfully, visible text and mentions remained intact, the original bookmark JSON was preserved, and the console errors disappeared.

Versions checked

  • @harbour-enterprises/superdoc@1.44.1
  • @harbour-enterprises/superdoc@1.45.0
  • Current main implementation of packages/superdoc/src/stores/comments-store.js

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions