You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by GitBox <gi...@apache.org> on 2021/06/07 20:32:59 UTC

[GitHub] [superset] nytai commented on a change in pull request #15025: fix(dashboard): custom css should be removed on unmount

nytai commented on a change in pull request #15025:
URL: https://github.com/apache/superset/pull/15025#discussion_r646920118



##########
File path: superset-frontend/src/dashboard/util/injectCustomCss.ts
##########
@@ -16,19 +16,31 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-export default function injectCustomCss(css) {
+
+function createStyleElement(className: string) {
+  const style = document.createElement('style');
+  style.className = className;
+  style.type = 'text/css';
+  return style;
+}
+
+export default function injectCustomCss(css: string) {
   const className = 'CssEditor-css';
   const head = document.head || document.getElementsByTagName('head')[0];
-  let style = document.querySelector(`.${className}`);
+  const style: HTMLStyleElement =
+    document.querySelector(`.${className}`) || createStyleElement(className);
 
-  if (!style) {
-    style = document.createElement('style');
-    style.className = className;
-    style.type = 'text/css';
-  }
-
-  if (style.styleSheet) {
-    style.styleSheet.cssText = css;
+  if ('styleSheet' in style) {
+    // The original, non-typescript code referenced `style.styleSheet`.
+    // I can't find what sort of element would have a styleSheet property,
+    // and don't know in what situation this condition would be true,
+    // so have created this type to satisfy TS without changing behavior.
+    type MysteryStyleElement = {

Review comment:
       maybe move this type up to the module scope? 




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org