Compare commits

...
Author SHA1 Message Date
renovate[bot] cf98d39240 Update dependency mermaid to v12.4.1 (#56496)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2026-12-04 20:29:37 +02:00
renovate[bot] 218492b655 Update dependency globals to v17.15.0 (#56494)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2026-12-04 17:30:12 +00:00
ChrisandClaude Opus 5.5 f5b44ed025 Preload the config of the dashboard opened from the URL (#56217)
* Preload the config of the dashboard opened from the URL

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* Skip paths that cannot be a dashboard

media-browser is a built-in panel with a hyphen in its path, and
developer-tools is still read from the URL before the redirect to
/config/tools runs. Neither can be a dashboard, so neither preloads a
config that is bound to fail.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* Test that the dashboard uses its own preloaded config

The existing tests only cover which URL paths start a preload, so they
would still pass if the panel discarded every preload, used another
dashboard's config, or never refetched after a failed preload.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
2026-12-04 16:34:20 +01:00
7 changed files with 123 additions and 22 deletions

No files matched your search

+2 -2
View File
@@ -113,7 +113,7 @@
"marked-footnote": "1.4.0",
"marked-gfm-heading-id": "4.1.4",
"memoize-one": "7.0.0",
"mermaid": "12.4.0",
"mermaid": "12.4.1",
"nanoid": "6.0.2",
"node-vibrant": "4.0.4",
"object-hash": "3.0.0",
@@ -191,7 +191,7 @@
"fs-extra": "11.4.1",
"generate-license-file": "4.2.5",
"glob": "15.0.0",
"globals": "17.14.0",
"globals": "17.15.0",
"gulp": "5.0.1",
"gulp-json-transform": "0.5.0",
"gulp-rename": "2.1.0",
+10 -10
View File
@@ -419,8 +419,8 @@ importers:
specifier: 7.0.0
version: 7.0.0
mermaid:
specifier: 12.4.0
version: 12.4.0
specifier: 12.4.1
version: 12.4.1
nanoid:
specifier: 6.0.2
version: 6.0.2
@@ -648,8 +648,8 @@ importers:
specifier: 15.0.0
version: 15.0.0
globals:
specifier: 17.14.0
version: 17.14.0
specifier: 17.15.0
version: 17.15.0
gulp:
specifier: 5.0.1
version: 5.0.1
@@ -5747,8 +5747,8 @@ packages:
resolution: {integrity: sha512-5lsx1NUDHtSjfg0eHlmYvZKv8/nVqX4ckFbM+FrGcQ+04KWcWFo9P5MxPZYSzUvyzmdTbI7Eix8Q4IbELDqzKg==}
engines: {node: '>=0.10.0'}
[email protected]4.0:
resolution: {integrity: sha512-UtdkTVyAJePQv0J2M9Xe4L0ruNSDV314XiIJsADI2Zf40bcdAonE/D/OhAU8AT99oij9mhLByb+NvA3QWZYgCg==}
[email protected]5.0:
resolution: {integrity: sha512-OyBOdPnzu9B2lFpums9/4wcyNHx4haAxY2X5PgO9LqCvXJgKYMMr/1y4TU7om/vTy4eYqRsVes1ZTJEJYKap8Q==}
engines: {node: '>=18'}
[email protected]:
@@ -6607,8 +6607,8 @@ packages:
resolution: {integrity: sha512-8q7VEgMJW4J8tcfVPy8g09NcQwZdbwFEqhe/WZkoIzjn/3TGDwtOCYtXGxA3O8tPzpczCCDgv+P2P5y00ZJOOg==}
engines: {node: '>= 8'}
[email protected].0:
resolution: {integrity: sha512-j2gvsGUFeS/53WdYLl9H5G2YtMZX9G/PlCvV3E5Pf4j5XSnK19DwazU6wki7OTcKeYKed7+qujRDLhy8NV2zBg==}
[email protected].1:
resolution: {integrity: sha512-8uCLCSeow+N6CrNzAB54lbNFipC1DOPXZeOTeSlfvJaNUohg0A9eebmJNxs4Ik/OyEDqmF2thvyCzkwkmNnTtg==}
engines: {node: '>=22.12.0'}
[email protected]:
@@ -14181,7 +14181,7 @@ snapshots:
is-windows: 1.0.2
which: 1.3.1
[email protected]4.0: {}
[email protected]5.0: {}
[email protected]:
dependencies:
@@ -15065,7 +15065,7 @@ snapshots:
[email protected]: {}
[email protected].0:
[email protected].1:
dependencies:
'@braintree/sanitize-url': 7.1.2
'@iconify/utils': 3.1.7
+16
View File
@@ -4,6 +4,22 @@ import type { RecorderInfo } from "./recorder";
export interface WindowWithPreloads extends Window {
llConfProm?: Promise<LovelaceRawConfig>;
llConfUrlPath?: string;
llResProm?: Promise<LovelaceResource[]>;
recorderInfoProm?: Promise<RecorderInfo>;
}
const HYPHENATED_NON_DASHBOARD_PATHS = ["developer-tools", "media-browser"];
export const getPreloadDashboardUrlPath = (
pathname: string
): string | undefined => {
const urlPath = pathname.split("/")[1];
if (urlPath === "lovelace") {
return urlPath;
}
return urlPath?.includes("-") &&
!HYPHENATED_NON_DASHBOARD_PATHS.includes(urlPath)
? urlPath
: undefined;
};
+9 -4
View File
@@ -14,7 +14,10 @@ import { isExternal } from "../data/external";
import { fetchConfig } from "../data/lovelace/config/types";
import { fetchResources } from "../data/lovelace/resource";
import { MAIN_WINDOW_NAME } from "../data/main_window";
import type { WindowWithPreloads } from "../data/preloads";
import {
getPreloadDashboardUrlPath,
type WindowWithPreloads,
} from "../data/preloads";
import { getRecorderInfo } from "../data/recorder";
import { subscribeRepairsIssueRegistry } from "../data/repairs";
import { subscribeAreaRegistry } from "../data/ws-area_registry";
@@ -193,9 +196,11 @@ window.hassConnection.then(({ conn }) => {
preloadWindow.recorderInfoProm = getRecorderInfo(conn);
// "/" opens the default panel, which is not known yet, so only preload the
// config when the "lovelace" dashboard is opened directly.
if (location.pathname.startsWith("/lovelace/")) {
preloadWindow.llConfProm = fetchConfig(conn, "lovelace", false);
// config when a dashboard is opened directly.
const dashboardUrlPath = getPreloadDashboardUrlPath(location.pathname);
if (dashboardUrlPath) {
preloadWindow.llConfUrlPath = dashboardUrlPath;
preloadWindow.llConfProm = fetchConfig(conn, dashboardUrlPath, false);
preloadWindow.llConfProm.catch(() => {
// Ignore it, it is handled by Lovelace panel.
});
+5 -6
View File
@@ -315,7 +315,9 @@ export class LovelacePanel extends LitElement {
// On first load, we speed up loading page by having LL promise ready
if (preloadWindow.llConfProm) {
confProm = preloadWindow.llConfProm;
if (preloadWindow.llConfUrlPath === this.urlPath) {
confProm = preloadWindow.llConfProm;
}
preloadWindow.llConfProm = undefined;
}
if (!resourcesLoaded) {
@@ -333,12 +335,9 @@ export class LovelacePanel extends LitElement {
const fetchDashboardConfig = () =>
fetchConfig(this.hass!.connection, this.urlPath, forceDiskRefresh);
// The preload is the config of the "lovelace" dashboard. Fetch it again if
// The preload is the config of the dashboard in the URL. Fetch it again if
// it failed, for example because the connection dropped before it came back.
confProm =
confProm && this.urlPath === "lovelace"
? confProm.catch(fetchDashboardConfig)
: fetchDashboardConfig();
confProm = confProm?.catch(fetchDashboardConfig) ?? fetchDashboardConfig();
try {
rawConf = await confProm;
+34
View File
@@ -0,0 +1,34 @@
import { describe, expect, it } from "vitest";
import { getPreloadDashboardUrlPath } from "../../src/data/preloads";
describe("getPreloadDashboardUrlPath", () => {
it("returns the lovelace dashboard", () => {
expect(getPreloadDashboardUrlPath("/lovelace")).toBe("lovelace");
expect(getPreloadDashboardUrlPath("/lovelace/0")).toBe("lovelace");
});
it("returns a dashboard with a hyphen in its url path", () => {
expect(getPreloadDashboardUrlPath("/dashboard-test")).toBe(
"dashboard-test"
);
expect(getPreloadDashboardUrlPath("/dashboard-test/kitchen")).toBe(
"dashboard-test"
);
});
it("returns nothing when the default panel is opened", () => {
expect(getPreloadDashboardUrlPath("/")).toBeUndefined();
});
it("returns nothing for panels that cannot be a dashboard", () => {
expect(getPreloadDashboardUrlPath("/home")).toBeUndefined();
expect(getPreloadDashboardUrlPath("/config/dashboard")).toBeUndefined();
expect(getPreloadDashboardUrlPath("/lovelaces")).toBeUndefined();
expect(
getPreloadDashboardUrlPath("/media-browser/browser")
).toBeUndefined();
expect(
getPreloadDashboardUrlPath("/developer-tools/state")
).toBeUndefined();
});
});
@@ -1,6 +1,8 @@
import { afterEach, describe, expect, it, vi } from "vitest";
import { subscribeLovelaceUpdates } from "../../../src/data/lovelace";
import type { LovelaceRawConfig } from "../../../src/data/lovelace/config/types";
import { fetchConfig } from "../../../src/data/lovelace/config/types";
import type { WindowWithPreloads } from "../../../src/data/preloads";
import "../../../src/panels/lovelace/ha-panel-lovelace";
type LovelacePanel = HTMLElement & {
@@ -63,9 +65,54 @@ const openPanel = async (urlPath: string) => {
return { panel, unsub, notifyUpdated: () => notifyUpdated() };
};
const preloadWindow = window as WindowWithPreloads;
const preloadConfig = (
urlPath: string,
confProm: Promise<LovelaceRawConfig>
) => {
confProm.catch(() => undefined);
preloadWindow.llConfUrlPath = urlPath;
preloadWindow.llConfProm = confProm;
};
afterEach(() => {
document.body.replaceChildren();
vi.clearAllMocks();
delete preloadWindow.llConfProm;
delete preloadWindow.llConfUrlPath;
});
describe("ha-panel-lovelace config preload", () => {
it("uses the preloaded config of its own dashboard", async () => {
preloadConfig("dashboard-test", Promise.resolve({ views: [] }));
await openPanel("dashboard-test");
expect(fetchConfig).not.toHaveBeenCalled();
expect(preloadWindow.llConfProm).toBeUndefined();
});
it("ignores the preloaded config of another dashboard", async () => {
preloadConfig("dashboard-other", Promise.resolve({ views: [] }));
await openPanel("dashboard-test");
expect(fetchConfig).toHaveBeenCalledTimes(1);
expect(fetchConfig).toHaveBeenCalledWith(
expect.anything(),
"dashboard-test",
false
);
expect(preloadWindow.llConfProm).toBeUndefined();
});
it("fetches the config again when its preload failed", async () => {
preloadConfig("dashboard-test", Promise.reject(new Error("closed")));
await openPanel("dashboard-test");
expect(fetchConfig).toHaveBeenCalledTimes(1);
expect(fetchConfig).toHaveBeenCalledWith(
expect.anything(),
"dashboard-test",
false
);
});
});
describe("ha-panel-lovelace config updates", () => {