fix: recover stale table editor transforms

This commit is contained in:
lucaronin
2026-05-23 15:28:35 +02:00
parent 7709ad1002
commit 5bb3fe0550
4 changed files with 48 additions and 7 deletions

View File

@@ -48,6 +48,12 @@ describe('isRecoverableEditorTransformError', () => {
expect(isRecoverableEditorTransformError(new RangeError(
'Invalid content for node blockContainer: <paragraph("Procedures are long-running"), blockGroup(blockContainer(bulletListItem("Step")))>',
))).toBe(true)
expect(isRecoverableEditorTransformError(new RangeError(
'Index 1 out of range for <tableRow(tableCell(tableParagraph("A")))>',
))).toBe(true)
expect(isRecoverableEditorTransformError(new RangeError(
'Index 1 out of range for <paragraph("A")>',
))).toBe(false)
expect(isRecoverableEditorTransformError(new Error('unrelated'))).toBe(false)
})
})
@@ -93,6 +99,22 @@ describe('installRichEditorTransformErrorRecovery', () => {
})
})
it('recovers table selection transactions whose target row changed underneath BlockNote', () => {
const tableError = new RangeError(
'Index 1 out of range for <tableRow(tableCell(tableParagraph("A")))>',
)
const { currentDoc, view } = createView(tableError)
const recoverDocument = vi.fn()
installRichEditorTransformErrorRecovery(view, { recoverDocument })
expect(() => view.dispatch({ before: currentDoc })).not.toThrow()
expect(recoverDocument).toHaveBeenCalledTimes(1)
expect(trackEvent).toHaveBeenCalledWith('rich_editor_transform_error_recovered', {
reason: 'table_position_out_of_range',
})
})
it('keeps non-ProseMirror dispatch failures visible', () => {
const { view } = createView(new Error('plugin failed'))