From 5c18868aa46861519ebffead338b32f44ea09d85 Mon Sep 17 00:00:00 2001 From: Hugh Nimmo-Smith Date: Sat, 23 Nov 2024 08:55:03 +0000 Subject: [PATCH] The preload URL param shouldn't be used in SPA mode, so ignore it if not in widget (#2832) * Refactor URL parameters into table This is for readability and ahead of some possible changes * Whitespace * Lint * The preload URL param shouldn't be used in SPA mode, so ignore it --- src/UrlParams.test.ts | 16 +++++++++++++++- src/UrlParams.ts | 7 +++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/UrlParams.test.ts b/src/UrlParams.test.ts index 2bf12a6b..47428ac6 100644 --- a/src/UrlParams.test.ts +++ b/src/UrlParams.test.ts @@ -7,7 +7,7 @@ Please see LICENSE in the repository root for full details. import { describe, expect, it } from "vitest"; -import { getRoomIdentifierFromUrl } from "../src/UrlParams"; +import { getRoomIdentifierFromUrl, getUrlParams } from "../src/UrlParams"; const ROOM_NAME = "roomNameHere"; const ROOM_ID = "!d45f138fsd"; @@ -86,4 +86,18 @@ describe("UrlParams", () => { .roomAlias, ).toBeFalsy(); }); + + describe("preload", () => { + it("defaults to false", () => { + expect(getUrlParams().preload).toBe(false); + }); + + it("ignored in SPA mode", () => { + expect(getUrlParams("?preload=true").preload).toBe(false); + }); + + it("respected in widget mode", () => { + expect(getUrlParams("?preload=true&widgetId=12345").preload).toBe(true); + }); + }); }); diff --git a/src/UrlParams.ts b/src/UrlParams.ts index b4f6ca28..c87b79cc 100644 --- a/src/UrlParams.ts +++ b/src/UrlParams.ts @@ -211,8 +211,11 @@ export const getUrlParams = ( const fontScale = parseFloat(parser.getParam("fontScale") ?? ""); + const widgetId = parser.getParam("widgetId"); + const isWidget = !!widgetId; + return { - widgetId: parser.getParam("widgetId"), + widgetId, parentUrl: parser.getParam("parentUrl"), // NB. we don't validate roomId here as we do in getRoomIdentifierFromUrl: @@ -224,7 +227,7 @@ export const getUrlParams = ( confineToRoom: parser.getFlagParam("confineToRoom") || parser.getFlagParam("embed"), appPrompt: parser.getFlagParam("appPrompt", true), - preload: parser.getFlagParam("preload"), + preload: isWidget ? parser.getFlagParam("preload") : false, hideHeader: parser.getFlagParam("hideHeader"), showControls: parser.getFlagParam("showControls", true), hideScreensharing: parser.getFlagParam("hideScreensharing"),