From cca4a6f534ed5dd67089e27bc70970da8424af25 Mon Sep 17 00:00:00 2001 From: Marcus Forsberg Date: Mon, 6 May 2024 07:54:23 +0200 Subject: [PATCH 1/2] fix: don't crash when interacting with empty link field (#9) --- 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 ? (