fix: codeframe not visible with custom _500.tsx (#1869)

This commit is contained in:
Marvin Hagemeister
2023-10-05 16:29:22 +02:00
committed by GitHub
parent a838a6c733
commit 4044b5be78
8 changed files with 81 additions and 2 deletions
+15 -2
View File
@@ -281,8 +281,21 @@ export async function getServerContext(opts: InternalFreshOptions) {
url,
name,
component,
handler: handler ??
((req, ctx) => router.defaultErrorHandler(req, ctx, ctx.error)),
handler: (req, ctx) => {
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),
appWrapper: !config?.skipAppWrapper,
inheritLayouts: !config?.skipInheritedLayouts,
+19
View File
@@ -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");
},
);
});
+4
View File
@@ -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,
})],
});
+17
View File
@@ -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;
+11
View File
@@ -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");
}