Merge branch 'main' into pr-728
This commit is contained in:
@@ -61,6 +61,9 @@ describe('isRecoverableEditorTransformError', () => {
|
||||
expect(isRecoverableEditorTransformError(new RangeError(
|
||||
'Invalid content for node blockContainer: <paragraph("Procedures are long-running"), blockGroup(blockContainer(bulletListItem("Step")))>',
|
||||
))).toBe(true)
|
||||
expect(isRecoverableEditorTransformError(transformError(
|
||||
'Cannot join blockGroup onto blockContainer',
|
||||
))).toBe(true)
|
||||
expect(isRecoverableEditorTransformError(new RangeError(
|
||||
'Inserted content deeper than insertion position',
|
||||
))).toBe(true)
|
||||
@@ -111,6 +114,13 @@ describe('installRichEditorTransformErrorRecovery', () => {
|
||||
)
|
||||
})
|
||||
|
||||
it('repairs invalid block joins after pull refreshes editor state', () => {
|
||||
expectDocumentRepairRecovery(
|
||||
transformError('Cannot join blockGroup onto blockContainer'),
|
||||
'invalid_block_join',
|
||||
)
|
||||
})
|
||||
|
||||
it('recovers table selection transactions whose target row changed underneath BlockNote', () => {
|
||||
expectDocumentRepairRecovery(
|
||||
new RangeError('Index 1 out of range for <tableRow(tableCell(tableParagraph("A")))>'),
|
||||
|
||||
@@ -36,6 +36,7 @@ interface RepairableBlockNoteEditor {
|
||||
}
|
||||
|
||||
type RecoveryReason =
|
||||
| 'invalid_block_join'
|
||||
| 'invalid_insertion_depth'
|
||||
| 'mismatched_transaction'
|
||||
| 'stale_block_reference'
|
||||
@@ -81,11 +82,15 @@ function isTablePositionOutOfRangeError(error: unknown): boolean {
|
||||
return error instanceof RangeError && /^Index \d+ out of range for <tableRow\(/.test(error.message)
|
||||
}
|
||||
|
||||
function isInvalidBlockJoinError(error: unknown): boolean {
|
||||
return isTransformError(error) && error.message === 'Cannot join blockGroup onto blockContainer'
|
||||
}
|
||||
|
||||
export function isStaleBlockReferenceError(error: unknown): boolean {
|
||||
return error instanceof Error && /^Block with ID .+ not found$/.test(error.message)
|
||||
}
|
||||
|
||||
function isTransformError(error: unknown): boolean {
|
||||
function isTransformError(error: unknown): error is Error {
|
||||
return error instanceof Error && error.name === 'TransformError'
|
||||
}
|
||||
|
||||
@@ -114,16 +119,17 @@ function recoveryReason(
|
||||
if (transactionDocIsStale(transaction, view)) return 'stale_transaction'
|
||||
if (isMismatchedTransactionError(error)) return 'mismatched_transaction'
|
||||
if (isStaleBlockReferenceError(error)) return 'stale_block_reference'
|
||||
if (isInvalidBlockJoinError(error)) return 'invalid_block_join'
|
||||
if (isInvalidInsertionDepthError(error)) return 'invalid_insertion_depth'
|
||||
if (isTablePositionOutOfRangeError(error)) return 'table_position_out_of_range'
|
||||
return 'transform_error'
|
||||
}
|
||||
|
||||
function shouldRepairEditorDocument(error: unknown): boolean {
|
||||
return isRecoverableRangeError(error)
|
||||
return isRecoverableRangeError(error) || isInvalidBlockJoinError(error)
|
||||
}
|
||||
|
||||
export function reportRecoveredEditorTransformError(reason: RecoveryReason, error: unknown): void {
|
||||
export const reportRecoveredEditorTransformError = (reason: RecoveryReason, error: unknown): void => {
|
||||
console.warn('[editor] Recovered rich-editor transform error:', error)
|
||||
trackEvent('rich_editor_transform_error_recovered', { reason })
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user