Revert "FIX: CSP unsafe-eval errors when using graphviz on client side."

Revert “FIX: CSP unsafe-eval errors when using graphviz on client side.”

This reverts commit b52d4d68d98adfa64373a288e3a8721b4afdcf76.

diff --git a/assets/javascripts/initializers/discourse-graphviz.js.es6 b/assets/javascripts/initializers/discourse-graphviz.js.es6
index ecaeba7..4d03a09 100644
--- a/assets/javascripts/initializers/discourse-graphviz.js.es6
+++ b/assets/javascripts/initializers/discourse-graphviz.js.es6
@@ -2,7 +2,6 @@ import loadScript from "discourse/lib/load-script";
 import { withPluginApi } from "discourse/lib/plugin-api";
 import { escape } from "pretty-text/sanitizer";
 const { run } = Ember;
-let worker = undefined;
 
 export default {
   name: "discourse-graphviz",
@@ -26,43 +25,42 @@ export default {
     const $spinner = $("<div class='spinner tiny'></div>");
     $container.html($spinner);
 
-    if (worker === undefined) {
-      worker = new Worker("/plugins/discourse-graphviz/javascripts/worker.js");
-    }
-
-    worker.addEventListener("message", event => {
-      const data = event.data;
+    loadScript(
+      "/plugins/discourse-graphviz/javascripts/@hpcc-js/wasm@0.3.14/dist/index.min.js"
+    ).then(() => {
       $container.removeClass("is-loading");
 
-      if (data.svgChart) {
-        $container.html(data.svgChart);
-      } else {
-        // graphviz errors are very helpful so we just show them as is
-        const $error = $(
-          "<div class='graph-error'>" + escape(data.errorMessage) + "</div>"
-        );
-        $container.html($error);
-      }
+      let hpccWasm = self["@hpcc-js/wasm"];
+      hpccWasm.graphviz
+        .layout(graphDefinition, "svg", engine)
+        .then(svgChart => {
+          $container.html(svgChart);
+        })
+        .catch(e => {
+          // graphviz errors are very helpful so we just show them as is
+          const $error = $(
+            "<div class='graph-error'>" + escape(e.message) + "</div>"
+          );
+          $container.html($error);
+        });
     });
-
-    worker.postMessage({ graphDefinition, engine });
   },
 
-  initialize(container) {
-    const siteSettings = container.lookup("site-settings:main");
+  initialize() {
+    withPluginApi("0.8.22", api => {
+      api.decorateCooked(
+        $elem => {
+          if (!Discourse.SiteSettings.discourse_graphviz_enabled) {
+            return;
+          }
 
-    if (siteSettings.discourse_graphviz_enabled) {
-      withPluginApi("0.8.22", api => {
-        api.decorateCooked(
-          $elem => {
-            const $graphviz = $elem.find(".graphviz");
-            if ($graphviz.length) {
-              run.debounce(this, this.renderGraphs, $graphviz, 200);
-            }
-          },
-          { id: "graphviz" }
-        );
-      });
-    }
+          const $graphviz = $elem.find(".graphviz");
+          if ($graphviz.length) {
+            run.debounce(this, this.renderGraphs, $graphviz, 200);
+          }
+        },
+        { id: "graphviz" }
+      );
+    });
   }
 };
diff --git a/public/javascripts/worker.js b/public/javascripts/worker.js
deleted file mode 100644
index 1280a1c..0000000
--- a/public/javascripts/worker.js
+++ /dev/null
@@ -1,26 +0,0 @@
-const scriptURL =
-  "/plugins/discourse-graphviz/javascripts/@hpcc-js/wasm@0.3.14/dist/index.min.js";
-
-// There is no document in a worker but @hpcc-js/wasm expects a document object
-// so we work around the problem by declaring the document here.
-const document = {
-  currentScript: {
-    src: scriptURL
-  }
-};
-
-importScripts(scriptURL);
-
-self.addEventListener("message", event => {
-  const data = event.data;
-  let hpccWasm = self["@hpcc-js/wasm"];
-
-  hpccWasm.graphviz
-    .layout(data.graphDefinition, "svg", data.engine)
-    .then(svgChart => {
-      self.postMessage({ svgChart });
-    })
-    .catch(e => {
-      self.postMessage({ errorMessage: e.message });
-    });
-});

GitHub sha: 4c0d5d92