Revert "PERF: Move highlightjs to a background worker, and add result cache (#10191)"

This caused a CORS error when used with S3 asset storage

This reverts commit d09f283e91.
This commit is contained in:
David Taylor
2020-07-15 13:52:35 +01:00
parent c802c7367a
commit 7d300006a1
11 changed files with 46 additions and 280 deletions
@@ -1,37 +1,11 @@
import Component from "@ember/component";
import { highlightText } from "discourse/lib/highlight-syntax";
import { escapeExpression } from "discourse/lib/utilities";
import discourseComputed from "discourse-common/utils/decorators";
import { htmlSafe } from "@ember/template";
import { on, observes } from "discourse-common/utils/decorators";
import highlightSyntax from "discourse/lib/highlight-syntax";
export default Component.extend({
didReceiveAttrs() {
this._super(...arguments);
if (this.code === this.previousCode) return;
this.set("previousCode", this.code);
this.set("highlightResult", null);
const toHighlight = this.code;
highlightText(escapeExpression(toHighlight), this.lang).then(
({ result }) => {
if (toHighlight !== this.code) return; // Code has changed since highlight was requested
this.set("highlightResult", result);
}
);
},
@discourseComputed("code", "highlightResult")
displayCode(code, highlightResult) {
if (highlightResult) return htmlSafe(highlightResult);
return code;
},
@discourseComputed("highlightResult", "lang")
codeClasses(highlightResult, lang) {
const classes = [];
if (lang) classes.push(lang);
if (highlightResult) classes.push("hljs");
return classes.join(" ");
@on("didInsertElement")
@observes("code")
_refresh: function() {
highlightSyntax($(this.element));
}
});
+2 -2
View File
@@ -7,8 +7,8 @@ import discourseComputed from "discourse-common/utils/decorators";
import { popupAjaxError } from "discourse/lib/ajax-error";
import { ajax } from "discourse/lib/ajax";
import { escapeExpression } from "discourse/lib/utilities";
import { url } from "discourse/lib/computed";
import highlightSyntax from "discourse/lib/highlight-syntax";
import { url } from "discourse/lib/computed";
const THEME_UPLOAD_VAR = 2;
const FIELDS_IDS = [0, 1, 5];
@@ -321,7 +321,7 @@ const Theme = RestModel.extend({
}
}
);
highlightSyntax(document.querySelector(".bootbox.modal"));
highlightSyntax();
} else {
return this.save({ remote_update: true }).then(() =>
this.set("changed", false)
@@ -1 +1 @@
<pre><code class={{codeClasses}}>{{displayCode}}</code></pre>
<pre><code class={{lang}}>{{code}}</code></pre>