From f7b04e6ec39a3c8e185026512705e43a68e4fdc9 Mon Sep 17 00:00:00 2001 From: Monica Wheeler Date: Mon, 11 Mar 2024 11:08:40 -0500 Subject: [PATCH] fix(dropdown): prevent null reference errors on dynamic positioning Add a guard clause in the positionElement function to check for null before accessing wrapperRef.current properties. This prevents runtime errors related to attempting to access properties on null when the dropdown component mounts or updates under certain conditions. Solves Sentry errors "Cannot read properties of null (reading lastElementChild)" and "null is not an object (evaluating r.lastElementChild)". --- packages/sage-system/lib/dropdown.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/sage-system/lib/dropdown.js b/packages/sage-system/lib/dropdown.js index f1a35d6171..c0134fbbf4 100644 --- a/packages/sage-system/lib/dropdown.js +++ b/packages/sage-system/lib/dropdown.js @@ -190,8 +190,12 @@ Sage.dropdown = (function () { } function positionElement(el) { + // Guard clause to check if wrapperRef.current is null + if (!wrapperRef.current) return; + let directionX = null; let directionY = null; + const el = wrapperRef.current; // Elements const button = el;