From 07fb8c072d9b35b18682285078e689ae15cc2a7c Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Wed, 14 Aug 2024 18:59:02 +0300 Subject: [PATCH 01/10] server: Fix CSRF on mobile reload (closes #318) --- src/routes/index.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/routes/index.ts b/src/routes/index.ts index a9403ab26..7cc0a5014 100644 --- a/src/routes/index.ts +++ b/src/routes/index.ts @@ -23,6 +23,11 @@ function index(req: Request, res: Response) { const csrfToken = req.csrfToken(); log.info(`Generated CSRF token ${csrfToken} with secret ${res.getHeader('set-cookie')}`); + // We force the page to not be cached since on mobile the CSRF token can be + // broken when closing the browser and coming back in to the page. + // The page is restored from cache, but the API call fail. + res.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); + res.render(view, { csrfToken: csrfToken, themeCssUrl: getThemeCssUrl(options.theme), From c204b31cdad1cb8f7e75320d541f6cca06aa48c2 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Wed, 14 Aug 2024 19:15:07 +0300 Subject: [PATCH 02/10] client: Fix fancytree being broken on mobile --- integration-tests/tree.spec.ts | 18 ++++++++++++++++++ src/views/mobile.ejs | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 integration-tests/tree.spec.ts diff --git a/integration-tests/tree.spec.ts b/integration-tests/tree.spec.ts new file mode 100644 index 000000000..38482eeb0 --- /dev/null +++ b/integration-tests/tree.spec.ts @@ -0,0 +1,18 @@ +import test, { expect } from "@playwright/test"; + +test("Renders on desktop", async ({ page, context }) => { + await page.goto('http://localhost:8082'); + await expect(page.locator('.tree')).toContainText('Trilium Integration Test'); +}); + +test("Renders on mobile", async ({ page, context }) => { + await context.addCookies([ + { + url: "http://localhost:8082", + name: "trilium-device", + value: "mobile" + } + ]); + await page.goto('http://localhost:8082'); + await expect(page.locator('.tree')).toContainText('Trilium Integration Test'); +}); \ No newline at end of file diff --git a/src/views/mobile.ejs b/src/views/mobile.ejs index 218c17d98..dc8471eee 100644 --- a/src/views/mobile.ejs +++ b/src/views/mobile.ejs @@ -128,7 +128,7 @@ - + From 115c2576cf9c92648dfd889b30526153fbc0cbbe Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Wed, 14 Aug 2024 21:51:42 +0300 Subject: [PATCH 03/10] client: Fix duplicate items in language selection --- src/public/app/widgets/type_widgets/options/appearance/i18n.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/public/app/widgets/type_widgets/options/appearance/i18n.js b/src/public/app/widgets/type_widgets/options/appearance/i18n.js index 392e3e7a0..0c79ac94c 100644 --- a/src/public/app/widgets/type_widgets/options/appearance/i18n.js +++ b/src/public/app/widgets/type_widgets/options/appearance/i18n.js @@ -29,6 +29,8 @@ export default class LocalizationOptions extends OptionsWidget { async optionsLoaded(options) { const availableLocales = await server.get("options/locales"); + this.$localeSelect.empty(); + for (const locale of availableLocales) { this.$localeSelect.append($("