Summary
Opening a .docx that has Word comments but no tracked changes throws an uncaught TypeError during deferred bootstrap. The editor recovers (mounts and renders normally), but the error fires on every load.
Version
SuperDoc 1.31.2 (not fixed in 1.32.0 source — getTrackChanges.js still dereferences state.doc without a guard).
Repro
- Open any
.docx that has at least one comment anchor and zero w:ins/w:del tracked-change marks.
- Mount it in SuperDoc.
Concrete case that triggered this:
- A doctoral thesis
.docx with comments: 88, trackedChanges: 0.
- Opened verbatim (not saved through SuperDoc first).
- Error appears once per load, inside a
setTimeout queued from processLoadedDocxComments.
Stack trace
Uncaught TypeError: Cannot read properties of undefined (reading 'doc')
at getTrackChanges (superdoc.js:95046)
at createCommentForTrackChanges (superdoc.js:239074)
at bootstrapImportedTrackedChangeComments (superdoc.js:239017)
at superdoc.js:239068 ← inside a setTimeout
Root cause
getTrackChanges in packages/super-editor/src/editors/v1/extensions/track-changes/trackChangesHelpers/getTrackChanges.js dereferences state.doc unconditionally on the first line:
export const getTrackChanges = (state, id = null) => {
const trackedChanges = [];
const allInlineNodes = findInlineNodes(state.doc); // ← throws when state is null/undefined
...
};
The deferred comment-bootstrap path (bootstrapImportedTrackedChangeComments, called via setTimeout after onCommentsLoaded) appears to call this with a null or not-yet-populated state. It runs unconditionally whenever there are imported comments, even when there are no tracked-change marks to process.
Suggested fix
Option A — guard getTrackChanges against a missing state (minimal):
export const getTrackChanges = (state, id = null) => {
const trackedChanges = [];
+ if (!state || !state.doc) return trackedChanges;
const allInlineNodes = findInlineNodes(state.doc);
Option B — skip the bootstrap when there are no tracked-change marks (semantically correct):
function bootstrapImportedTrackedChangeComments(editor, ...) {
+ if (!editor?.state?.doc) return;
+ if (getTrackChanges(editor.state).length === 0) return;
...
}
Both fixes are complementary: A eliminates the crash class, B avoids the unnecessary work. A docs-with-comments-and-no-tracked-changes file is a perfectly normal Word document and should load cleanly.
Impact
Non-fatal — the editor mounts and behaves correctly. The bootstrap merely fails to attach tracked-change context to comments, which is fine since there are none. But the console error fires on every load and could mask real errors.
Summary
Opening a
.docxthat has Word comments but no tracked changes throws an uncaughtTypeErrorduring deferred bootstrap. The editor recovers (mounts and renders normally), but the error fires on every load.Version
SuperDoc 1.31.2 (not fixed in 1.32.0 source —
getTrackChanges.jsstill dereferencesstate.docwithout a guard).Repro
.docxthat has at least one comment anchor and zerow:ins/w:deltracked-change marks.Concrete case that triggered this:
.docxwithcomments: 88,trackedChanges: 0.setTimeoutqueued fromprocessLoadedDocxComments.Stack trace
Root cause
getTrackChangesinpackages/super-editor/src/editors/v1/extensions/track-changes/trackChangesHelpers/getTrackChanges.jsdereferencesstate.docunconditionally on the first line:The deferred comment-bootstrap path (
bootstrapImportedTrackedChangeComments, called viasetTimeoutafteronCommentsLoaded) appears to call this with anullor not-yet-populatedstate. It runs unconditionally whenever there are imported comments, even when there are no tracked-change marks to process.Suggested fix
Option A — guard
getTrackChangesagainst a missing state (minimal):export const getTrackChanges = (state, id = null) => { const trackedChanges = []; + if (!state || !state.doc) return trackedChanges; const allInlineNodes = findInlineNodes(state.doc);Option B — skip the bootstrap when there are no tracked-change marks (semantically correct):
function bootstrapImportedTrackedChangeComments(editor, ...) { + if (!editor?.state?.doc) return; + if (getTrackChanges(editor.state).length === 0) return; ... }Both fixes are complementary: A eliminates the crash class, B avoids the unnecessary work. A docs-with-comments-and-no-tracked-changes file is a perfectly normal Word document and should load cleanly.
Impact
Non-fatal — the editor mounts and behaves correctly. The bootstrap merely fails to attach tracked-change context to comments, which is fine since there are none. But the console error fires on every load and could mask real errors.