@panomc/theme-core 1.3.0-dev.5 → 1.3.0-dev.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@panomc/theme-core",
3
- "version": "1.3.0-dev.5",
3
+ "version": "1.3.0-dev.6",
4
4
  "description": "The Pano theme engine: hooks factories, plugin engine, headless page controllers, default views and the theme CLI. Themes depend on this package instead of forking vanilla-theme.",
5
5
  "author": "PanoMC",
6
6
  "pano": {
@@ -61,7 +61,7 @@
61
61
  "@fortawesome/fontawesome-free": "^6.7.2"
62
62
  },
63
63
  "peerDependencies": {
64
- "@panomc/sdk": "^2.0.0-dev.5",
64
+ "@panomc/sdk": "^2.0.0-dev.6",
65
65
  "@sveltejs/adapter-node": "^6.0.0",
66
66
  "@sveltejs/kit": "^3.1.0",
67
67
  "@sveltejs/vite-plugin-svelte": "^7.3.1",
@@ -71,7 +71,7 @@
71
71
  "vite": "^8.3.4"
72
72
  },
73
73
  "devDependencies": {
74
- "@panomc/sdk": "2.0.0-dev.5",
74
+ "@panomc/sdk": "2.0.0-dev.6",
75
75
  "@sveltejs/adapter-node": "^6.0.0",
76
76
  "@sveltejs/kit": "^3.1.0",
77
77
  "@sveltejs/vite-plugin-svelte": "^7.3.1",
@@ -386,12 +386,12 @@ export function createViteConfig(opts = {}) {
386
386
  // recreates plugins/<id>/client and server under a running dev server, the watchers on
387
387
  // the old directories start firing endless "rename" events, and every vite process
388
388
  // rescans the tree at ~2 CPU cores until it is restarted.
389
- // agent-guide/ (docs for coding agents, never imported) has the same problem: the
390
- // theme-core sync script replaces the whole folder with rmSync + cpSync.
389
+ // docs/ (the PanoMC/docs submodule: rules for coding agents, never imported) is not
390
+ // part of the app either; a docs build inside it would recreate .vitepress/dist.
391
391
  // build/ (the adapter output) and .svelte-kit/output (the build's intermediate output)
392
392
  // too: `vite build` empties and recreates them next to a running dev server, with the
393
393
  // same endless "rename" storm (seen 2026-11-17).
394
- ignored: ["plugins", "agent-guide", "build", ".svelte-kit/output"].map(
394
+ ignored: ["plugins", "docs", "build", ".svelte-kit/output"].map(
395
395
  (dir) => path.resolve(process.cwd(), dir).replace(/\\/g, "/") + "/**",
396
396
  ),
397
397
  },
@@ -7,6 +7,7 @@ import { Window } from "happy-dom";
7
7
  const win = new Window({ url: "https://site.test/theme-settings" });
8
8
  const saved = {};
9
9
  const posted = [];
10
+ const links = [];
10
11
 
11
12
  mock.module("svelte", () => ({ onMount: (fn) => fn(), onDestroy: () => {} }));
12
13
  mock.module("@sveltejs/kit", () => ({ redirect: () => new Error("redirect") }));
@@ -22,6 +23,16 @@ beforeAll(async () => {
22
23
  globalThis.ResizeObserver = class { observe() {} disconnect() {} };
23
24
  globalThis.MessageEvent = win.MessageEvent;
24
25
  win.parent.postMessage = (data, target) => posted.push({ data, target });
26
+ // Links are recorded, not loaded: the tests fire load / error themselves.
27
+ const realAppend = win.document.head.appendChild.bind(win.document.head);
28
+ win.document.head.appendChild = (el) => {
29
+ if (el.tagName === "LINK") {
30
+ el.remove = () => links.splice(links.indexOf(el), 1);
31
+ links.push(el);
32
+ return el;
33
+ }
34
+ return realAppend(el);
35
+ };
25
36
  logic = await import("../ui-logics/layout-logics/ThemeSettingsLayoutLogics.js");
26
37
  logic.init();
27
38
  });
@@ -59,7 +70,41 @@ describe("theme-settings iframe messages", () => {
59
70
 
60
71
  test("only same-origin stylesheet links are injected", () => {
61
72
  send({ type: "inject-css-all", css: "", links: ["https://evil.test/x.css", "/panel/_app/a.css", "javascript:alert(1)"] });
62
- const hrefs = [...win.document.querySelectorAll('link[data-panel-injected="true"]')].map((l) => l.getAttribute("href"));
73
+ const hrefs = links.map((l) => l.getAttribute("href"));
63
74
  expect(hrefs).toEqual(["/panel/_app/a.css"]);
64
75
  });
65
76
  });
77
+
78
+ describe("theme-settings stylesheet loading", () => {
79
+ const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
80
+ const injected = () => links;
81
+
82
+ test("a stylesheet that fails twice reports an error, never ready", async () => {
83
+ links.length = 0;
84
+ posted.length = 0;
85
+ send({ type: "inject-css-all", css: "", links: ["/panel/_app/broken.css"] });
86
+ injected()[0].onerror();
87
+ await sleep(1100);
88
+ expect(injected().length).toBe(1);
89
+ injected()[0].onerror();
90
+ await sleep(200);
91
+ const types = posted.map((p) => p.data.type);
92
+ expect(types).toContain("theme-settings-error");
93
+ expect(types).not.toContain("theme-settings-ready");
94
+ });
95
+
96
+ test("ready is posted once every stylesheet loaded, also after one retry", async () => {
97
+ links.length = 0;
98
+ posted.length = 0;
99
+ send({ type: "inject-css-all", css: "", links: ["/panel/_app/a.css", "/panel/_app/b.css"] });
100
+ const [a] = injected();
101
+ a.onerror();
102
+ injected()[0].onload();
103
+ await sleep(1100);
104
+ injected().find((l) => l.getAttribute("href") === "/panel/_app/a.css").onload();
105
+ await sleep(200);
106
+ const types = posted.map((p) => p.data.type);
107
+ expect(types).toContain("theme-settings-ready");
108
+ expect(types).not.toContain("theme-settings-error");
109
+ });
110
+ });
@@ -25,6 +25,12 @@ function postReady() {
25
25
  window.parent.postMessage({ type: "theme-settings-ready" }, panelOrigin());
26
26
  }
27
27
 
28
+ // The panel's stylesheets could not be loaded: the panel shows its error with a retry button. A panel build that
29
+ // predates this message ignores it and runs into its own timeout.
30
+ function postError() {
31
+ window.parent.postMessage({ type: "theme-settings-error" }, panelOrigin());
32
+ }
33
+
28
34
  // The theme settings UI runs inside an iframe in the panel, so its toasts are posted to
29
35
  // the parent instead of rendered here. `variant` ('success' | 'danger') rides along so the
30
36
  // panel can colour the toast — without it the panel has no way to tell an outcome from a
@@ -163,37 +169,48 @@ export function init() {
163
169
  document.head.appendChild(style);
164
170
  }
165
171
 
166
- // 2. Inject CSS Links
167
- if (links && Array.isArray(links) && links.length > 0) {
168
- let loadedCount = 0;
169
- const totalLinks = links.length;
170
-
171
- links.forEach((href) => {
172
+ // 2. Inject CSS Links. The theme's own styles are gone now, so the page is shown only when every panel
173
+ // stylesheet loaded. A link that fails is tried once more; if it fails again the panel is told, and it shows
174
+ // its error instead of an unstyled page.
175
+ if (links.length > 0) {
176
+ let pending = links.length;
177
+ let failed = false;
178
+
179
+ const onComplete = (ok) => {
180
+ if (!ok) failed = true;
181
+ pending--;
182
+ if (pending > 0) return;
183
+ if (failed) {
184
+ postError();
185
+ return;
186
+ }
187
+ hidden.set(false);
188
+ setTimeout(() => {
189
+ postHeight();
190
+ postReady();
191
+ }, 150);
192
+ };
193
+
194
+ const addLink = (href, retried = false) => {
172
195
  const link = document.createElement("link");
173
196
  link.rel = "stylesheet";
174
197
  link.href = href;
175
198
  link.setAttribute("data-panel-injected", "true");
176
-
177
- const onComplete = () => {
178
- loadedCount++;
179
- if (loadedCount === totalLinks) {
180
- console.log("All CSS links loaded successfully");
181
- hidden.set(false);
182
- setTimeout(() => {
183
- postHeight();
184
- postReady();
185
- }, 150);
186
- }
187
- };
188
-
189
- link.onload = onComplete;
199
+ link.onload = () => onComplete(true);
190
200
  link.onerror = () => {
201
+ link.remove();
202
+ if (!retried) {
203
+ console.warn("Failed to load CSS link, retrying:", href);
204
+ setTimeout(() => addLink(href, true), 1000);
205
+ return;
206
+ }
191
207
  console.warn("Failed to load CSS link:", href);
192
- onComplete();
208
+ onComplete(false);
193
209
  };
194
-
195
210
  document.head.appendChild(link);
196
- });
211
+ };
212
+
213
+ links.forEach((href) => addLink(href));
197
214
  } else {
198
215
  // No links to load, ready now
199
216
  hidden.set(false);