Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
feat(render): display syntax errors inside render note
Elian Dorancee16dc3dc10
diff --git a/apps/client/src/services/render.ts b/apps/client/src/services/render.tsindex f09d26532d..2c7371ba3b 100644--- a/apps/client/src/services/render.ts+++ b/apps/client/src/services/render.ts@@ -12,26 +12,34 @@ async function render(note: FNote, $el: JQuery<HTMLElement>, onError?: (e: unkno$el.empty().toggle(renderNoteIds.length > 0);- for (const renderNoteId of renderNoteIds) {- const bundle = await server.post<Bundle>(`script/bundle/${renderNoteId}`);-- const $scriptContainer = $("<div>");- $el.append($scriptContainer);-- $scriptContainer.append(bundle.html);-- // async so that scripts cannot block trilium execution- bundleService.executeBundle(bundle, note, $scriptContainer)- .catch(onError)- .then(result => {- // Render JSX- if (bundle.html === "") {- renderIfJsx(bundle, result, $el).catch(onError);- }- });- }+ try {+ for (const renderNoteId of renderNoteIds) {+ const bundle = await server.post<Bundle>(`script/bundle/${renderNoteId}`);++ const $scriptContainer = $("<div>");+ $el.append($scriptContainer);++ $scriptContainer.append(bundle.html);- return renderNoteIds.length > 0;+ // async so that scripts cannot block trilium execution+ bundleService.executeBundle(bundle, note, $scriptContainer)+ .catch(onError)+ .then(result => {+ // Render JSX+ if (bundle.html === "") {+ renderIfJsx(bundle, result, $el).catch(onError);+ }+ });+ }++ return renderNoteIds.length > 0;+ } catch (e) {+ if (typeof e === "string" && e.startsWith("{") && e.endsWith("}")) {+ onError?.(JSON.parse(e));+ } else {+ onError?.(e);+ }+ }}async function renderIfJsx(bundle: Bundle, result: unknown, $el: JQuery<HTMLElement>) {