fix(editor): guard tippy instance in suggestion handlers (#543)

The popup variable stays undefined when onStart bails out early because
props.clientRect is missing, so popup[0] throws instead of no-oping.
Use optional chaining on the array itself.
This commit is contained in:
Anatoly Rubinshteyn
2026-07-27 23:14:51 +03:00
committed by GitHub
parent 9ec4bedd9a
commit 395dbfae04

View File

@@ -180,13 +180,13 @@ const RenderSuggestions = () => {
if (!props.clientRect) return; if (!props.clientRect) return;
popup[0]?.setProps({ popup?.[0]?.setProps({
getReferenceClientRect: props.clientRect, getReferenceClientRect: props.clientRect,
}); });
}, },
onKeyDown(props: SuggestionKeyDownProps): boolean { onKeyDown(props: SuggestionKeyDownProps): boolean {
if (props.event.key === "Escape") { if (props.event.key === "Escape") {
popup[0]?.hide(); popup?.[0]?.hide();
return true; return true;
} }
@@ -199,7 +199,7 @@ const RenderSuggestions = () => {
); );
}, },
onExit() { onExit() {
popup[0]?.destroy(); popup?.[0]?.destroy();
reactRenderer.destroy(); reactRenderer.destroy();
}, },
}; };
@@ -308,11 +308,11 @@ const renderMentionSuggestions = () => {
onUpdate(props: any) { onUpdate(props: any) {
reactRenderer.updateProps(props); reactRenderer.updateProps(props);
if (!props.clientRect) return; if (!props.clientRect) return;
popup[0]?.setProps({ getReferenceClientRect: props.clientRect }); popup?.[0]?.setProps({ getReferenceClientRect: props.clientRect });
}, },
onKeyDown(props: SuggestionKeyDownProps) { onKeyDown(props: SuggestionKeyDownProps) {
if (props.event.key === "Escape") { if (props.event.key === "Escape") {
popup[0]?.hide(); popup?.[0]?.hide();
return true; return true;
} }
return ( return (
@@ -324,7 +324,7 @@ const renderMentionSuggestions = () => {
); );
}, },
onExit() { onExit() {
popup[0]?.destroy(); popup?.[0]?.destroy();
reactRenderer.destroy(); reactRenderer.destroy();
}, },
}; };