From 9980c54fcf1ef8b5b5e0b529ef9aadbb8b6e855e Mon Sep 17 00:00:00 2001 From: Alice Gaudon Date: Wed, 24 Nov 2021 22:08:38 +0100 Subject: [PATCH] front/SvelteViewEngine: pre-compile ssr on demand, refactor globals into proper locals and lazy locals --- src/Application.ts | 4 + src/assets/views/auth/auth.svelte | 4 +- .../views/components/FlashMessages.svelte | 2 +- .../views/templates/ErrorTemplate.svelte | 2 +- .../views/templates/svelte_template.html | 8 +- src/assets/views/utils/CsrfTokenField.svelte | 2 +- src/assets/views/utils/Field.svelte | 4 +- src/components/CsrfProtectionComponent.ts | 27 +- src/components/FormHelperComponent.ts | 35 +-- src/components/FrontendToolsComponent.ts | 60 +---- src/components/MailComponent.ts | 22 +- src/components/PreviousUrlComponent.ts | 10 +- src/components/SessionComponent.ts | 50 +--- src/components/WebSocketServerComponent.ts | 13 +- .../core/AppLocalsCoreComponents.ts | 26 ++ .../core/LazyLocalsCoreComponent.ts | 30 +++ src/frontend/AssetPreCompiler.ts | 11 - src/frontend/Globals.ts | 11 - src/frontend/SvelteViewEngine.ts | 247 ++++-------------- src/frontend/ViewEngine.ts | 8 +- src/types/Express.d.ts | 4 + test/CsrfProtectionComponent.test.ts | 2 +- test/_authentication_common.ts | 2 +- 23 files changed, 175 insertions(+), 409 deletions(-) create mode 100644 src/components/core/AppLocalsCoreComponents.ts create mode 100644 src/components/core/LazyLocalsCoreComponent.ts delete mode 100644 src/frontend/Globals.ts diff --git a/src/Application.ts b/src/Application.ts index 3e96abe..b4aa287 100644 --- a/src/Application.ts +++ b/src/Application.ts @@ -21,6 +21,8 @@ import SecurityError from "./SecurityError.js"; import {doesFileExist, Type} from "./Utils.js"; import WebSocketListener from "./WebSocketListener.js"; import TemplateError = nunjucks.lib.TemplateError; +import AppLocalsCoreComponents from "./components/core/AppLocalsCoreComponents.js"; +import LazyLocalsCoreComponent from "./components/core/LazyLocalsCoreComponent.js"; export default abstract class Application implements Extendable> { private readonly version: string; @@ -98,6 +100,8 @@ export default abstract class Application implements Extendable