@panomc/theme-core 1.0.0-dev.54 → 1.0.0-dev.56

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/bin/new.js CHANGED
@@ -288,11 +288,13 @@ export const { handle, handleError, handleFetch } = createThemeHooks({
288
288
  "src/hooks.client.js": `import {
289
289
  installRuntimeRegistry,
290
290
  createClientInit,
291
+ createClientHandleError,
291
292
  } from "$pano/kit/hooks-client.js";
292
293
 
293
294
  installRuntimeRegistry();
294
295
 
295
296
  export const init = createClientInit();
297
+ export const handleError = createClientHandleError();
296
298
  `,
297
299
 
298
300
  "src/styles/tokens.scss": `// Design tokens — imported FIRST by style.scss, so anything you set here
@@ -8,17 +8,17 @@
8
8
  // module map for the lifetime of the document (per HTML spec), so a single
9
9
  // transient 404/network error on any script chunk leaves the SSR'd page
10
10
  // permanently dead with no retry. Recover with ONE cache-busting reload;
11
- // hooks.client.js clears the flag once the app boots successfully.
11
+ // RootLayout calls markAppBooted() once the page really hydrated.
12
12
  (function () {
13
13
  var KEY = "pano:hydration-reload";
14
14
  var MODULE_ERROR =
15
15
  /(failed to fetch dynamically imported module|error loading dynamically imported module|importing a module script failed|failed to resolve module specifier|import map|pano-runtime|failed to load module script)/i;
16
16
  function recover(message) {
17
17
  // Only rescue pages whose boot never completed (dead SSR page with a
18
- // poisoned module map). After a successful boot (hooks.client init sets
19
- // the flag) a failing module import is a plugin's own runtime problem —
20
- // reloading would loop forever since init also re-arms the sessionStorage
21
- // guard on every successful boot.
18
+ // poisoned module map). After a successful boot (RootLayout's onMount sets
19
+ // the flag via markAppBooted) a failing module import is a plugin's own
20
+ // runtime problem — reloading would loop forever since markAppBooted also
21
+ // re-arms the sessionStorage guard on every successful boot.
22
22
  if (window.__PANO_APP_BOOTED__) return;
23
23
  if (!MODULE_ERROR.test(String(message || ""))) return;
24
24
  try {
package/bin/ui.js CHANGED
@@ -90,4 +90,4 @@ export function brandIntro() {
90
90
  }
91
91
 
92
92
  /** Docs entry point, referenced by help/new/eject next-steps. */
93
- export const DOCS_URL = "https://panocms.com/docs/theme/getting-started/";
93
+ export const DOCS_URL = "https://panomc.com/docs/theme/getting-started/";
package/lang/en-US.json CHANGED
@@ -443,8 +443,10 @@
443
443
  }
444
444
  },
445
445
  "page-errors": {
446
+ "title": "Error: {status}",
446
447
  "404": "The page is not found!",
447
448
  "404-description": "The page you're looking for doesn't exist or has been moved.",
449
+ "assets-failed": "Some of the page's files could not be loaded. Please refresh the page; if it keeps happening, contact support.",
448
450
  "need-help": "If you believe this is an error, please contact support."
449
451
  },
450
452
  "ticket-statuses": {
package/lang/ru.json CHANGED
@@ -443,8 +443,10 @@
443
443
  }
444
444
  },
445
445
  "page-errors": {
446
+ "title": "Ошибка: {status}",
446
447
  "404": "Страница не найдена!",
447
448
  "404-description": "Страница, которую вы ищете, не существует или была перенесена.",
449
+ "assets-failed": "Не удалось загрузить часть файлов страницы. Обновите страницу; если ошибка повторяется, обратитесь в поддержку.",
448
450
  "need-help": "Если вы считаете, что это ошибка, обратитесь в поддержку."
449
451
  },
450
452
  "ticket-statuses": {
package/lang/tr.json CHANGED
@@ -443,8 +443,10 @@
443
443
  }
444
444
  },
445
445
  "page-errors": {
446
+ "title": "Hata: {status}",
446
447
  "404": "Aradığınız sayfa bulunamadı!",
447
448
  "404-description": "Aradığınız sayfa mevcut değil veya taşınmış olabilir.",
449
+ "assets-failed": "Sayfanın bazı dosyaları yüklenemedi. Lütfen sayfayı yenileyin; devam ederse destek ile iletişime geçin.",
448
450
  "need-help": "Bunun bir hata olduğunu düşünüyorsanız, lütfen destek ile iletişime geçin."
449
451
  },
450
452
  "ticket-statuses": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@panomc/theme-core",
3
- "version": "1.0.0-dev.54",
3
+ "version": "1.0.0-dev.56",
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
  "license": "MIT",
@@ -101,20 +101,72 @@ export function installRuntimeRegistry() {
101
101
  g.__PANO_RT_RESOLVE__?.(g.__PANO_RUNTIME__);
102
102
  }
103
103
 
104
+ const HYDRATION_RELOAD_KEY = "pano:hydration-reload";
105
+
106
+ /**
107
+ * Tells the hydration watchdog in app.html that this document booted. Until this runs, a
108
+ * failed module fetch (a chunk 502'd behind a proxy/CDN, a stale hash after an update) makes
109
+ * the watchdog reload the page once with a cache-busting query; afterwards a failing import is
110
+ * a plugin's own runtime problem and must not reload.
111
+ *
112
+ * Call it once the root layout has hydrated WITHOUT an error page — not from the SvelteKit
113
+ * `init` hook. `init` runs before hydration, before the route chunks are even requested, so a
114
+ * flag set there disarmed the watchdog exactly when it was needed and left visitors on a dead
115
+ * error page.
116
+ */
117
+ export function markAppBooted() {
118
+ if (!browser) return;
119
+
120
+ globalThis.__PANO_APP_BOOTED__ = true;
121
+
122
+ try {
123
+ // Re-arm the one-shot reload guard for the NEXT document.
124
+ sessionStorage.removeItem(HYDRATION_RELOAD_KEY);
125
+ } catch {
126
+ /* sessionStorage unavailable (e.g. blocked); the watchdog degrades gracefully */
127
+ }
128
+ }
129
+
130
+ /** Matches every browser's wording for a script chunk that could not be fetched/parsed. */
131
+ const MODULE_LOAD_ERROR =
132
+ /(failed to fetch dynamically imported module|error loading dynamically imported module|importing a module script failed|failed to load module script|failed to resolve module specifier)/i;
133
+
134
+ /**
135
+ * Client-side error hook. SvelteKit's default only prints the error; this one also names the
136
+ * page and the status, flags chunk-load failures (the classic "SSR fine, hydration dead"
137
+ * symptom: a proxy/CDN served HTML or a 5xx for a JS module) and hands the error page a code
138
+ * so it can tell the visitor to refresh instead of "report this".
139
+ *
140
+ * A theme's src/hooks.client.js exports it as:
141
+ *
142
+ * export const handleError = createClientHandleError();
143
+ */
144
+ export function createClientHandleError() {
145
+ /** @type {import('@sveltejs/kit').HandleClientError} */
146
+ return function handleError({ error, event, status, message }) {
147
+ const text = String(error?.message ?? error ?? "");
148
+ const moduleLoadFailed = MODULE_LOAD_ERROR.test(text);
149
+ const where = `${event?.url?.pathname ?? location.pathname} (status ${status})`;
150
+
151
+ console.error(
152
+ moduleLoadFailed
153
+ ? `[pano] a script chunk failed to load on ${where}; the page cannot hydrate:`
154
+ : `[pano] client error on ${where}:`,
155
+ error,
156
+ );
157
+
158
+ return {
159
+ message: moduleLoadFailed ? "Page files could not be loaded" : message,
160
+ code: moduleLoadFailed ? "MODULE_LOAD_FAILED" : error?.code,
161
+ };
162
+ };
163
+ }
164
+
104
165
  export function createClientInit() {
105
166
  /** @type {import('@sveltejs/kit').ClientInit} */
106
167
  return async function init() {
107
- // Hydration succeeded far enough to run app code: disarm the watchdog for this
108
- // document (post-boot module failures must not reload), re-arm the one-shot
109
- // reload guard for the NEXT document, and drop the cache-busting marker.
110
- globalThis.__PANO_APP_BOOTED__ = true;
111
-
112
- try {
113
- sessionStorage.removeItem("pano:hydration-reload");
114
- } catch {
115
- /* sessionStorage unavailable (e.g. blocked); the watchdog degrades gracefully */
116
- }
117
-
168
+ // Only cosmetic cleanup belongs here: `init` runs before hydration, so it must NOT mark the
169
+ // app as booted — see markAppBooted(), called from RootLayout after a successful mount.
118
170
  try {
119
171
  const url = new URL(location.href);
120
172
  if (url.searchParams.has("pano-rl")) {
@@ -61,7 +61,14 @@
61
61
  const resolved = await Promise.all(
62
62
  list.map(async (h) => {
63
63
  if (typeof h === "function" && !h.prototype) {
64
- return await h();
64
+ try {
65
+ return await h();
66
+ } catch (e) {
67
+ // Keep the unresolved thunk so the markup's `typeof module !== 'function'` guard
68
+ // skips this hook instead of the whole effect rejecting.
69
+ console.error(`[Hook:${name}] Failed to load plugin module`, e);
70
+ return h;
71
+ }
65
72
  }
66
73
  return h;
67
74
  }),
@@ -3,16 +3,18 @@
3
3
  Controller: $pano/lib/pages/ErrorPage.svelte
4
4
  Props:
5
5
  data object|undefined — undefined when rendered as +error.svelte (no load runs); kept for the shared controller contract
6
- page object — SvelteKit's reactive page state ($app/state); page.status picks the 404 vs. internal-error message
6
+ page object — SvelteKit's reactive page state ($app/state); page.status drives the title; page.status / page.error.code pick the 404, chunk-load or internal-error message
7
7
  Override from a theme:
8
8
  theme.config.js → views: { ErrorView: () => import("./src/views/ErrorView.svelte") }
9
9
  -->
10
10
  <div class="vstack gap-3">
11
11
  <PageTitle
12
- title="Hata: 404"
12
+ title={$_("page-errors.title", { values: { status: page.status }, default: `Error: ${page.status}` })}
13
13
  subtitle={page.status === 404
14
14
  ? $_("page-errors.404-description")
15
- : $_("errors.INTERNAL_SERVER_ERROR")} />
15
+ : page.error?.code === "MODULE_LOAD_FAILED"
16
+ ? $_("page-errors.assets-failed")
17
+ : $_("errors.INTERNAL_SERVER_ERROR")} />
16
18
 
17
19
  <div class="text-center mb-3">
18
20
  <img src="/assets/img/404.png" alt="Error" width="256" height="auto" />
@@ -205,7 +205,17 @@ export function createHookEngine() {
205
205
  const raw = entry.component || entry;
206
206
  let module = raw;
207
207
  if (typeof raw === "function" && !raw.prototype) {
208
- module = await raw();
208
+ try {
209
+ module = await raw();
210
+ } catch (e) {
211
+ // One plugin's chunk failing to load (a 502 behind a proxy/CDN, a stale hash after
212
+ // an update) must cost that plugin its slot, not the whole page: a throw here
213
+ // propagates out of the page's universal load and SvelteKit renders a 500. Leave
214
+ // the entry unresolved so Hook.svelte skips it, and keep the result aligned with
215
+ // the hook list (hookProps is indexed by position).
216
+ console.error(`[Hook:${name}] Failed to load plugin module`, e);
217
+ return {};
218
+ }
209
219
  // Cache the resolved module back into the hooks store
210
220
  hooks.update((h) => {
211
221
  if (h[name]) {
@@ -1,5 +1,7 @@
1
1
  <script>
2
+ import { onMount } from "svelte";
2
3
  import { page } from "$app/stores";
4
+ import { markAppBooted } from "$pano/kit/hooks-client.js";
3
5
  import AppLayout from "$pano/lib/layouts/AppLayout.svelte";
4
6
  import MainLayout from "$pano/lib/layouts/MainLayout.svelte";
5
7
 
@@ -8,6 +10,15 @@
8
10
  $: isThemeSettings = $page.route.id?.includes("(theme-settings)");
9
11
  $: isResetLayout = $page.data.resetLayout;
10
12
  $: showMainLayout = !isThemeSettings && !isResetLayout;
13
+
14
+ onMount(() => {
15
+ // Arms the hydration watchdog's "booted" state only after the page really rendered. An
16
+ // error render (a route chunk that failed to load) keeps it unarmed so the watchdog can
17
+ // still issue its one recovery reload.
18
+ if (!$page.error) {
19
+ markAppBooted();
20
+ }
21
+ });
11
22
  </script>
12
23
 
13
24
  <AppLayout {data}>