fix: recover stale editor block references

This commit is contained in:
lucaronin
2026-05-23 16:53:43 +02:00
parent f0fb7b7418
commit 12646d4e98
8 changed files with 157 additions and 18 deletions

View File

@@ -67,6 +67,9 @@ describe('isRecoverableEditorTransformError', () => {
expect(isRecoverableEditorTransformError(new RangeError(
'Index 1 out of range for <tableRow(tableCell(tableParagraph("A")))>',
))).toBe(true)
expect(isRecoverableEditorTransformError(new Error(
'Block with ID 6c1c3bb4-e218-4f00-aaf5-40606852d286 not found',
))).toBe(true)
expect(isRecoverableEditorTransformError(new RangeError(
'Index 1 out of range for <paragraph("A")>',
))).toBe(false)
@@ -122,6 +125,21 @@ describe('installRichEditorTransformErrorRecovery', () => {
)
})
it('recovers stale block-reference transactions from toolbar actions', () => {
const { currentDoc, view } = createView(new Error(
'Block with ID 6c1c3bb4-e218-4f00-aaf5-40606852d286 not found',
))
const recoverDocument = vi.fn()
installRichEditorTransformErrorRecovery(view, { recoverDocument })
expect(() => view.dispatch({ before: currentDoc })).not.toThrow()
expect(recoverDocument).not.toHaveBeenCalled()
expect(trackEvent).toHaveBeenCalledWith('rich_editor_transform_error_recovered', {
reason: 'stale_block_reference',
})
})
it('keeps non-ProseMirror dispatch failures visible', () => {
const { view } = createView(new Error('plugin failed'))