From 20e8647e33a8c4a388287322242452ba2ccd9f13 Mon Sep 17 00:00:00 2001 From: Luke Cotter <4013877+lukecotter@users.noreply.github.com> Date: Mon, 24 Mar 2025 16:20:33 +0000 Subject: [PATCH 1/2] perf: avoid extra call to innerHTML This avoids the input needing to be parsed which we are going to do later anyway. --- src/js/core/cell/Cell.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/js/core/cell/Cell.js b/src/js/core/cell/Cell.js index bc68ae0e7..178a1f4c4 100644 --- a/src/js/core/cell/Cell.js +++ b/src/js/core/cell/Cell.js @@ -98,10 +98,8 @@ export default class Cell extends CoreFeature{ //generate cell contents _generateContents(){ - var val; - - val = this.chain("cell-format", this, null, () => { - return this.element.innerHTML = this.value; + const val = this.chain("cell-format", this, null, () => { + return this.value; }); switch(typeof val){ From 113f48fee48eb2e8150ff5cd5de83bb3f32afbdc Mon Sep 17 00:00:00 2001 From: Luke Cotter <4013877+lukecotter@users.noreply.github.com> Date: Mon, 24 Mar 2025 16:21:09 +0000 Subject: [PATCH 2/2] perf: switch to removeChild for clearing cell content It is faster than using innerHTML = '' --- src/js/core/cell/Cell.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/js/core/cell/Cell.js b/src/js/core/cell/Cell.js index 178a1f4c4..c2fbbf9c8 100644 --- a/src/js/core/cell/Cell.js +++ b/src/js/core/cell/Cell.js @@ -107,11 +107,10 @@ export default class Cell extends CoreFeature{ if(val instanceof Node){ //clear previous cell contents - while(this.element.firstChild) this.element.removeChild(this.element.firstChild); - + this._clearCellContent(); this.element.appendChild(val); }else{ - this.element.innerHTML = ""; + this._clearCellContent(); if(val != null){ console.warn("Format Error - Formatter has returned a type of object, the only valid formatter object return is an instance of Node, the formatter returned:", val); @@ -119,13 +118,17 @@ export default class Cell extends CoreFeature{ } break; case "undefined": - this.element.innerHTML = ""; + this._clearCellContent(); break; default: this.element.innerHTML = val; } } + _clearCellContent(){ + while(this.element.firstChild) this.element.removeChild(this.element.firstChild); + } + cellRendered(){ this.dispatch("cell-rendered", this); }