Skip to content

Commit 8f64b22

Browse files
committed
Fix crash when removing a link mark with no active mark present
The link toolbar's onRemove handler called editor.removeMark()/ removeMarkAtRange() with the result of an unguarded Array.find(), which is undefined whenever the selection has no active link mark. Slate's Mark.create() silently defaults an undefined argument to {} and passes it to Mark.fromJSON(), which throws "Mark.fromJS() requires a type string." This is reached whenever a user opens the Link popover and confirms an empty URL field without ever having applied a link (Enter or the Add button triggers onConfirm, which delegates to onRemove when the field is blank). Guard onRemove the same way the neighboring removeMarksOfTypeInRange helper already does: no-op when there's no active mark to remove.
1 parent 52fd9fb commit 8f64b22

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

app/src/components/composer-editor/toolbar-component-factories.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,13 @@ export function BuildMarkButtonWithValuePicker(config) {
201201
e.preventDefault();
202202
const { value, editor } = this.props;
203203
const active = safeActiveMarks(value).find((m) => m.type === config.type);
204+
if (!active) {
205+
// Nothing to remove — e.g. the user confirmed an empty URL field
206+
// without ever having applied a mark. Calling into Slate with an
207+
// undefined mark throws inside Mark.fromJSON.
208+
editor.focus();
209+
return;
210+
}
204211
if (value.selection.isCollapsed) {
205212
const anchorNode = value.document.getNode(value.selection.anchor.key);
206213
const expanded = value.selection.moveToRangeOfNode(anchorNode);

0 commit comments

Comments
 (0)