Commit de7dcbc
authored
fix(super-editor): null-safe getTrackChanges to avoid init-race crash (SD-2641) (#3253)
createCommentForTrackChanges is scheduled from processLoadedDocxComments
via setTimeout(0). That only defers to the next tick; it does not wait for
the editor's PM state to be initialized. When the bootstrap fires before
editor.state is attached, getTrackChanges(editor.state) becomes
getTrackChanges(undefined) and crashes reading state.doc.
The same race affects all four call sites of getTrackChanges in
comments-store.js (lines 294, 1143, 1453, 1545), so harden the helper once
rather than guarding each caller. A pure helper returning [] when there is
no state to inspect is the semantically correct null behaviour.
Adds focused unit tests covering undefined / null / missing-doc inputs.1 parent 53e2c47 commit de7dcbc
2 files changed
Lines changed: 34 additions & 2 deletions
File tree
- packages/super-editor/src/editors/v1/extensions/track-changes/trackChangesHelpers
Lines changed: 8 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
7 | | - | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
8 | 13 | | |
9 | 14 | | |
10 | 15 | | |
11 | 16 | | |
| 17 | + | |
12 | 18 | | |
13 | 19 | | |
14 | 20 | | |
| |||
Lines changed: 26 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
0 commit comments