From 076cda800839e1686ddf7b669d6e711b1694a8b6 Mon Sep 17 00:00:00 2001 From: Alice Gaudon Date: Tue, 11 May 2021 15:13:32 +0200 Subject: [PATCH] Fix localStore set to a function that fetches pre-executed backend calls --- assets/views/layouts/svelte_layout.html | 17 ++++++++--------- src/frontend/SvelteViewEngine.ts | 9 +++++++-- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/assets/views/layouts/svelte_layout.html b/assets/views/layouts/svelte_layout.html index cb58f1d..caf13b9 100644 --- a/assets/views/layouts/svelte_layout.html +++ b/assets/views/layouts/svelte_layout.html @@ -6,20 +6,19 @@ diff --git a/src/frontend/SvelteViewEngine.ts b/src/frontend/SvelteViewEngine.ts index 7114085..786701f 100644 --- a/src/frontend/SvelteViewEngine.ts +++ b/src/frontend/SvelteViewEngine.ts @@ -221,7 +221,7 @@ export default class SvelteViewEngine extends ViewEngine { logger.info(canonicalName + ' > ', 'Replacing backend calls'); // Skip replace if there is no swaf export - if (!code.match(/export[ \n]+let[ \n]+locals[ \n]*=[ \n]*{[ \n]*}/)) { + if (!code.match(/import[ \n]+\{[ \n]*locals[ \n]*\}[ \n]+from[ \n]+["'](\.\.\/)+ts\/stores\.js["']/)) { return { backendCalls: [], code: code, @@ -296,7 +296,12 @@ export default class SvelteViewEngine extends ViewEngine { // Load locals into locals store const localsModulePath = "../../build/ts/stores.js"; const localsModule = await import(localsModulePath); - localsModule.locals.set(ViewEngine.getGlobals()); + const locals = ViewEngine.getGlobals(); + localsModule.locals.set((key: string, args: string) => { + return locals[args ? + `'${key}', \`${args}\`` + : `'${key}'`]; + }); // Load module and render return requireFromString(svelteSsr.js.code, file + nanoid() + '.js').default.render();