Skip to content

Port client to Vite #1956

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 47 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
016d59f
refactor(client/vite): first setup
eliandoran May 16, 2025
e23400b
fix(client/vite): build errors due to mark.js
eliandoran May 16, 2025
4d2ae6a
fix(client/vite): build errors due to top-level async
eliandoran May 16, 2025
6ccfa09
fix(client/vite): runtime error due to chunk name
eliandoran May 16, 2025
e28a64a
fix(client/vite): handle static assets
eliandoran May 16, 2025
d4dbe1c
fix(server): proxying of inner client modules
eliandoran May 16, 2025
1d67553
refactor(server): improve script URL rewriting
eliandoran May 16, 2025
ac79ae2
refactor(server): fix stylesheet paths
eliandoran May 16, 2025
ae2eb9f
refactor(server): fix script dir for libraries
eliandoran May 16, 2025
d3488ca
refactor(server): fix vite runtime not proxied
eliandoran May 16, 2025
390b384
refactor(server): remove unnecessary script
eliandoran May 16, 2025
a3a810c
Merge branch 'feature/db_session_store' into client_vite
eliandoran May 16, 2025
dd73517
fix(server): some assets not served properly
eliandoran May 16, 2025
83058e9
fix(server): some dist assets not served properly
eliandoran May 16, 2025
b678e4e
fix(server): package.json not accessible
eliandoran May 16, 2025
cb381d0
chore(server): remove URL logging to increase performance slightly
eliandoran May 16, 2025
278cdf6
feat(server): serve client directly instead of proxying
eliandoran May 16, 2025
90ee096
fix(client): integrate boxicons into client
eliandoran May 16, 2025
ac2e5fc
fix(client): integrate autocomplete into client
eliandoran May 16, 2025
875075e
fix(client): emoji definitions
eliandoran May 16, 2025
bfa4c09
fix(client): integrate highlight.js (partially)
eliandoran May 16, 2025
470ac18
feat(client): integrate normalize.css
eliandoran May 17, 2025
786233a
fix(share): script not loadable due to relative path
eliandoran May 17, 2025
f7471b5
fix(share): script not loadable due to ESM
eliandoran May 17, 2025
255e529
fix(share): content.css missing
eliandoran May 17, 2025
7b787ff
feat(client): integrate katex
eliandoran May 17, 2025
626e321
fix(math): proxying of fonts
eliandoran May 17, 2025
a4cfef7
fix(canvas): proxying of fonts
eliandoran May 17, 2025
3f2a0e3
refactor(client): integrate jquery-hotkeys
eliandoran May 17, 2025
23db7fe
chore(client): partial integrate jquery.fancytree
eliandoran May 17, 2025
4b22d05
refactor(server): remove leftover autocomplete in EJS
eliandoran May 17, 2025
67d0d0f
refactor(client): different method for loading jquery
eliandoran May 17, 2025
901ab54
fix(client): missing fancytree dependencies
eliandoran May 17, 2025
84d9198
refactor(client): tree CSS
eliandoran May 17, 2025
c1ae5b2
chore(client): suppress SCSS warnings
eliandoran May 17, 2025
c1648f9
chore(client): suppress module level directives warnings
eliandoran May 17, 2025
c0c79b1
fix(mobile): apply same fix about jquery
eliandoran May 17, 2025
932a371
chore(server): remove unnecessary CSS
eliandoran May 17, 2025
4153359
Merge remote-tracking branch 'origin/develop' into client_vite
eliandoran May 19, 2025
a5f0b3b
Merge remote-tracking branch 'origin/develop' into client_vite
eliandoran May 19, 2025
7702a87
fix(client/vite): highlight.js not playing well with ESM-native
eliandoran May 19, 2025
8a1f05c
refactor(client): remove library loader entirely
eliandoran May 19, 2025
cad6417
fix(client): loading app CSS no longer working
eliandoran May 19, 2025
c7a4c92
test(highlightjs): broken import
eliandoran May 19, 2025
7743f99
test(highlightjs): another broken import
eliandoran May 19, 2025
b242809
fix(highlightjs): broken imports for syntax highlighting
eliandoran May 19, 2025
6286c39
fix(highlightjs): languages incorrectly imported
eliandoran May 19, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"redhat.vscode-yaml",
"tobermory.es6-string-html",
"vitest.explorer",
"yzhang.markdown-all-in-one"
"yzhang.markdown-all-in-one",
"aaron-bond.better-comments"
]
}
10 changes: 8 additions & 2 deletions apps/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@
"@mind-elixir/node-menu": "1.0.5",
"@popperjs/core": "2.11.8",
"@triliumnext/ckeditor5": "workspace:*",
"@triliumnext/commons": "workspace:*",
"@triliumnext/codemirror": "workspace:*",
"@triliumnext/commons": "workspace:*",
"autocomplete.js": "0.38.1",
"bootstrap": "5.3.6",
"boxicons": "2.1.4",
"dayjs": "1.11.13",
"dayjs-plugin-utc": "0.1.2",
"debounce": "2.2.0",
Expand All @@ -37,13 +39,15 @@
"jquery-hotkeys": "0.2.2",
"jquery.fancytree": "2.38.5",
"jsplumb": "2.15.6",
"katex": "0.16.22",
"knockout": "3.5.1",
"leaflet": "1.9.4",
"leaflet-gpx": "2.2.0",
"mark.js": "8.11.1",
"marked": "15.0.11",
"mermaid": "11.6.0",
"mind-elixir": "4.5.2",
"normalize.css": "8.0.1",
"panzoom": "9.4.3",
"react": "19.1.0",
"react-dom": "19.1.0",
Expand All @@ -57,11 +61,13 @@
"@types/jquery": "3.5.32",
"@types/leaflet": "1.9.17",
"@types/leaflet-gpx": "1.3.7",
"@types/mark.js": "8.11.12",
"@types/react": "19.1.4",
"@types/react-dom": "19.1.5",
"copy-webpack-plugin": "13.0.0",
"happy-dom": "17.4.7",
"script-loader": "0.7.2"
"script-loader": "0.7.2",
"vite-plugin-static-copy": "3.0.0"
},
"nx": {
"name": "client"
Expand Down
3 changes: 3 additions & 0 deletions apps/client/src/desktop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import options from "./services/options.js";
import type ElectronRemote from "@electron/remote";
import type Electron from "electron";
import "./stylesheets/bootstrap.scss";
import "boxicons";
import "jquery-hotkeys";
import "autocomplete.js/index_jquery.js";

await appContext.earlyInit();

Expand Down
2 changes: 2 additions & 0 deletions apps/client/src/mobile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import appContext from "./components/app_context.js";
import noteAutocompleteService from "./services/note_autocomplete.js";
import glob from "./services/glob.js";
import "./stylesheets/bootstrap.scss";
import "boxicons";
import "autocomplete.js/index_jquery.js";

glob.setupGlobs();

Expand Down
5 changes: 5 additions & 0 deletions apps/client/src/runtime.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import $ from "jquery";
(window as any).$ = $;
(window as any).jQuery = $;

$("body").show();
4 changes: 1 addition & 3 deletions apps/client/src/services/content_renderer.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import renderService from "./render.js";
import protectedSessionService from "./protected_session.js";
import protectedSessionHolder from "./protected_session_holder.js";
import libraryLoader from "./library_loader.js";
import openService from "./open.js";
import froca from "./froca.js";
import utils from "./utils.js";
Expand All @@ -15,6 +14,7 @@ import { loadElkIfNeeded, postprocessMermaidSvg } from "./mermaid.js";
import renderDoc from "./doc_renderer.js";
import { t } from "../services/i18n.js";
import WheelZoom from 'vanilla-js-wheel-zoom';
import { renderMathInElement } from "./math.js";
import { normalizeMimeTypeForCKEditor } from "@triliumnext/commons";

let idCounter = 1;
Expand Down Expand Up @@ -94,8 +94,6 @@ async function renderText(note: FNote | FAttachment, $renderedContent: JQuery<HT
$renderedContent.append($('<div class="ck-content">').html(blob.content));

if ($renderedContent.find("span.math-tex").length > 0) {
await libraryLoader.requireLibrary(libraryLoader.KATEX);

renderMathInElement($renderedContent[0], { trust: true });
}

Expand Down
16 changes: 13 additions & 3 deletions apps/client/src/services/glob.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import utils from "./utils.js";
import appContext from "../components/app_context.js";
import server from "./server.js";
import libraryLoader from "./library_loader.js";
import ws from "./ws.js";
import froca from "./froca.js";
import linkService from "./link.js";
Expand All @@ -17,7 +16,6 @@ function setupGlobs() {

// required for ESLint plugin and CKEditor
window.glob.getActiveContextNote = () => appContext.tabManager.getActiveContextNote();
window.glob.requireLibrary = libraryLoader.requireLibrary;
window.glob.appContext = appContext; // for debugging
window.glob.froca = froca;
window.glob.treeCache = froca; // compatibility for CKEditor builds for a while
Expand Down Expand Up @@ -64,7 +62,7 @@ function setupGlobs() {
});

for (const appCssNoteId of glob.appCssNoteIds || []) {
libraryLoader.requireCss(`api/notes/download/${appCssNoteId}`, false);
requireCss(`api/notes/download/${appCssNoteId}`, false);
}

utils.initHelpButtons($(window));
Expand All @@ -76,6 +74,18 @@ function setupGlobs() {
});
}

