From f8feb3eddb745208e6e02b1659617f7a066367f1 Mon Sep 17 00:00:00 2001 From: Victor Lin <13424970+victorlin@users.noreply.github.com> Date: Wed, 13 Nov 2024 16:08:22 -0800 Subject: [PATCH] Throw an error if IndividualResource cannot be rendered With the current code, this condition will always fail. Prevent this from silently passing and instead raise an error. --- .../src/components/ListResources/IndividualResource.tsx | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/static-site/src/components/ListResources/IndividualResource.tsx b/static-site/src/components/ListResources/IndividualResource.tsx index 177d3272a..2e1ad18f6 100644 --- a/static-site/src/components/ListResources/IndividualResource.tsx +++ b/static-site/src/components/ListResources/IndividualResource.tsx @@ -133,10 +133,11 @@ export const IndividualResource = ({ const ref = useRef(null); const [topOfColumn, setTopOfColumn] = useState(false); useEffect(() => { - // don't do anything if the ref is undefined or the parent is not a div (IndividualResourceContainer) - if (!ref.current - || !ref.current.parentNode - || ref.current.parentNode.nodeName != 'DIV') return; + if (ref.current === null || + ref.current.parentNode === null || + ref.current.parentNode.nodeName != 'DIV') { + throw new InternalError("ref must be defined and the parent must be a div (IndividualResourceContainer)."); + } /* The column CSS is great but doesn't allow us to know if an element is at the top of its column, so we resort to JS */