feat: keep dev server alive during HMR updates

This commit is contained in:
2026-07-13 15:17:49 +05:30
parent cf4c3723c5
commit 577c38a965
62 changed files with 281 additions and 169 deletions
+7 -2
View File
@@ -36,6 +36,7 @@ export interface DevStyles {
/** A dev asset server also supports invalidating its caches in-process. */
export interface DevAssetServer extends AssetServer {
invalidateCss(): void;
updateSchemas(code: string): void;
}
function jsResponse(code: string): Response {
@@ -65,12 +66,17 @@ export function createDevAssetServer(
schemasJs?: string,
): DevAssetServer {
let cssCache: string | null = null;
let schemasCode = schemasJs ?? "window.__wireSchemas={};";
return {
invalidateCss() {
cssCache = null;
},
updateSchemas(code) {
schemasCode = code;
},
async serve(pathname: string): Promise<Response | null> {
if (pathname === "/__wrnexus/reactive.js") return jsResponse(getReactiveRuntime());
if (pathname === "/__wrnexus/nav.js") return jsResponse(getNavRuntime());
@@ -83,8 +89,7 @@ export function createDevAssetServer(
if (pathname.startsWith(UPLOADS_PREFIX)) {
return (await serveStoredFile(pathname)) ?? new Response("Not Found", { status: 404 });
}
if (pathname === "/__wrnexus/schemas.js")
return jsResponse(schemasJs ?? "window.__wireSchemas={};");
if (pathname === "/__wrnexus/schemas.js") return jsResponse(schemasCode);
if (pathname === "/__wrnexus/ui.css") {
return uiCss ? cssResponse(uiCss) : new Response("Not Found", { status: 404 });