From 11e3a1509e5810f123a2ec46b1f7a561afed9738 Mon Sep 17 00:00:00 2001 From: Zak Burke Date: Fri, 29 Mar 2024 12:08:59 -0400 Subject: [PATCH] STCOM-1235 validate refs before dereferencing them (#2257) Avoid an NPE in `Paneset` by null-checking a ref before dereferencing it. Refs STCOM-1235 --- CHANGELOG.md | 1 + lib/Paneset/insertByClientRect.js | 12 ++++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ffee4e27c..8f86fa93e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## 12.2.0 IN PROGRESS * Exclude invalid additional currencies. Refs STCOM-1274. +* Validate ref in `Paneset` before dereferencing it. Refs STCOM-1235. ## [12.1.0](https://github.com/folio-org/stripes-components/tree/v12.1.0) (2024-03-12) [Full Changelog](https://github.com/folio-org/stripes-components/compare/v12.0.0...v12.1.0) diff --git a/lib/Paneset/insertByClientRect.js b/lib/Paneset/insertByClientRect.js index f721d725d..5726cdd04 100644 --- a/lib/Paneset/insertByClientRect.js +++ b/lib/Paneset/insertByClientRect.js @@ -2,10 +2,14 @@ import cloneDeep from 'lodash/cloneDeep'; export default (prevArray, newItem) => { - const newClientRect = newItem.getRef().current.getBoundingClientRect(); - const nextIndex = prevArray.findIndex((p) => { - return (p.getRef().current.getBoundingClientRect().left > newClientRect.left); - }); + let nextIndex = -1; + if (newItem.getRef().current) { + const newClientRect = newItem.getRef().current.getBoundingClientRect(); + nextIndex = prevArray.findIndex((p) => { + return (p.getRef().current.getBoundingClientRect().left > newClientRect.left); + }); + } + let newArray; if (nextIndex === -1) { newArray = [...prevArray, newItem];