mirror of
https://github.com/zadam/trilium.git
synced 2026-01-16 19:44:24 +01:00
fix(client/lightweight): CLS not available in routes
This commit is contained in:
parent
3371a31c70
commit
a84e804fc3
@ -3,6 +3,8 @@
|
||||
* Supports path parameters (e.g., /api/notes/:noteId) and query strings.
|
||||
*/
|
||||
|
||||
import { getContext } from "@triliumnext/core";
|
||||
|
||||
export interface BrowserRequest {
|
||||
method: string;
|
||||
url: string;
|
||||
@ -166,7 +168,7 @@ export class BrowserRouter {
|
||||
};
|
||||
|
||||
try {
|
||||
const result = await route.handler(request);
|
||||
const result = await getContext().init(async () => await route.handler(request));
|
||||
return this.formatResult(result);
|
||||
} catch (error) {
|
||||
return this.formatError(error);
|
||||
|
||||
@ -24,10 +24,23 @@ export default class BrowserExecutionContext implements ExecutionContext {
|
||||
this.store = new Map();
|
||||
|
||||
try {
|
||||
return callback();
|
||||
} finally {
|
||||
// Always clean up
|
||||
const result = callback();
|
||||
|
||||
// If the result is a Promise, we need to handle cleanup after it resolves
|
||||
if (result && typeof result === 'object' && 'then' in result && 'catch' in result) {
|
||||
const promise = result as unknown as Promise<any>;
|
||||
return promise.finally(() => {
|
||||
this.store = prev;
|
||||
}) as T;
|
||||
} else {
|
||||
// Synchronous result, clean up immediately
|
||||
this.store = prev;
|
||||
return result;
|
||||
}
|
||||
} catch (error) {
|
||||
// Always clean up on error (for synchronous errors)
|
||||
this.store = prev;
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user