async function requireCss(url: string, prependAssetPath = true) {
const cssLinks = Array.from(document.querySelectorAll("link")).map((el) => el.href);

if (!cssLinks.some((l) => l.endsWith(url))) {
if (prependAssetPath) {
url = `${window.glob.assetPath}/${url}`;
}

$("head").append($('<link rel="stylesheet" type="text/css" />').attr("href", url));
}
}

export default {
setupGlobs
};
68 changes: 0 additions & 68 deletions apps/client/src/services/library_loader.ts

This file was deleted.

5 changes: 5 additions & 0 deletions apps/client/src/services/math.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import katex from "katex";
import "katex/contrib/mhchem";
import "katex/dist/katex.min.css";
export { default as renderMathInElement } from "katex/contrib/auto-render";
export default katex;
2 changes: 2 additions & 0 deletions apps/client/src/setup.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import "jquery";
import "jquery-hotkeys";
import utils from "./services/utils.js";
import ko from "knockout";
import "./stylesheets/bootstrap.scss";
Expand Down
2 changes: 2 additions & 0 deletions apps/client/src/share.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import "./stylesheets/bootstrap.scss";
import "normalize.css";
import "@triliumnext/ckeditor5/content.css";

/**
* Fetch note with given ID from backend
Expand Down
4 changes: 1 addition & 3 deletions apps/client/src/types-assets.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ declare module "*.png" {
export default path;
}

declare module "*.json?external" {
declare module "@triliumnext/ckeditor5/emoji_definitions/en.json?url" {
var path: string;
export default path;
}

declare module "script-loader!mark.js/dist/jquery.mark.min.js";
7 changes: 7 additions & 0 deletions apps/client/src/types-lib.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,10 @@ declare module "draggabilly" {
declare module "@mind-elixir/node-menu" {
export default mindmap;
}

declare module "katex/contrib/auto-render" {
var renderMathInElement: (element: HTMLElement, options: {
trust: boolean;
}) => void;
export default renderMathInElement;
}
12 changes: 0 additions & 12 deletions apps/client/src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ interface CustomGlobals {
getReferenceLinkTitle: (href: string) => Promise<string>;
getReferenceLinkTitleSync: (href: string) => string;
getActiveContextNote: () => FNote | null;
requireLibrary: typeof library_loader.requireLibrary;
ESLINT: Library;
appContext: AppContext;
froca: Froca;
Expand Down Expand Up @@ -123,17 +122,6 @@ declare global {
var require: RequireMethod;
var __non_webpack_require__: RequireMethod | undefined;

// Libraries
var renderMathInElement: (element: HTMLElement, options: {
trust: boolean;
}) => void;

var katex: {
renderToString(text: string, opts: {
throwOnError: boolean
});
}

/*
* Panzoom
*/
Expand Down
4 changes: 1 addition & 3 deletions apps/client/src/widgets/dialogs/revisions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import utils from "../../services/utils.js";
import server from "../../services/server.js";
import toastService from "../../services/toast.js";
import appContext from "../../components/app_context.js";
import libraryLoader from "../../services/library_loader.js";
import openService from "../../services/open.js";
import protectedSessionHolder from "../../services/protected_session_holder.js";
import BasicWidget from "../basic_widget.js";
Expand All @@ -12,6 +11,7 @@ import options from "../../services/options.js";
import type FNote from "../../entities/fnote.js";
import type { NoteType } from "../../entities/fnote.js";
import { Dropdown, Modal } from "bootstrap";
import { renderMathInElement } from "../../services/math.js";

