Skip to content

Build your personal knowledge base with Trilium Notes

chore(client/lightweight): basic CLS implementation

Elian Doran1beda05e6c28
diff --git a/apps/client/src/lightweight/cls_provider.ts b/apps/client/src/lightweight/cls_provider.ts
new file mode 100644
index 0000000000..20ff5dda9f
--- /dev/null
+++ b/apps/client/src/lightweight/cls_provider.ts
@@ -0,0 +1,33 @@
+import { ExecutionContext } from "@triliumnext/core";
+
+export default class BrowserExecutionContext implements ExecutionContext {
+ private store: Map<string, any> | null = null;
+
+ get<T = any>(key: string): T | undefined {
+ return this.store?.get(key);
+ }
+
+ set(key: string, value: any): void {
+ if (!this.store) {
+ throw new Error("ExecutionContext not initialized");
+ }
+ this.store.set(key, value);
+ }
+
+ reset(): void {
+ this.store = null;
+ }
+
+ init<T>(callback: () => T): T {
+ // Create a fresh context for this request
+ const prev = this.store;
+ this.store = new Map();
+
+ try {
+ return callback();
+ } finally {
+ // Always clean up
+ this.store = prev;
+ }
+ }
+}