Skip to content

Commit

Permalink
refactor(core/form/inputs): wrap delete in try/catch to finalize ref …
Browse files Browse the repository at this point in the history
…assignment

It could potentially error, and then we must not set the deleted ref.
  • Loading branch information
skogsmaskin committed May 30, 2023
1 parent 20fb696 commit cd3eb90
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,13 @@ export function BlockObject(props: BlockObjectProps) {
if (isDeleting.current) {
return
}
PortableTextEditor.delete(editor, selfSelection, {mode: 'blocks'})
isDeleting.current = true
try {
PortableTextEditor.delete(editor, selfSelection, {mode: 'blocks'})
} catch (err) {
console.error(err)
} finally {
isDeleting.current = true
}
}, [editor, selfSelection])

// Focus the editor if this object is removed because it was deleted.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,14 @@ export function InlineObjectToolbarPopover(props: InlineObjectToolbarPopoverProp
}
event.preventDefault()
event.stopPropagation()
onDelete(event)
if (deleteButtonRef.current) {
deleteButtonRef.current.disabled = true
try {
onDelete(event)
} catch (err) {
console.error(err)
} finally {
if (deleteButtonRef.current) {
deleteButtonRef.current.disabled = true
}
}
},
[onDelete]
Expand Down

0 comments on commit cd3eb90

Please sign in to comment.