From 35ff3623f2b9ec49233270b63e3a7412f75cf3cf Mon Sep 17 00:00:00 2001 From: Marcus Forsberg Date: Mon, 6 May 2024 07:52:04 +0200 Subject: [PATCH 1/2] fix: don't crash when interacting with empty link field --- src/components/CustomLinkInput.tsx | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/components/CustomLinkInput.tsx b/src/components/CustomLinkInput.tsx index 3704f26..01f6432 100644 --- a/src/components/CustomLinkInput.tsx +++ b/src/components/CustomLinkInput.tsx @@ -23,18 +23,20 @@ export function CustomLinkInput( const linkValue = useFormValue(props.path.slice(0, -1)) as LinkValue | null const [options, setOptions] = useState(null) - const customLinkType = props.customLinkTypes.find((type) => type.value === linkValue!.type)! + const customLinkType = props.customLinkTypes.find((type) => type.value === linkValue!.type) useEffect(() => { - if (Array.isArray(customLinkType.options)) { - setOptions(customLinkType.options) - } else { - customLinkType - .options(document, props.path, workspace.currentUser) - .then((options) => setOptions(options)) + if (customLinkType) { + if (Array.isArray(customLinkType?.options)) { + setOptions(customLinkType.options) + } else { + customLinkType + .options(document, props.path, workspace.currentUser) + .then((options) => setOptions(options)) + } } // eslint-disable-next-line react-hooks/exhaustive-deps - }, [customLinkType.options, props.path, workspace.currentUser]) + }, [customLinkType, props.path, workspace.currentUser]) return options ? (