Skip to content

Commit fb2fa28

Browse files
authored
fix: add more checks around cached rows (#881)
* fix: add more checks around cached rows - there were many assumptions that certain objects/fields were defined and calls on them were being made but it could happen in certain rare case that these row cache fields are actually undefined and that threw errors on our end, so this PR adds more checks before using any of these row cache objects/arrays
1 parent a9e7e53 commit fb2fa28

File tree

1 file changed

+28
-22
lines changed

1 file changed

+28
-22
lines changed

src/slick.grid.ts

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4408,19 +4408,17 @@ export class SlickGrid<TData = any, C extends Column<TData> = Column<TData>, O e
44084408

44094409
protected ensureCellNodesInRowsCache(row: number) {
44104410
const cacheEntry = this.rowsCache[row];
4411-
if (cacheEntry) {
4412-
if (cacheEntry.cellRenderQueue.length) {
4413-
const rowNode = cacheEntry.rowNode as HTMLElement[];
4414-
let children = Array.from(rowNode[0].children) as HTMLElement[];
4415-
if (rowNode.length > 1) {
4416-
children = children.concat(Array.from(rowNode[1].children) as HTMLElement[]);
4417-
}
4411+
if (cacheEntry?.cellRenderQueue.length && cacheEntry.rowNode?.length) {
4412+
const rowNode = cacheEntry.rowNode as HTMLElement[];
4413+
let children = Array.from(rowNode[0].children) as HTMLElement[];
4414+
if (rowNode.length > 1) {
4415+
children = children.concat(Array.from(rowNode[1].children) as HTMLElement[]);
4416+
}
44184417

4419-
let i = children.length - 1;
4420-
while (cacheEntry.cellRenderQueue.length) {
4421-
const columnIdx = cacheEntry.cellRenderQueue.pop();
4422-
(cacheEntry.cellNodesByColumnIdx as HTMLElement[])[columnIdx] = children[i--];
4423-
}
4418+
let i = children.length - 1;
4419+
while (cacheEntry.cellRenderQueue.length) {
4420+
const columnIdx = cacheEntry.cellRenderQueue.pop();
4421+
(cacheEntry.cellNodesByColumnIdx as HTMLElement[])[columnIdx] = children[i--];
44244422
}
44254423
}
44264424
}
@@ -4625,20 +4623,28 @@ export class SlickGrid<TData = any, C extends Column<TData> = Column<TData>, O e
46254623
for (let i = 0, ii = rows.length; i < ii; i++) {
46264624
if ((this.hasFrozenRows) && (rows[i] >= this.actualFrozenRow)) {
46274625
if (this.hasFrozenColumns()) {
4628-
this.rowsCache[rows[i]].rowNode = [x.firstChild as HTMLElement, xRight.firstChild as HTMLElement];
4629-
this._canvasBottomL.appendChild(x.firstChild as ChildNode);
4630-
this._canvasBottomR.appendChild(xRight.firstChild as ChildNode);
4626+
if (this.rowsCache?.hasOwnProperty(rows[i]) && x.firstChild && xRight.firstChild) {
4627+
this.rowsCache[rows[i]].rowNode = [x.firstChild as HTMLElement, xRight.firstChild as HTMLElement];
4628+
this._canvasBottomL.appendChild(x.firstChild as ChildNode);
4629+
this._canvasBottomR.appendChild(xRight.firstChild as ChildNode);
4630+
}
46314631
} else {
4632-
this.rowsCache[rows[i]].rowNode = [x.firstChild as HTMLElement];
4633-
this._canvasBottomL.appendChild(x.firstChild as ChildNode);
4632+
if (this.rowsCache?.hasOwnProperty(rows[i]) && x.firstChild) {
4633+
this.rowsCache[rows[i]].rowNode = [x.firstChild as HTMLElement];
4634+
this._canvasBottomL.appendChild(x.firstChild as ChildNode);
4635+
}
46344636
}
46354637
} else if (this.hasFrozenColumns()) {
4636-
this.rowsCache[rows[i]].rowNode = [x.firstChild as HTMLElement, xRight.firstChild as HTMLElement];
4637-
this._canvasTopL.appendChild(x.firstChild as ChildNode);
4638-
this._canvasTopR.appendChild(xRight.firstChild as ChildNode);
4638+
if (this.rowsCache?.hasOwnProperty(rows[i]) && x.firstChild && xRight.firstChild) {
4639+
this.rowsCache[rows[i]].rowNode = [x.firstChild as HTMLElement, xRight.firstChild as HTMLElement];
4640+
this._canvasTopL.appendChild(x.firstChild as ChildNode);
4641+
this._canvasTopR.appendChild(xRight.firstChild as ChildNode);
4642+
}
46394643
} else {
4640-
this.rowsCache[rows[i]].rowNode = [x.firstChild as HTMLElement];
4641-
this._canvasTopL.appendChild(x.firstChild as ChildNode);
4644+
if (this.rowsCache?.hasOwnProperty(rows[i]) && x.firstChild) {
4645+
this.rowsCache[rows[i]].rowNode = [x.firstChild as HTMLElement];
4646+
this._canvasTopL.appendChild(x.firstChild as ChildNode);
4647+
}
46424648
}
46434649
}
46444650

0 commit comments

Comments
 (0)