@lemonriver/core 1.0.0 → 1.0.2

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/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # @lemonriver/core
2
2
 
3
- ![LemonRiver — the agent-driven slide & deck platform](https://raw.githubusercontent.com/SegawaBeer/lemonriver/main/.github/assets/lemonriver-banner-en.png)
3
+ ![LemonRiver — the agent-driven slide & deck platform](https://raw.githubusercontent.com/SegawaBeer/lemonriver-slide/main/assets/lemonriver-banner-en.png)
4
4
 
5
- The runtime behind [LemonRiver](https://github.com/SegawaBeer/lemonriver) — the agent-driven slide & deck platform. Your own agent writes the deck; this package supplies everything around the slides themselves.
5
+ The runtime behind [LemonRiver](https://github.com/SegawaBeer/lemonriver-slide) — the agent-driven slide & deck platform. Your own agent writes the deck; this package supplies everything around the slides themselves.
6
6
 
7
7
  ## Install
8
8
 
@@ -1,5 +1,5 @@
1
1
  import { r as printHeader, t as createCliLogger } from "./cli/bin.js";
2
- import { t as createViteConfig } from "./config-BI3VRI2n.js";
2
+ import { t as createViteConfig } from "./config-DW1wSoxa.js";
3
3
  import path from "node:path";
4
4
  import { build as build$1, mergeConfig } from "vite";
5
5
  //#region src/cli/build.ts
package/dist/cli/bin.js CHANGED
@@ -449,17 +449,17 @@ async function run(argv) {
449
449
  program.command("dev").description("Start the dev server").addOption(new Option("-p, --port <port>", "port to listen on").argParser(parsePort)).addOption(new Option("--host [host]", "expose on the network (optional host)")).option("--open", "open the browser on start").option("--no-skills-check", "skip the built-in skills drift check").action(async (flags) => {
450
450
  if (flags.skillsCheck !== false) await runSkillsDriftCheck(resolveBuiltinSkillsDir());
451
451
  await assertViteResolvesToCore();
452
- const { dev } = await import("../dev-DpzBn_sf.js");
452
+ const { dev } = await import("../dev-_VDoRfAK.js");
453
453
  await dev(flags);
454
454
  });
455
455
  program.command("build").description("Build a static site").option("--out-dir <dir>", "output directory (defaults to `dist`)").action(async (flags) => {
456
456
  await assertViteResolvesToCore();
457
- const { build } = await import("../build-CiT4CNey.js");
457
+ const { build } = await import("../build-DYN-H65n.js");
458
458
  await build(flags);
459
459
  });
460
460
  program.command("preview").description("Preview the production build").addOption(new Option("-p, --port <port>", "port to listen on").argParser(parsePort)).addOption(new Option("--host [host]", "expose on the network (optional host)")).option("--open", "open the browser on start").action(async (flags) => {
461
461
  await assertViteResolvesToCore();
462
- const { preview } = await import("../preview-Dro8hl5_.js");
462
+ const { preview } = await import("../preview-CYIGh3Z8.js");
463
463
  await preview(flags);
464
464
  });
465
465
  program.command("mcp").description("Run the LemonRiver MCP server over stdio, for the agent working in this folder").action(async () => {
@@ -2953,7 +2953,7 @@ async function listBackups(dir, written) {
2953
2953
  * The how-to-restore page inside a backup zip. Same rules as the share guide:
2954
2954
  * standalone, no script, every string escaped.
2955
2955
  */
2956
- const RELEASES_URL = "https://github.com/SegawaBeer/lemonriver/releases";
2956
+ const RELEASES_URL = "https://github.com/SegawaBeer/lemonriver-slide/releases/latest";
2957
2957
  function restoreGuideFileName(locale) {
2958
2958
  if (locale === "zh-CN") return "怎么恢复.html";
2959
2959
  if (locale === "zh-TW") return "怎麼還原.html";
@@ -1,6 +1,6 @@
1
1
  import { V as PKG_NAMES } from "./update-b1dSg_FW.js";
2
2
  import { a as printUrls, c as startupDuration, i as printShortcutsHint, n as formatError, r as printHeader, s as shortcutsEnabled, t as createCliLogger } from "./cli/bin.js";
3
- import { n as DEV_SUPERVISED_ENV, t as createViteConfig } from "./config-BI3VRI2n.js";
3
+ import { n as DEV_SUPERVISED_ENV, t as createViteConfig } from "./config-DW1wSoxa.js";
4
4
  import path from "node:path";
5
5
  import { existsSync } from "node:fs";
6
6
  import { fork } from "node:child_process";
@@ -1,5 +1,5 @@
1
1
  import { a as printUrls, c as startupDuration, i as printShortcutsHint, r as printHeader, s as shortcutsEnabled, t as createCliLogger } from "./cli/bin.js";
2
- import { t as createViteConfig } from "./config-BI3VRI2n.js";
2
+ import { t as createViteConfig } from "./config-DW1wSoxa.js";
3
3
  import { mergeConfig, preview as preview$1 } from "vite";
4
4
  //#region src/cli/preview.ts
5
5
  async function preview(opts = {}) {
@@ -1,2 +1,2 @@
1
- import { t as createViteConfig } from "../config-BI3VRI2n.js";
1
+ import { t as createViteConfig } from "../config-DW1wSoxa.js";
2
2
  export { createViteConfig };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lemonriver/core",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "The LemonRiver runtime: deck viewer, story board, present mode, agent panel and export.",
5
5
  "type": "module",
6
6
  "exports": {
@@ -59,8 +59,9 @@
59
59
  "directory": "packages/core"
60
60
  },
61
61
  "bugs": {
62
- "url": "https://github.com/SegawaBeer/lemonriver/issues"
62
+ "url": "https://github.com/SegawaBeer/lemonriver-slide/issues"
63
63
  },
64
+ "homepage": "https://github.com/SegawaBeer/lemonriver-slide",
64
65
  "publishConfig": {
65
66
  "access": "public",
66
67
  "registry": "https://registry.npmjs.org/"
@@ -15,7 +15,7 @@ describe('the restore guide inside a backup', () => {
15
15
  expect(zh).toContain('LemonRiver 备份 · 2026-11-01 21:30');
16
16
  expect(zh).toContain('3 份演示 · 620 MB · 用 LemonRiver 0.8.0 备份');
17
17
  expect(zh).toContain('从备份恢复');
18
- expect(zh).toContain('https://github.com/SegawaBeer/lemonriver/releases');
18
+ expect(zh).toContain('https://github.com/SegawaBeer/lemonriver-slide/releases/latest');
19
19
  expect(zh).not.toContain('<script');
20
20
 
21
21
  const en = buildRestoreGuide({
@@ -13,7 +13,7 @@ export type RestoreGuideInput = {
13
13
  locale: GuideLocale;
14
14
  };
15
15
 
16
- const RELEASES_URL = 'https://github.com/SegawaBeer/lemonriver/releases';
16
+ const RELEASES_URL = 'https://github.com/SegawaBeer/lemonriver-slide/releases/latest';
17
17
 
18
18
  export function restoreGuideFileName(locale: GuideLocale): string {
19
19
  if (locale === 'zh-CN') return '怎么恢复.html';
@@ -38,11 +38,14 @@ export function Mascot({
38
38
  size,
39
39
  float = false,
40
40
  className,
41
+ src,
41
42
  }: {
42
43
  state: MascotState;
43
44
  size: number;
44
45
  float?: boolean;
45
46
  className?: string;
47
+ /** An already-loaded image, used when the file on disk may be gone. */
48
+ src?: string;
46
49
  }) {
47
50
  const first = useRef(true);
48
51
  const [bounce, setBounce] = useState(0);
@@ -59,7 +62,7 @@ export function Mascot({
59
62
  return (
60
63
  <img
61
64
  key={bounce}
62
- src={MASCOT_SRC[state]}
65
+ src={src ?? MASCOT_SRC[state]}
63
66
  alt=""
64
67
  aria-hidden
65
68
  draggable={false}
@@ -6,6 +6,7 @@ import { Mascot, type MascotState } from '../brand/mascot';
6
6
  export function LemonEmpty({
7
7
  state = 'idle',
8
8
  size = 140,
9
+ mascotSrc,
9
10
  title,
10
11
  children,
11
12
  actions,
@@ -14,6 +15,7 @@ export function LemonEmpty({
14
15
  }: {
15
16
  state?: MascotState;
16
17
  size?: number;
18
+ mascotSrc?: string;
17
19
  title: ReactNode;
18
20
  children?: ReactNode;
19
21
  actions?: ReactNode;
@@ -29,7 +31,7 @@ export function LemonEmpty({
29
31
  className,
30
32
  )}
31
33
  >
32
- <Mascot state={state} size={size} float={state === 'idle'} className="mb-2" />
34
+ <Mascot state={state} size={size} src={mascotSrc} float={state === 'idle'} className="mb-2" />
33
35
  <h2
34
36
  className={cn(
35
37
  'font-heading font-semibold text-foreground',
@@ -0,0 +1,32 @@
1
+ import { readdirSync, readFileSync, statSync } from 'node:fs';
2
+ import path from 'node:path';
3
+ import { fileURLToPath } from 'node:url';
4
+ import { describe, expect, it } from 'vitest';
5
+
6
+ const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../../../../..');
7
+
8
+ // The main repository is private now, so anything a user can open has to point
9
+ // at lemonriver-slide instead.
10
+ const PRIVATE_REPO = /(?:github\.com|raw\.githubusercontent\.com)\/SegawaBeer\/lemonriver\//;
11
+
12
+ function sourceFiles(dir: string): string[] {
13
+ return readdirSync(dir).flatMap((name) => {
14
+ const full = path.join(dir, name);
15
+ if (statSync(full).isDirectory()) return sourceFiles(full);
16
+ if (/\.test\.tsx?$/.test(name)) return [];
17
+ return /\.(?:ts|tsx|css|html|json)$/.test(name) ? [full] : [];
18
+ });
19
+ }
20
+
21
+ describe('public links', () => {
22
+ it('never point at the private repository', () => {
23
+ const files = [
24
+ ...sourceFiles(path.join(ROOT, 'packages/core/src')),
25
+ path.join(ROOT, 'packages/core/README.md'),
26
+ path.join(ROOT, 'packages/cli/README.md'),
27
+ ];
28
+ expect(files.length).toBeGreaterThan(0);
29
+ const offenders = files.filter((file) => PRIVATE_REPO.test(readFileSync(file, 'utf8')));
30
+ expect(offenders.map((file) => path.relative(ROOT, file))).toEqual([]);
31
+ });
32
+ });
@@ -1,4 +1,4 @@
1
- import type { ReactElement } from 'react';
1
+ import type { ReactElement, ReactNode } from 'react';
2
2
  import { describe, expect, it, vi } from 'vitest';
3
3
 
4
4
  vi.mock('./features', () => ({ isFeatureEnabled: vi.fn(() => true) }));
@@ -7,6 +7,9 @@ vi.mock('./home/home-page', () => ({ LemonRiverHome: () => null }));
7
7
  vi.mock('./help/help-page', () => ({ HelpPage: () => null }));
8
8
  vi.mock('./settings/settings-page', () => ({ SettingsPage: () => null }));
9
9
  vi.mock('./trash/trash-page', () => ({ TrashPage: () => null }));
10
+ vi.mock('./update/lazy-page', () => ({
11
+ LazyPage: ({ children }: { children: ReactNode }) => children,
12
+ }));
10
13
 
11
14
  import { isFeatureEnabled } from './features';
12
15
  import { lemonRiverRoutes, lemonRiverShellRoutes } from './routes';
@@ -1,4 +1,4 @@
1
- import { lazy, Suspense } from 'react';
1
+ import { lazy } from 'react';
2
2
  import { Route } from 'react-router-dom';
3
3
  import { NotFound } from './chrome/not-found';
4
4
  import { isFeatureEnabled } from './features';
@@ -6,6 +6,7 @@ import { HelpPage } from './help/help-page';
6
6
  import { LemonRiverHome } from './home/home-page';
7
7
  import { SettingsPage } from './settings/settings-page';
8
8
  import { TrashPage } from './trash/trash-page';
9
+ import { LazyPage } from './update/lazy-page';
9
10
 
10
11
  const BoardPage = lazy(() => import('./board/board-page').then((m) => ({ default: m.Board })));
11
12
  const DescribePage = lazy(() =>
@@ -29,9 +30,9 @@ export function lemonRiverRoutes() {
29
30
  key="board"
30
31
  path="/s/:slideId/board"
31
32
  element={
32
- <Suspense fallback={null}>
33
+ <LazyPage>
33
34
  <BoardPage />
34
- </Suspense>
35
+ </LazyPage>
35
36
  }
36
37
  />
37
38
  ),
@@ -40,9 +41,9 @@ export function lemonRiverRoutes() {
40
41
  key="outline"
41
42
  path="/s/:slideId/outline"
42
43
  element={
43
- <Suspense fallback={null}>
44
+ <LazyPage>
44
45
  <OutlinePage />
45
- </Suspense>
46
+ </LazyPage>
46
47
  }
47
48
  />
48
49
  ),
@@ -51,9 +52,9 @@ export function lemonRiverRoutes() {
51
52
  key="template-demo"
52
53
  path="/template-demo/:templateId"
53
54
  element={
54
- <Suspense fallback={null}>
55
+ <LazyPage>
55
56
  <TemplateDemoPage />
56
- </Suspense>
57
+ </LazyPage>
57
58
  }
58
59
  />
59
60
  ),
@@ -70,9 +71,9 @@ export function lemonRiverShellRoutes() {
70
71
  key="new"
71
72
  path="/new"
72
73
  element={
73
- <Suspense fallback={null}>
74
+ <LazyPage>
74
75
  <DescribePage />
75
- </Suspense>
76
+ </LazyPage>
76
77
  }
77
78
  />
78
79
  ),
@@ -85,9 +86,9 @@ export function lemonRiverShellRoutes() {
85
86
  key="templates"
86
87
  path="/templates"
87
88
  element={
88
- <Suspense fallback={null}>
89
+ <LazyPage>
89
90
  <TemplatesPage />
90
- </Suspense>
91
+ </LazyPage>
91
92
  }
92
93
  />
93
94
  ),
@@ -41,10 +41,10 @@ describe('buildGuideHtml', () => {
41
41
  for (const locale of ['zh-CN', 'zh-TW', 'en'] as const) {
42
42
  const html = buildGuideHtml({ ...base, title: 'Deck', locale });
43
43
  expect(html.toLowerCase()).not.toContain('<script');
44
- expect(html).toContain('https://github.com/SegawaBeer/lemonriver/releases');
44
+ expect(html).toContain('https://github.com/SegawaBeer/lemonriver-slide/releases/latest');
45
45
  const hrefs = [...html.matchAll(/href="([^"]+)"/g)].map((match) => match[1]);
46
46
  for (const href of hrefs) {
47
- expect(href).toBe('https://github.com/SegawaBeer/lemonriver/releases');
47
+ expect(href).toBe('https://github.com/SegawaBeer/lemonriver-slide/releases/latest');
48
48
  }
49
49
  expect(html).toContain('LemonRiver-0.6.0-arm64.dmg');
50
50
  }
@@ -15,7 +15,7 @@ export type GuideInput = {
15
15
  hasPdf?: boolean;
16
16
  };
17
17
 
18
- const RELEASES_URL = 'https://github.com/SegawaBeer/lemonriver/releases';
18
+ const RELEASES_URL = 'https://github.com/SegawaBeer/lemonriver-slide/releases/latest';
19
19
 
20
20
  export function guideLocaleFor(id: string): GuideLocale {
21
21
  if (id === 'zh-CN') return 'zh-CN';
@@ -362,7 +362,7 @@ export const enHelp: LrText['help'] = {
362
362
  kind: 'steps',
363
363
  items: [
364
364
  {
365
- text: 'On the new computer, install LemonRiver first (download: https://github.com/SegawaBeer/lemonriver/releases ), make sure the cloud drive client is installed and signed in, and the backup file is downloaded to this computer.',
365
+ text: 'On the new computer, install LemonRiver first (download: https://github.com/SegawaBeer/lemonriver-slide/releases/latest ), make sure the cloud drive client is installed and signed in, and the backup file is downloaded to this computer.',
366
366
  },
367
367
  {
368
368
  text: 'Open “{settings} → {backupSection}”, choose “{restore}”, pick one from the list, or choose “{chooseOtherFile}” to find it.',
@@ -1017,8 +1017,11 @@ export const en: LrText = {
1017
1017
  later: 'Later',
1018
1018
  updating: 'Updating…',
1019
1019
  updated: 'Updated to {version}',
1020
- updatedHint: 'Restart the local server to use it.',
1021
- updatedManual: 'Run the start command again to use it.',
1020
+ updatedHint:
1021
+ 'Restart the server now. Until you do, pages you have not opened yet may not open.',
1022
+ updatedManual:
1023
+ 'Run the start command again. Until you do, pages you have not opened yet may not open.',
1024
+ restartNeeded: 'LemonRiver has updated. Restart the server to open this page.',
1022
1025
  restart: 'Restart server',
1023
1026
  failed: "The update didn't go through",
1024
1027
  failedHint: 'The terminal running the start command has the details.',
@@ -365,8 +365,11 @@ export const es: LrText = {
365
365
  later: 'Más tarde',
366
366
  updating: 'Actualizando…',
367
367
  updated: 'Actualizado a {version}',
368
- updatedHint: 'Reinicia el servidor local para usarla.',
369
- updatedManual: 'Vuelve a ejecutar el comando de inicio para usarla.',
368
+ updatedHint:
369
+ 'Reinicia el servidor ahora. Hasta entonces, puede que las páginas que aún no has abierto no se abran.',
370
+ updatedManual:
371
+ 'Vuelve a ejecutar el comando de inicio. Hasta entonces, puede que las páginas que aún no has abierto no se abran.',
372
+ restartNeeded: 'LemonRiver se ha actualizado. Reinicia el servidor para abrir esta página.',
370
373
  restart: 'Reiniciar servidor',
371
374
  failed: 'La actualización no se completó',
372
375
  failedHint: 'La terminal donde corre el comando de inicio tiene los detalles.',
@@ -362,8 +362,11 @@ export const ja: LrText = {
362
362
  later: 'あとで',
363
363
  updating: '更新中…',
364
364
  updated: '{version} に更新しました',
365
- updatedHint: 'ローカルサーバーを再起動すると反映されます。',
366
- updatedManual: '起動コマンドをもう一度実行すると反映されます。',
365
+ updatedHint:
366
+ '今すぐサーバーを再起動してください。再起動するまで、まだ開いていないページが開けないことがあります。',
367
+ updatedManual:
368
+ '起動コマンドをもう一度実行してください。それまでは、まだ開いていないページが開けないことがあります。',
369
+ restartNeeded: 'LemonRiver を更新しました。このページを開くにはサーバーを再起動してください。',
367
370
  restart: 'サーバーを再起動',
368
371
  failed: '更新できませんでした',
369
372
  failedHint: '起動コマンドを実行しているターミナルに詳細が出ています。',
@@ -389,6 +389,7 @@ export type LrText = {
389
389
  updated: string;
390
390
  updatedHint: string;
391
391
  updatedManual: string;
392
+ restartNeeded: string;
392
393
  restart: string;
393
394
  failed: string;
394
395
  failedHint: string;
@@ -352,7 +352,7 @@ export const zhCN: LrText = {
352
352
  kind: 'steps',
353
353
  items: [
354
354
  {
355
- text: '新电脑先装好 LemonRiver(下载地址:https://github.com/SegawaBeer/lemonriver/releases ),确认云盘客户端也装好并登录了,备份文件已经下载到这台电脑。',
355
+ text: '新电脑先装好 LemonRiver(下载地址:https://github.com/SegawaBeer/lemonriver-slide/releases/latest ),确认云盘客户端也装好并登录了,备份文件已经下载到这台电脑。',
356
356
  },
357
357
  {
358
358
  text: '打开「{settings} → {backupSection}」,点「{restore}」,在列表里选一份,或者点「{chooseOtherFile}」找到它。',
@@ -972,8 +972,9 @@ export const zhCN: LrText = {
972
972
  later: '稍后',
973
973
  updating: '正在更新…',
974
974
  updated: '已更新到 {version}',
975
- updatedHint: '重启本机服务后生效。',
976
- updatedManual: '重新运行启动命令后生效。',
975
+ updatedHint: '现在重启服务。重启之前,还没打开过的页面可能打不开。',
976
+ updatedManual: '重新运行启动命令。在那之前,还没打开过的页面可能打不开。',
977
+ restartNeeded: 'LemonRiver 已更新,重启服务后才能打开这一页',
977
978
  restart: '重启服务',
978
979
  failed: '更新没成功',
979
980
  failedHint: '启动命令所在的终端里有报错详情。',
@@ -352,7 +352,7 @@ export const zhTW: LrText = {
352
352
  kind: 'steps',
353
353
  items: [
354
354
  {
355
- text: '新電腦先裝好 LemonRiver(下載網址:https://github.com/SegawaBeer/lemonriver/releases ),確認雲端硬碟用戶端也裝好並登入了,備份檔案已經下載到這台電腦。',
355
+ text: '新電腦先裝好 LemonRiver(下載網址:https://github.com/SegawaBeer/lemonriver-slide/releases/latest ),確認雲端硬碟用戶端也裝好並登入了,備份檔案已經下載到這台電腦。',
356
356
  },
357
357
  {
358
358
  text: '打開「{settings} → {backupSection}」,點「{restore}」,在清單裡選一份,或者點「{chooseOtherFile}」找到它。',
@@ -972,8 +972,9 @@ export const zhTW: LrText = {
972
972
  later: '稍後',
973
973
  updating: '正在更新…',
974
974
  updated: '已更新到 {version}',
975
- updatedHint: '重啟本機服務後生效。',
976
- updatedManual: '重新執行啟動指令後生效。',
975
+ updatedHint: '現在重啟服務。重啟之前,還沒打開過的頁面可能打不開。',
976
+ updatedManual: '重新執行啟動指令。在那之前,還沒打開過的頁面可能打不開。',
977
+ restartNeeded: 'LemonRiver 已更新,重啟服務後才能開啟這一頁',
977
978
  restart: '重啟服務',
978
979
  failed: '更新沒成功',
979
980
  failedHint: '啟動指令所在的終端機裡有錯誤詳情。',
@@ -0,0 +1,29 @@
1
+ import { Component, type ReactNode, Suspense } from 'react';
2
+ import { RestartNotice } from './restart-notice';
3
+ import { justUpdated, moduleFetchFailed } from './state';
4
+
5
+ /** A `lazy` route: while it loads nothing shows, and after an update a missing chunk gets a restart hint. */
6
+ export function LazyPage({ children }: { children: ReactNode }) {
7
+ return (
8
+ <Suspense fallback={null}>
9
+ <ModuleBoundary>{children}</ModuleBoundary>
10
+ </Suspense>
11
+ );
12
+ }
13
+
14
+ type BoundaryState = { error: Error | null };
15
+
16
+ class ModuleBoundary extends Component<{ children: ReactNode }, BoundaryState> {
17
+ state: BoundaryState = { error: null };
18
+
19
+ static getDerivedStateFromError(error: Error): BoundaryState {
20
+ return { error };
21
+ }
22
+
23
+ render() {
24
+ const { error } = this.state;
25
+ if (!error) return this.props.children;
26
+ if (!moduleFetchFailed(error) || !justUpdated()) throw error;
27
+ return <RestartNotice />;
28
+ }
29
+ }
@@ -0,0 +1,18 @@
1
+ const SIZE = 36;
2
+
3
+ /** Lemon at the size the toaster draws it, from an already-loaded copy. */
4
+ export function NoticeMascot({ src }: { src: string | null }) {
5
+ if (!src) return null;
6
+ return (
7
+ <img
8
+ src={src}
9
+ alt=""
10
+ aria-hidden
11
+ draggable={false}
12
+ width={SIZE}
13
+ height={SIZE}
14
+ className="lr-mascot shrink-0"
15
+ style={{ width: SIZE, height: SIZE }}
16
+ />
17
+ );
18
+ }
@@ -0,0 +1,47 @@
1
+ import { useEffect } from 'react';
2
+ import { toast } from 'sonner';
3
+ import { Button } from '@/components/ui/button';
4
+ import { format } from '@/lib/use-locale';
5
+ import { useRestartServer } from '@/lib/use-restart-server';
6
+ import { LemonEmpty } from '../feedback/lemon-empty';
7
+ import { useLrText } from '../text';
8
+ import { NoticeMascot } from './notice-mascot';
9
+ import { justUpdated, noticeIcons, UPDATE_TOAST_ID } from './state';
10
+
11
+ /** Shown instead of a blank page when the code for this route was deleted by the update. */
12
+ export function RestartNotice() {
13
+ const lr = useLrText();
14
+ const { canRestart, restarting, restartServer } = useRestartServer();
15
+ const version = justUpdated();
16
+
17
+ useEffect(() => {
18
+ if (!version) return;
19
+ const { done } = noticeIcons();
20
+ toast.success(format(lr.update.updated, { version }), {
21
+ id: UPDATE_TOAST_ID,
22
+ duration: Infinity,
23
+ description: canRestart ? lr.update.updatedHint : lr.update.updatedManual,
24
+ icon: done ? <NoticeMascot src={done} /> : undefined,
25
+ action: canRestart
26
+ ? { label: lr.update.restart, onClick: () => void restartServer() }
27
+ : undefined,
28
+ });
29
+ }, [canRestart, lr, restartServer, version]);
30
+
31
+ return (
32
+ <div className="grid min-h-dvh place-items-center bg-background px-6 text-foreground">
33
+ <LemonEmpty
34
+ state="needs-you"
35
+ mascotSrc={noticeIcons().needsYou ?? undefined}
36
+ title={lr.update.restartNeeded}
37
+ actions={
38
+ canRestart && (
39
+ <Button data-slot="button" disabled={restarting} onClick={() => void restartServer()}>
40
+ {lr.update.restart}
41
+ </Button>
42
+ )
43
+ }
44
+ />
45
+ </div>
46
+ );
47
+ }
@@ -0,0 +1,33 @@
1
+ export const UPDATE_TOAST_ID = 'lemonriver-update';
2
+
3
+ let updatedVersion: string | null = null;
4
+ let icons: { done: string | null; needsYou: string | null } = { done: null, needsYou: null };
5
+
6
+ export function markUpdated(version: string): void {
7
+ updatedVersion = version;
8
+ }
9
+
10
+ export function justUpdated(): string | null {
11
+ return updatedVersion;
12
+ }
13
+
14
+ export function rememberNoticeIcons(next: typeof icons): void {
15
+ icons = next;
16
+ }
17
+
18
+ export function noticeIcons(): typeof icons {
19
+ return icons;
20
+ }
21
+
22
+ // A dev-server update deletes the old files while the page still runs them, so
23
+ // the next page the user opens fails to fetch its chunk.
24
+ const MODULE_FETCH_ERRORS = [
25
+ 'Failed to fetch dynamically imported module',
26
+ 'error loading dynamically imported module',
27
+ 'Importing a module script failed',
28
+ ];
29
+
30
+ export function moduleFetchFailed(error: unknown): boolean {
31
+ const message = (error as Error | null)?.message ?? '';
32
+ return MODULE_FETCH_ERRORS.some((text) => message.includes(text));
33
+ }
@@ -3,7 +3,9 @@ import { useLocation } from 'react-router-dom';
3
3
  import { toast } from 'sonner';
4
4
  import { format } from '@/lib/use-locale';
5
5
  import { useRestartServer } from '@/lib/use-restart-server';
6
+ import { MASCOT_SRC } from '../brand/mascot';
6
7
  import { useLrText } from '../text';
8
+ import { NoticeMascot } from './notice-mascot';
7
9
  import {
8
10
  promptsOnPage,
9
11
  readSnooze,
@@ -12,8 +14,26 @@ import {
12
14
  UPDATE_CHECK_INTERVAL_MS,
13
15
  type UpdateCheck,
14
16
  } from './prompt';
17
+ import { markUpdated, rememberNoticeIcons, UPDATE_TOAST_ID } from './state';
15
18
 
16
- const TOAST_ID = 'lemonriver-update';
19
+ const TOAST_ID = UPDATE_TOAST_ID;
20
+
21
+ /** Reads a mascot while its file still exists, so the notice can still draw it after the update. */
22
+ async function preloadMascot(src: string): Promise<string | null> {
23
+ try {
24
+ const res = await fetch(src);
25
+ if (!res.ok) return null;
26
+ const blob = await res.blob();
27
+ return await new Promise<string>((resolve, reject) => {
28
+ const reader = new FileReader();
29
+ reader.onload = () => resolve(String(reader.result));
30
+ reader.onerror = () => reject(reader.error);
31
+ reader.readAsDataURL(blob);
32
+ });
33
+ } catch {
34
+ return null;
35
+ }
36
+ }
17
37
 
18
38
  export function UpdatePrompt() {
19
39
  const { pathname } = useLocation();
@@ -41,6 +61,12 @@ export function UpdatePrompt() {
41
61
  phase.current = 'busy';
42
62
  toast.loading(lr.update.updating, { id: TOAST_ID, duration: Infinity });
43
63
 
64
+ const icons = {
65
+ done: await preloadMascot(MASCOT_SRC.done),
66
+ needsYou: await preloadMascot(MASCOT_SRC['needs-you']),
67
+ };
68
+ rememberNoticeIcons(icons);
69
+
44
70
  let ok = false;
45
71
  try {
46
72
  const res = await fetch('/__update-package', { method: 'POST' });
@@ -56,6 +82,7 @@ export function UpdatePrompt() {
56
82
  id: TOAST_ID,
57
83
  duration: Infinity,
58
84
  description: lr.update.failedHint,
85
+ icon: icons.needsYou ? <NoticeMascot src={icons.needsYou} /> : undefined,
59
86
  action: { label: lr.update.retry, onClick: () => void runUpdate(latest) },
60
87
  cancel: { label: lr.update.later, onClick: () => snooze(latest) },
61
88
  });
@@ -64,10 +91,12 @@ export function UpdatePrompt() {
64
91
 
65
92
  phase.current = 'done';
66
93
  settled.current = latest;
94
+ markUpdated(latest);
67
95
  if (cancelled) return;
68
96
  toast.success(format(lr.update.updated, { version: latest }), {
69
97
  id: TOAST_ID,
70
98
  duration: Infinity,
99
+ icon: icons.done ? <NoticeMascot src={icons.done} /> : undefined,
71
100
  description: canRestart ? lr.update.updatedHint : lr.update.updatedManual,
72
101
  action: canRestart
73
102
  ? { label: lr.update.restart, onClick: () => void restartServer() }