fix: recover table-cell transform errors

This commit is contained in:
lucaronin
2026-05-27 19:50:16 +02:00
parent 41b531e899
commit 8ad23f72e1
2 changed files with 24 additions and 1 deletions

View File

@@ -139,6 +139,13 @@ describe('installRichEditorTransformErrorRecovery', () => {
)
})
it('repairs invalid table-cell joins while editing table contents', () => {
expectDocumentRepairRecovery(
transformError('Cannot join tableCell onto blockContainer'),
'invalid_block_join',
)
})
it('recovers invalid block joins thrown during keydown handling before dispatch', () => {
const { view, keyDownPlugin } = createViewWithSomeProp(() => {
throw transformError('Cannot join blockGroup onto blockContainer')
@@ -155,6 +162,22 @@ describe('installRichEditorTransformErrorRecovery', () => {
})
})
it('recovers invalid table-cell joins thrown during keydown handling', () => {
const { view, keyDownPlugin } = createViewWithSomeProp(() => {
throw transformError('Cannot join tableCell onto blockContainer')
})
const recoverDocument = vi.fn()
installRichEditorTransformErrorRecovery(view, { recoverDocument })
expect(view.someProp('handleKeyDown', (handler) => handler())).toBe(true)
expect(keyDownPlugin).toHaveBeenCalledTimes(1)
expect(recoverDocument).toHaveBeenCalledTimes(1)
expect(trackEvent).toHaveBeenCalledWith('rich_editor_transform_error_recovered', {
reason: 'invalid_block_join',
})
})
it('keeps unrelated keydown handler failures visible', () => {
const { view } = createViewWithSomeProp(() => {
throw new Error('keyboard plugin failed')

View File

@@ -92,7 +92,7 @@ function isTablePositionOutOfRangeError(error: unknown): boolean {
}
function isInvalidBlockJoinError(error: unknown): boolean {
return isTransformError(error) && error.message === 'Cannot join blockGroup onto blockContainer'
return isTransformError(error) && /^Cannot join (blockGroup|tableCell) onto blockContainer$/.test(error.message)
}
export function isStaleBlockReferenceError(error: unknown): boolean {