const TPL = /*html*/`
<div class="revisions-dialog modal fade mx-auto" tabindex="-1" role="dialog">
Expand Down Expand Up @@ -315,8 +315,6 @@ export default class RevisionsDialog extends BasicWidget {
this.$content.html(`<div class="ck-content">${fullRevision.content}</div>`);

if (this.$content.find("span.math-tex").length > 0) {
await libraryLoader.requireLibrary(libraryLoader.KATEX);

renderMathInElement(this.$content[0], { trust: true });
}
} else if (revisionItem.type === "code") {
Expand Down
4 changes: 2 additions & 2 deletions apps/client/src/widgets/find_in_html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default class FindInHtml {
}

async performFind(searchTerm: string, matchCase: boolean, wholeWord: boolean) {
await import("script-loader!mark.js/dist/jquery.mark.min.js");
await import("mark.js");

const $content = await this.parent?.noteContext?.getContentElement();

Expand All @@ -42,7 +42,7 @@ export default class FindInHtml {
const containerTop = scrollingContainer?.getBoundingClientRect().top ?? 0;
const closestIndex = this.$results.toArray().findIndex(el => el.getBoundingClientRect().top >= containerTop);
this.currentIndex = closestIndex >= 0 ? closestIndex : 0;

await this.jumpTo();

res({
Expand Down
3 changes: 1 addition & 2 deletions apps/client/src/widgets/highlights_list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import RightPanelWidget from "./right_panel_widget.js";
import options from "../services/options.js";
import OnClickButtonWidget from "./buttons/onclick_button.js";
import appContext, { type EventData } from "../components/app_context.js";
import libraryLoader from "../services/library_loader.js";
import type FNote from "../entities/fnote.js";
import katex from "../services/math.js";

const TPL = /*html*/`<div class="highlights-list-widget">
<style>
Expand Down Expand Up @@ -175,7 +175,6 @@ export default class HighlightsListWidget extends RightPanelWidget {
} catch (e) {
if (e instanceof ReferenceError && e.message.includes("katex is not defined")) {
// Load KaTeX if it is not already loaded
await libraryLoader.requireLibrary(libraryLoader.KATEX);
try {
rendered = katex.renderToString(latexCode, {
throwOnError: false
Expand Down
5 changes: 5 additions & 0 deletions apps/client/src/widgets/note_tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ import type { AttributeRow, BranchRow } from "../services/load_results.js";
import type { SetNoteOpts } from "../components/note_context.js";
import type { TouchBarItem } from "../components/touch_bar.js";
import type { TreeCommandNames } from "../menus/tree_context_menu.js";
import "jquery.fancytree";
import "jquery.fancytree/dist/modules/jquery.fancytree.dnd5.js";
import "jquery.fancytree/dist/modules/jquery.fancytree.clones.js";
import "jquery.fancytree/dist/modules/jquery.fancytree.filter.js";
import "../stylesheets/tree.css";

const TPL = /*html*/`
<div class="tree-wrapper">
Expand Down
Loading
Loading