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
This commit is contained in:
Hugh Nimmo-Smith 2024-11-23 08:55:03 +00:00 committed by GitHub
parent 9ce16b68e9
commit 5c18868aa4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 20 additions and 3 deletions

View File

@ -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);
});
});
});

View File

@ -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"),