fix: codeframe not visible with custom _500.tsx (#1869)
This commit is contained in:
+15
-2
@@ -281,8 +281,21 @@ export async function getServerContext(opts: InternalFreshOptions) {
|
|||||||
url,
|
url,
|
||||||
name,
|
name,
|
||||||
component,
|
component,
|
||||||
handler: handler ??
|
handler: (req, ctx) => {
|
||||||
((req, ctx) => router.defaultErrorHandler(req, ctx, ctx.error)),
|
if (opts.dev) {
|
||||||
|
const prevComp = error.component;
|
||||||
|
error.component = DefaultErrorHandler;
|
||||||
|
try {
|
||||||
|
return ctx.render();
|
||||||
|
} finally {
|
||||||
|
error.component = prevComp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return handler
|
||||||
|
? handler(req, ctx)
|
||||||
|
: router.defaultErrorHandler(req, ctx, ctx.error);
|
||||||
|
},
|
||||||
csp: Boolean(config?.csp ?? false),
|
csp: Boolean(config?.csp ?? false),
|
||||||
appWrapper: !config?.skipAppWrapper,
|
appWrapper: !config?.skipAppWrapper,
|
||||||
inheritLayouts: !config?.skipInheritedLayouts,
|
inheritLayouts: !config?.skipInheritedLayouts,
|
||||||
|
|||||||
@@ -149,3 +149,22 @@ Deno.test("shows custom 500 page for rendering errors when not in dev", async (t
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Deno.test("show codeframe in dev mode even with custom 500", async () => {
|
||||||
|
await withFakeServe(
|
||||||
|
"./tests/fixture_dev_codeframe/dev.ts",
|
||||||
|
async (server) => {
|
||||||
|
const doc = await server.getHtml(`/`);
|
||||||
|
assertSelector(doc, ".frsh-error-page");
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
await withFakeServe(
|
||||||
|
"./tests/fixture_dev_codeframe/main.ts",
|
||||||
|
async (server) => {
|
||||||
|
const doc = await server.getHtml(`/`);
|
||||||
|
assertNotSelector(doc, ".frsh-error-page");
|
||||||
|
assertSelector(doc, "h1");
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
import { dev } from "$fresh/src/dev/dev_command.ts";
|
||||||
|
import config from "./fresh.config.ts";
|
||||||
|
|
||||||
|
await dev(import.meta.url, "./main.ts", config);
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
import { defineConfig } from "$fresh/server.ts";
|
||||||
|
import twind from "$fresh/plugins/twind.ts";
|
||||||
|
|
||||||
|
export default defineConfig({
|
||||||
|
plugins: [twind({
|
||||||
|
selfURL: import.meta.url,
|
||||||
|
})],
|
||||||
|
});
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
// DO NOT EDIT. This file is generated by Fresh.
|
||||||
|
// This file SHOULD be checked into source version control.
|
||||||
|
// This file is automatically updated during development when running `dev.ts`.
|
||||||
|
|
||||||
|
import * as $0 from "./routes/_500.tsx";
|
||||||
|
import * as $1 from "./routes/index.tsx";
|
||||||
|
|
||||||
|
const manifest = {
|
||||||
|
routes: {
|
||||||
|
"./routes/_500.tsx": $0,
|
||||||
|
"./routes/index.tsx": $1,
|
||||||
|
},
|
||||||
|
islands: {},
|
||||||
|
baseUrl: import.meta.url,
|
||||||
|
};
|
||||||
|
|
||||||
|
export default manifest;
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
/// <reference no-default-lib="true" />
|
||||||
|
/// <reference lib="dom" />
|
||||||
|
/// <reference lib="dom.iterable" />
|
||||||
|
/// <reference lib="dom.asynciterable" />
|
||||||
|
/// <reference lib="deno.ns" />
|
||||||
|
|
||||||
|
import { start } from "$fresh/server.ts";
|
||||||
|
import manifest from "./fresh.gen.ts";
|
||||||
|
import config from "./fresh.config.ts";
|
||||||
|
|
||||||
|
await start(manifest, config);
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
export default function Error() {
|
||||||
|
return <h1>500 page</h1>;
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
// deno-lint-ignore no-explicit-any
|
||||||
|
export default function Page(): any {
|
||||||
|
throw new Error("fail");
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user