Skip to content

Commit

Permalink
fix(dropdown): prevent null reference errors on dynamic positioning
Browse files Browse the repository at this point in the history
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)".
  • Loading branch information
monicawheeler authored and kajabi-bot committed Mar 13, 2024
1 parent 5c93230 commit f7b04e6
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/sage-system/lib/dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit f7b04e6

Please sign in to comment.