Skip to content

Commit

Permalink
fix: add more checks around cached rows
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
ghiscoding-SE committed Oct 24, 2023
1 parent 93900ec commit 3fee104
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions src/slick.grid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4408,7 +4408,7 @@ export class SlickGrid<TData = any, C extends Column<TData> = Column<TData>, O e
protected ensureCellNodesInRowsCache(row: number) {
const cacheEntry = this.rowsCache[row];
if (cacheEntry) {
if (cacheEntry.cellRenderQueue.length) {
if (cacheEntry.cellRenderQueue.length && cacheEntry.rowNode && cacheEntry.rowNode.length) {
const rowNode = cacheEntry.rowNode as HTMLElement[];
let children = Array.from(rowNode[0].children) as HTMLElement[];
if (rowNode.length > 1) {
Expand Down Expand Up @@ -4624,20 +4624,28 @@ export class SlickGrid<TData = any, C extends Column<TData> = Column<TData>, O e
for (let i = 0, ii = rows.length; i < ii; i++) {
if ((this.hasFrozenRows) && (rows[i] >= this.actualFrozenRow)) {
if (this.hasFrozenColumns()) {
this.rowsCache[rows[i]].rowNode = [x.firstChild as HTMLElement, xRight.firstChild as HTMLElement];
this._canvasBottomL.appendChild(x.firstChild as ChildNode);
this._canvasBottomR.appendChild(xRight.firstChild as ChildNode);
if (this.rowsCache && this.rowsCache.hasOwnProperty(rows[i]) && x.firstChild && xRight.firstChild) {
this.rowsCache[rows[i]].rowNode = [x.firstChild as HTMLElement, xRight.firstChild as HTMLElement];
this._canvasBottomL.appendChild(x.firstChild as ChildNode);
this._canvasBottomR.appendChild(xRight.firstChild as ChildNode);
}
} else {
this.rowsCache[rows[i]].rowNode = [x.firstChild as HTMLElement];
if (this.rowsCache && this.rowsCache.hasOwnProperty(rows[i]) && x.firstChild) {
this.rowsCache[rows[i]].rowNode = [x.firstChild as HTMLElement];
this._canvasBottomL.appendChild(x.firstChild as ChildNode);
}
}
} else if (this.hasFrozenColumns()) {
this.rowsCache[rows[i]].rowNode = [x.firstChild as HTMLElement, xRight.firstChild as HTMLElement];
this._canvasTopL.appendChild(x.firstChild as ChildNode);
this._canvasTopR.appendChild(xRight.firstChild as ChildNode);
if (this.rowsCache && this.rowsCache.hasOwnProperty(rows[i]) && x.firstChild && xRight.firstChild) {
this.rowsCache[rows[i]].rowNode = [x.firstChild as HTMLElement, xRight.firstChild as HTMLElement];
this._canvasTopL.appendChild(x.firstChild as ChildNode);
this._canvasTopR.appendChild(xRight.firstChild as ChildNode);
}
} else {
this.rowsCache[rows[i]].rowNode = [x.firstChild as HTMLElement];
this._canvasTopL.appendChild(x.firstChild as ChildNode);
if (this.rowsCache && this.rowsCache.hasOwnProperty(rows[i]) && xRight.firstChild) {
this.rowsCache[rows[i]].rowNode = [x.firstChild as HTMLElement];
this._canvasTopL.appendChild(x.firstChild as ChildNode);
}
}
}

Expand Down

0 comments on commit 3fee104

Please sign in to comment.