Skip to content

Commit

Permalink
fix: add more checks around cached rows (#881)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
ghiscoding authored Oct 25, 2023
1 parent a9e7e53 commit fb2fa28
Showing 1 changed file with 28 additions and 22 deletions.
50 changes: 28 additions & 22 deletions src/slick.grid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4408,19 +4408,17 @@ 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) {
const rowNode = cacheEntry.rowNode as HTMLElement[];
let children = Array.from(rowNode[0].children) as HTMLElement[];
if (rowNode.length > 1) {
children = children.concat(Array.from(rowNode[1].children) as HTMLElement[]);
}
if (cacheEntry?.cellRenderQueue.length && cacheEntry.rowNode?.length) {
const rowNode = cacheEntry.rowNode as HTMLElement[];
let children = Array.from(rowNode[0].children) as HTMLElement[];
if (rowNode.length > 1) {
children = children.concat(Array.from(rowNode[1].children) as HTMLElement[]);
}

let i = children.length - 1;
while (cacheEntry.cellRenderQueue.length) {
const columnIdx = cacheEntry.cellRenderQueue.pop();
(cacheEntry.cellNodesByColumnIdx as HTMLElement[])[columnIdx] = children[i--];
}
let i = children.length - 1;
while (cacheEntry.cellRenderQueue.length) {
const columnIdx = cacheEntry.cellRenderQueue.pop();
(cacheEntry.cellNodesByColumnIdx as HTMLElement[])[columnIdx] = children[i--];
}
}
}
Expand Down Expand Up @@ -4625,20 +4623,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?.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];
this._canvasBottomL.appendChild(x.firstChild as ChildNode);
if (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?.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?.hasOwnProperty(rows[i]) && x.firstChild) {
this.rowsCache[rows[i]].rowNode = [x.firstChild as HTMLElement];
this._canvasTopL.appendChild(x.firstChild as ChildNode);
}
}
}

Expand Down

0 comments on commit fb2fa28

Please sign in to comment.