Skip to content

Commit 5be2ada

Browse files
committedJun 15, 2024
make the array match defensive
1 parent 59e612e commit 5be2ada

File tree

4 files changed

+24
-8
lines changed

4 files changed

+24
-8
lines changed
 

‎CHANGELOG.md

+8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# CHANGELOG
22

3+
## 0.5.7
4+
5+
_2024-06-14_
6+
7+
### Bugfix
8+
9+
- `arrayMatch` is now null-safe
10+
311
## 0.5.6
412

513
_2024-06-14_

‎package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-fluid-table",
3-
"version": "0.5.6",
3+
"version": "0.5.7",
44
"description": "A React table inspired by react-window",
55
"author": "Mckervin Ceme <mckervinc@live.com>",
66
"license": "MIT",

‎src/TableContext.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ function TableContextProvider<T>({ children, initialState }: ProviderProps<T>) {
171171
(refreshed.minColumnWidth || _stateOnMount.current.minColumnWidth) ?? 80,
172172
refreshed.columns
173173
);
174-
if (!arraysMatch(widths, _stateOnMount.current.pixelWidths!)) {
174+
if (!arraysMatch(widths, _stateOnMount.current.pixelWidths)) {
175175
refreshed.pixelWidths = widths;
176176
}
177177
}

‎src/util.ts

+14-6
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,26 @@ export const cx = (...args: (string | number | null | boolean | undefined)[]) =>
1313
.join(" ");
1414
};
1515

16-
export const arraysMatch = <T>(arr1: T[], arr2: T[]) => {
17-
if (arr1.length !== arr2.length) {
18-
return false;
16+
export const arraysMatch = <T>(arr1: T[] | null | undefined, arr2: T[] | null | undefined) => {
17+
if (arr1 == null && arr2 == null) {
18+
return true;
1919
}
2020

21-
for (var i = 0; i < arr1.length; i++) {
22-
if (arr1[i] !== arr2[i]) {
21+
if (arr1 != null && arr2 != null) {
22+
if (arr1.length !== arr2.length) {
2323
return false;
2424
}
25+
26+
for (var i = 0; i < arr1.length; i++) {
27+
if (arr1[i] !== arr2[i]) {
28+
return false;
29+
}
30+
}
31+
32+
return true;
2533
}
2634

27-
return true;
35+
return false;
2836
};
2937

3038
export const randomString = (num: number) => {

0 commit comments

Comments
 (0)