Skip to content

Commit

Permalink
STCOM-1235 validate refs before dereferencing them (#2257)
Browse files Browse the repository at this point in the history
Avoid an NPE in `Paneset` by null-checking a ref before dereferencing
it.

Refs STCOM-1235
  • Loading branch information
zburke authored and github-actions committed Mar 29, 2024
1 parent 30bb634 commit e048662
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 8 additions & 4 deletions lib/Paneset/insertByClientRect.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down

0 comments on commit e048662

Please sign in to comment.