From 68b06ca498875a2ba586b42746e99885a2693af8 Mon Sep 17 00:00:00 2001 From: silverwind Date: Wed, 12 Oct 2022 21:52:24 +0200 Subject: [PATCH 1/5] Fix mermaid related bugs 1. Apparently, mermaid 9.1.7 no longer sets a `height` attribute on the SVG it produces. Workaround by extracting height from `viewBox` instead. 2. Filter out unresolvable Monaco errors from error display. Fixes: https://github.com/go-gitea/gitea/issues/21427 Ref: https://github.com/microsoft/monaco-editor/issues/2962 --- web_src/js/bootstrap.js | 9 +++++++++ web_src/js/markup/mermaid.js | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/web_src/js/bootstrap.js b/web_src/js/bootstrap.js index 213c9e41df5db..f21ed87875ded 100644 --- a/web_src/js/bootstrap.js +++ b/web_src/js/bootstrap.js @@ -7,9 +7,18 @@ import {joinPaths} from './utils.js'; // This file must be imported before any lazy-loading is being attempted. __webpack_public_path__ = joinPaths(window?.config?.assetUrlPrefix ?? '/', '/'); +const ignoreErrors = [ + /vs\.editor\.nullLanguage/, // https://github.com/microsoft/monaco-editor/issues/2962 +]; + export function showGlobalErrorMessage(msg) { const pageContent = document.querySelector('.page-content'); if (!pageContent) return; + + for (const re of ignoreErrors) { + if (re.test(msg)) return; + } + const el = document.createElement('div'); el.innerHTML = `
`; el.childNodes[0].textContent = msg; diff --git a/web_src/js/markup/mermaid.js b/web_src/js/markup/mermaid.js index 773c46e791089..593272edf2f5c 100644 --- a/web_src/js/markup/mermaid.js +++ b/web_src/js/markup/mermaid.js @@ -50,7 +50,7 @@ export async function renderMermaid() { // can't use bindFunctions here because we can't cross the iframe boundary. This // means js-based interactions won't work but they aren't intended to work either mermaid.mermaidAPI.render('mermaid', source, (svgStr) => { - const heightStr = (svgStr.match(/height="(.+?)"/) || [])[1]; + const heightStr = (svgStr.match(/viewBox="(.+?)"/) || [])[1].split(/\s/)[3]; if (!heightStr) return displayError(el, new Error('Could not determine chart height')); const iframe = document.createElement('iframe'); iframe.classList.add('markup-render'); From 373631012dad17da99b5019616a3f7a084866cf7 Mon Sep 17 00:00:00 2001 From: silverwind Date: Wed, 12 Oct 2022 22:38:02 +0200 Subject: [PATCH 2/5] improve height extraction --- web_src/js/markup/mermaid.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web_src/js/markup/mermaid.js b/web_src/js/markup/mermaid.js index 593272edf2f5c..62de9a3aae053 100644 --- a/web_src/js/markup/mermaid.js +++ b/web_src/js/markup/mermaid.js @@ -50,7 +50,7 @@ export async function renderMermaid() { // can't use bindFunctions here because we can't cross the iframe boundary. This // means js-based interactions won't work but they aren't intended to work either mermaid.mermaidAPI.render('mermaid', source, (svgStr) => { - const heightStr = (svgStr.match(/viewBox="(.+?)"/) || [])[1].split(/\s/)[3]; + const heightStr = (svgStr.match(/viewBox="(.+?)"/) || ['', ''])[1].split(/\s+/)[3]; if (!heightStr) return displayError(el, new Error('Could not determine chart height')); const iframe = document.createElement('iframe'); iframe.classList.add('markup-render'); From 011cffa3183577e2119d67a61e78cf716fd0ac96 Mon Sep 17 00:00:00 2001 From: silverwind Date: Thu, 13 Oct 2022 08:51:40 +0200 Subject: [PATCH 3/5] remove array --- web_src/js/bootstrap.js | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/web_src/js/bootstrap.js b/web_src/js/bootstrap.js index f21ed87875ded..8e8e577c5cb43 100644 --- a/web_src/js/bootstrap.js +++ b/web_src/js/bootstrap.js @@ -7,17 +7,12 @@ import {joinPaths} from './utils.js'; // This file must be imported before any lazy-loading is being attempted. __webpack_public_path__ = joinPaths(window?.config?.assetUrlPrefix ?? '/', '/'); -const ignoreErrors = [ - /vs\.editor\.nullLanguage/, // https://github.com/microsoft/monaco-editor/issues/2962 -]; - export function showGlobalErrorMessage(msg) { const pageContent = document.querySelector('.page-content'); if (!pageContent) return; - for (const re of ignoreErrors) { - if (re.test(msg)) return; - } + // https://github.com/microsoft/monaco-editor/issues/2962 + if (/vs\.editor\.nullLanguage/.test(msg)) return; const el = document.createElement('div'); el.innerHTML = `
`; From 78a4ef2a9e74c31c5027e89cd4fd24e6baac812b Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Thu, 13 Oct 2022 16:29:46 +0800 Subject: [PATCH 4/5] check the error message in processWindowErrorEvent --- web_src/js/bootstrap.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/web_src/js/bootstrap.js b/web_src/js/bootstrap.js index 8e8e577c5cb43..52ad6fb148d3a 100644 --- a/web_src/js/bootstrap.js +++ b/web_src/js/bootstrap.js @@ -11,9 +11,6 @@ export function showGlobalErrorMessage(msg) { const pageContent = document.querySelector('.page-content'); if (!pageContent) return; - // https://github.com/microsoft/monaco-editor/issues/2962 - if (/vs\.editor\.nullLanguage/.test(msg)) return; - const el = document.createElement('div'); el.innerHTML = `
`; el.childNodes[0].textContent = msg; @@ -29,6 +26,10 @@ function processWindowErrorEvent(e) { // If a script inserts a newly created (and content changed) element into DOM, there will be a nonsense error event reporting: Script error: line 0, col 0. return; // ignore such nonsense error event } + + // Wait for upstream fix: https://github.com/microsoft/monaco-editor/issues/2962 + if (e.message.includes('Language id "vs.editor.nullLanguage" is not configured nor known')) return; + showGlobalErrorMessage(`JavaScript error: ${e.message} (${e.filename} @ ${e.lineno}:${e.colno}). Open browser console to see more details.`); } From 67c581b48301bd060f87b325058f6c3f5e2c38c9 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Thu, 13 Oct 2022 16:30:14 +0800 Subject: [PATCH 5/5] Update web_src/js/bootstrap.js --- web_src/js/bootstrap.js | 1 - 1 file changed, 1 deletion(-) diff --git a/web_src/js/bootstrap.js b/web_src/js/bootstrap.js index 52ad6fb148d3a..b5db3985456e0 100644 --- a/web_src/js/bootstrap.js +++ b/web_src/js/bootstrap.js @@ -10,7 +10,6 @@ __webpack_public_path__ = joinPaths(window?.config?.assetUrlPrefix ?? '/', '/'); export function showGlobalErrorMessage(msg) { const pageContent = document.querySelector('.page-content'); if (!pageContent) return; - const el = document.createElement('div'); el.innerHTML = `
`; el.childNodes[0].textContent = msg;