feat: keep dev server alive during HMR updates
This commit is contained in:
@@ -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 });
|
||||
|
||||
Reference in New Issue
Block a user