refactor: remove redundant fallback and legacy handling on drawing load failure

This commit simplifies `loadDrawing` in `useDrawingSession.ts` by removing silent fallbacks that were fetching the drawing list and redirecting users or auto-creating drawings when loading a specific drawing failed. Instead, the error state is simply set, ensuring errors surface cleanly.
This commit is contained in:
ruinivist
2026-05-31 13:23:50 +00:00
parent fcfde9f862
commit 65ecc8bfa4
21 changed files with 26 additions and 26 deletions
+4 -4
View File
@@ -3,11 +3,11 @@
"type": "module", "type": "module",
"private": true, "private": true,
"scripts": { "scripts": {
"dev": "bun --hot src/dev-server.tsx", "dev": "bun --hot src/server/dev-server.tsx",
"build": "rm -rf dist && bun run build:client && bun run build:server && bun run build:mcp", "build": "rm -rf dist && bun run build:client && bun run build:server && bun run build:mcp",
"build:client": "bun build --target=browser --production --outdir ./dist/public ./src/index.html", "build:client": "bun build --target=browser --production --outdir ./dist/public ./src/client/index.html",
"build:server": "mkdir -p ./dist/server && bun build --target=bun --production --outfile ./dist/server/server.js ./src/server.tsx", "build:server": "mkdir -p ./dist/server && bun build --target=bun --production --outfile ./dist/server/server.js ./src/server/http-server.tsx",
"build:mcp": "mkdir -p ./dist/mcp && bun build --target=bun --production --outfile ./dist/mcp/mcp-server.js ./src/mcp-server.ts", "build:mcp": "mkdir -p ./dist/mcp && bun build --target=bun --production --outfile ./dist/mcp/mcp-server.js ./src/mcp/server.ts",
"start": "DATABASE_PATH=./data/excalidraw.sqlite bun ./dist/server/server.js", "start": "DATABASE_PATH=./data/excalidraw.sqlite bun ./dist/server/server.js",
"test": "bun test", "test": "bun test",
"typecheck": "tsc --noEmit" "typecheck": "tsc --noEmit"
+4 -4
View File
@@ -1,8 +1,8 @@
import { useCallback, useEffect, useRef, useState } from "react"; import { useCallback, useEffect, useRef, useState } from "react";
import { DrawingSidebar, DrawingsToggle } from "./DrawingSidebar"; import { DrawingSidebar, DrawingsToggle } from "./components/DrawingSidebar";
import { EditorCanvas } from "./EditorCanvas"; import { EditorCanvas } from "./components/EditorCanvas";
import { useDrawingSession } from "./useDrawingSession"; import { useDrawingSession } from "./hooks/useDrawingSession";
import { useThemeTokenSync } from "./useThemeTokenSync"; import { useThemeTokenSync } from "./hooks/useThemeTokenSync";
export function App() { export function App() {
const [isSidebarOpen, setIsSidebarOpen] = useState(false); const [isSidebarOpen, setIsSidebarOpen] = useState(false);
@@ -1,4 +1,4 @@
import { type DrawingMeta } from "./shared"; import { type DrawingMeta } from "../../core/shared";
type DrawingSidebarProps = { type DrawingSidebarProps = {
open: boolean; open: boolean;
@@ -1,11 +1,11 @@
import "../node_modules/@excalidraw/excalidraw/dist/prod/index.css"; import "../../../node_modules/@excalidraw/excalidraw/dist/prod/index.css";
import { Excalidraw } from "@excalidraw/excalidraw"; import { Excalidraw } from "@excalidraw/excalidraw";
import type { import type {
AppState, AppState,
BinaryFiles, BinaryFiles,
ExcalidrawInitialDataState, ExcalidrawInitialDataState,
} from "@excalidraw/excalidraw/types"; } from "@excalidraw/excalidraw/types";
import { type ScenePayload } from "./shared"; import { type ScenePayload } from "../../core/shared";
type EditorCanvasProps = { type EditorCanvasProps = {
activeId: string | null; activeId: string | null;
@@ -1,5 +1,5 @@
import { useCallback, useEffect, useRef, useState } from "react"; import { useCallback, useEffect, useRef, useState } from "react";
import { DEFAULT_TITLE, type DrawingMeta, type ScenePayload } from "./shared"; import { DEFAULT_TITLE, type DrawingMeta, type ScenePayload } from "../../core/shared";
type DrawingResponse = DrawingMeta & ScenePayload; type DrawingResponse = DrawingMeta & ScenePayload;
type ApiErrorBody = { ok: false; error?: string; drawing?: DrawingMeta }; type ApiErrorBody = { ok: false; error?: string; drawing?: DrawingMeta };
+1 -1
View File
@@ -6,7 +6,7 @@
<!-- to resolve the hs and css from root --> <!-- to resolve the hs and css from root -->
<base href="/" /> <base href="/" />
<title>excali-box</title> <title>excali-box</title>
<script type="module" src="./client.tsx"></script> <script type="module" src="./main.tsx"></script>
</head> </head>
<body> <body>
<div id="root"></div> <div id="root"></div>
View File
@@ -2,9 +2,9 @@ import { afterEach, describe, expect, test } from "bun:test";
import { mkdtempSync, rmSync } from "node:fs"; import { mkdtempSync, rmSync } from "node:fs";
import { tmpdir } from "node:os"; import { tmpdir } from "node:os";
import { join } from "node:path"; import { join } from "node:path";
import { createDrawingStore, type DrawingStore } from "./db"; import { type ScenePayload } from "../core/shared";
import { createMcpToolHandlers, resolvePublicBaseUrl } from "./mcp-server"; import { createDrawingStore, type DrawingStore } from "../server/db";
import { type ScenePayload } from "./shared"; import { createMcpToolHandlers, resolvePublicBaseUrl } from "./server";
const cleanup: Array<{ dir: string; store: DrawingStore }> = []; const cleanup: Array<{ dir: string; store: DrawingStore }> = [];
+3 -3
View File
@@ -1,9 +1,9 @@
import { applyPatch, type Operation } from "fast-json-patch"; import { applyPatch, type Operation } from "fast-json-patch";
import { createMcpHandler } from "mcp-handler"; import { createMcpHandler } from "mcp-handler";
import { z } from "zod"; import { z } from "zod";
import { createDrawingStore, type DrawingStore } from "./db"; import { normalizeScene, normalizeTitle } from "../core/scene";
import { normalizeScene, normalizeTitle } from "./scene"; import { type ScenePayload } from "../core/shared";
import { type ScenePayload } from "./shared"; import { createDrawingStore, type DrawingStore } from "../server/db";
const sceneSchema = z.object({ const sceneSchema = z.object({
elements: z.array(z.unknown()), elements: z.array(z.unknown()),
+2 -2
View File
@@ -1,6 +1,6 @@
import { type DrawingStore } from "./db"; import { type DrawingStore } from "./db";
import { type DrawingMeta } from "./shared"; import { type DrawingMeta } from "../core/shared";
import { HttpError, normalizeTitle, parseJsonBody, parseSceneText } from "./scene"; import { HttpError, normalizeTitle, parseJsonBody, parseSceneText } from "../core/scene";
type RouteRequest = Request & { type RouteRequest = Request & {
params?: Record<string, string>; params?: Record<string, string>;
+2 -2
View File
@@ -2,8 +2,8 @@ import { Database } from "bun:sqlite";
import { randomUUID } from "node:crypto"; import { randomUUID } from "node:crypto";
import { mkdirSync } from "node:fs"; import { mkdirSync } from "node:fs";
import { dirname } from "node:path"; import { dirname } from "node:path";
import { DEFAULT_TITLE, type DrawingMeta, type DrawingRecord, type ScenePayload } from "./shared"; import { DEFAULT_TITLE, type DrawingMeta, type DrawingRecord, type ScenePayload } from "../core/shared";
import { emptyScene, normalizeScene, normalizeTitle } from "./scene"; import { emptyScene, normalizeScene, normalizeTitle } from "../core/scene";
type DrawingRow = { type DrawingRow = {
id: string; id: string;
@@ -1,5 +1,5 @@
import index from "./index.html"; import index from "../client/index.html";
import { createServer } from "./server"; import { createServer } from "./http-server";
export function createDevServer() { export function createDevServer() {
const server = createServer(); const server = createServer();
@@ -3,7 +3,7 @@ import { mkdtempSync, rmSync } from "node:fs";
import { tmpdir } from "node:os"; import { tmpdir } from "node:os";
import { join } from "node:path"; import { join } from "node:path";
import { createDrawingStore, type DrawingStore } from "./db"; import { createDrawingStore, type DrawingStore } from "./db";
import { createServer } from "./server"; import { createServer } from "./http-server";
const cleanup: string[] = []; const cleanup: string[] = [];
const stores: DrawingStore[] = []; const stores: DrawingStore[] = [];