fix: recover invalid editor block joins
This commit is contained in:
@@ -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