From ec9aebdbe039e26bba386c08a5d3062d3ed3107e Mon Sep 17 00:00:00 2001 From: Stephanie Closson Date: Fri, 22 Sep 2023 14:12:38 -0300 Subject: [PATCH] fixed issue with equality in props, moved to underscore --- package.json | 4 +++- src/divPanelChild.tsx | 4 ++-- yarn.lock | 15 ++++++++++----- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index e2d2a2e..ac03bfb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "grafana-div-panel", - "version": "1.2.1", + "version": "1.2.2", "description": "Create your own panel with html + css and javascript", "scripts": { "build": "webpack -c ./.config/webpack/webpack.config.ts --env production", @@ -34,6 +34,7 @@ "@types/prop-types": "15.7.5", "@types/react": "18.2.22", "@cypress/request": "3.0.0", + "@types/underscore": "^1.11.9", "acorn": "8.8.2", "console-feed": "3.5.0", "copy-webpack-plugin": "^11.0.0", @@ -67,6 +68,7 @@ "typescript": "4.8.4", "webpack": "^5.86.0", "webpack-cli": "^5.1.4", + "underscore": "^1.13.6", "webpack-livereload-plugin": "^3.0.2" }, "dependencies": { diff --git a/src/divPanelChild.tsx b/src/divPanelChild.tsx index b0d718e..cae4015 100644 --- a/src/divPanelChild.tsx +++ b/src/divPanelChild.tsx @@ -2,6 +2,7 @@ import React, { Component } from 'react'; import * as functions from 'utils/functions'; import { DivPanelChildProps, divStyle } from './types'; import { register, compile } from 'utils/handlebars'; +import { isEqual } from 'underscore'; interface State { ref: HTMLDivElement | null; @@ -19,8 +20,7 @@ export class DivPanelChild extends Component { shouldComponentUpdate = (prevProps: DivPanelChildProps, prevState: State): boolean => { const truth = - ((typeof prevProps !== "undefined" && typeof this.props !== "undefined") && - (JSON.stringify(prevProps) !== JSON.stringify(this.props))) || + isEqual(prevProps, this.props) || prevProps.data.state === 'Done' || prevProps.data.state === 'Streaming'; return truth; diff --git a/yarn.lock b/yarn.lock index ec98b09..9902dc4 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2943,6 +2943,11 @@ resolved "https://registry.yarnpkg.com/@types/tough-cookie/-/tough-cookie-4.0.3.tgz#3d06b6769518450871fbc40770b7586334bdfd90" integrity sha512-THo502dA5PzG/sfQH+42Lw3fvmYkceefOspdCwpHRul8ik2Jv1K8I5OZz1AT3/rs46kwgMCe9bSBmDLYkkOMGg== +"@types/underscore@^1.11.9": + version "1.11.9" + resolved "https://registry.yarnpkg.com/@types/underscore/-/underscore-1.11.9.tgz#76a071d27e544e422dbf00f956818b1057f377b2" + integrity sha512-M63wKUdsjDFUfyFt1TCUZHGFk9KDAa5JP0adNUErbm0U45Lr06HtANdYRP+GyleEopEoZ4UyBcdAC5TnW4Uz2w== + "@types/uuid@9.0.1": version "9.0.1" resolved "https://registry.yarnpkg.com/@types/uuid/-/uuid-9.0.1.tgz#98586dc36aee8dacc98cc396dbca8d0429647aa6" @@ -10122,16 +10127,16 @@ unbox-primitive@^1.0.2: has-symbols "^1.0.3" which-boxed-primitive "^1.0.2" -underscore@1.12.1: - version "1.12.1" - resolved "https://registry.yarnpkg.com/underscore/-/underscore-1.12.1.tgz#7bb8cc9b3d397e201cf8553336d262544ead829e" - integrity sha512-hEQt0+ZLDVUMhebKxL4x1BTtDY7bavVofhZ9KZ4aI26X9SRaE+Y3m83XUL1UP2jn8ynjndwCCpEHdUG+9pP1Tw== - underscore@1.7.0: version "1.7.0" resolved "https://registry.yarnpkg.com/underscore/-/underscore-1.7.0.tgz#6bbaf0877500d36be34ecaa584e0db9fef035209" integrity sha512-cp0oQQyZhUM1kpJDLdGO1jPZHgS/MpzoWYfe9+CM2h/QGDZlqwT2T3YGukuBdaNJ/CAPoeyAZRRHz8JFo176vA== +underscore@^1.13.6: + version "1.13.6" + resolved "https://registry.yarnpkg.com/underscore/-/underscore-1.13.6.tgz#04786a1f589dc6c09f761fc5f45b89e935136441" + integrity sha512-+A5Sja4HP1M08MaXya7p5LvjuM7K6q/2EaC0+iovj/wOcMsTzMvDFbasi/oSapiwOlt252IqsKqPjCl7huKS0A== + unicode-canonical-property-names-ecmascript@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/unicode-canonical-property-names-ecmascript/-/unicode-canonical-property-names-ecmascript-2.0.0.tgz#301acdc525631670d39f6146e0e77ff6bbdebddc"