feat(debug): show rendering issues during SSR (#1256)
Co-authored-by: Asher Gomez <ashersaupingomez@gmail.com>
This commit is contained in:
co-authored by
Asher Gomez
parent
273aa2ac5c
commit
be08573a95
+14
-1
@@ -56,6 +56,11 @@ function isObject(value: unknown) {
|
|||||||
value !== null;
|
value !== null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isDevMode() {
|
||||||
|
// Env var is only set in prod (on Deploy).
|
||||||
|
return Deno.env.get("DENO_DEPLOYMENT_ID") === undefined;
|
||||||
|
}
|
||||||
|
|
||||||
interface StaticFile {
|
interface StaticFile {
|
||||||
/** The URL to the static file on disk. */
|
/** The URL to the static file on disk. */
|
||||||
localUrl: URL;
|
localUrl: URL;
|
||||||
@@ -94,6 +99,7 @@ export class ServerContext {
|
|||||||
plugins: Plugin[],
|
plugins: Plugin[],
|
||||||
configPath: string,
|
configPath: string,
|
||||||
jsxConfig: JSXConfig,
|
jsxConfig: JSXConfig,
|
||||||
|
dev: boolean = isDevMode(),
|
||||||
) {
|
) {
|
||||||
this.#routes = routes;
|
this.#routes = routes;
|
||||||
this.#islands = islands;
|
this.#islands = islands;
|
||||||
@@ -104,7 +110,7 @@ export class ServerContext {
|
|||||||
this.#notFound = notFound;
|
this.#notFound = notFound;
|
||||||
this.#error = error;
|
this.#error = error;
|
||||||
this.#plugins = plugins;
|
this.#plugins = plugins;
|
||||||
this.#dev = typeof Deno.env.get("DENO_DEPLOYMENT_ID") !== "string"; // Env var is only set in prod (on Deploy).
|
this.#dev = dev;
|
||||||
this.#builder = new EsbuildBuilder({
|
this.#builder = new EsbuildBuilder({
|
||||||
buildID: BUILD_ID,
|
buildID: BUILD_ID,
|
||||||
entrypoints: collectEntrypoints(this.#dev, this.#islands, this.#plugins),
|
entrypoints: collectEntrypoints(this.#dev, this.#islands, this.#plugins),
|
||||||
@@ -320,6 +326,12 @@ export class ServerContext {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const dev = isDevMode();
|
||||||
|
if (dev) {
|
||||||
|
// Ensure that debugging hooks are set up for SSR rendering
|
||||||
|
await import("preact/debug");
|
||||||
|
}
|
||||||
|
|
||||||
return new ServerContext(
|
return new ServerContext(
|
||||||
routes,
|
routes,
|
||||||
islands,
|
islands,
|
||||||
@@ -332,6 +344,7 @@ export class ServerContext {
|
|||||||
opts.plugins ?? [],
|
opts.plugins ?? [],
|
||||||
configPath,
|
configPath,
|
||||||
jsxConfig,
|
jsxConfig,
|
||||||
|
dev,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ export default function DefaultErrorPage(props: ErrorPageProps) {
|
|||||||
return h(
|
return h(
|
||||||
"div",
|
"div",
|
||||||
{
|
{
|
||||||
|
class: "frsh-error-page",
|
||||||
style: {
|
style: {
|
||||||
display: "flex",
|
display: "flex",
|
||||||
justifyContent: "center",
|
justifyContent: "center",
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
{
|
||||||
|
"lock": false,
|
||||||
|
"imports": {
|
||||||
|
"$fresh/": "../../",
|
||||||
|
"preact": "https://esm.sh/preact@10.15.1",
|
||||||
|
"preact/": "https://esm.sh/preact@10.15.1/",
|
||||||
|
"preact-render-to-string": "https://esm.sh/*preact-render-to-string@6.0.3"
|
||||||
|
},
|
||||||
|
"compilerOptions": {
|
||||||
|
"jsx": "react-jsx",
|
||||||
|
"jsxImportSource": "preact"
|
||||||
|
}
|
||||||
|
}
|
||||||
Executable
+5
@@ -0,0 +1,5 @@
|
|||||||
|
#!/usr/bin/env -S deno run -A --watch=static/,routes/
|
||||||
|
|
||||||
|
import dev from "$fresh/dev.ts";
|
||||||
|
|
||||||
|
await dev(import.meta.url, "./main.ts");
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
// 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/index.tsx";
|
||||||
|
|
||||||
|
const manifest = {
|
||||||
|
routes: {
|
||||||
|
"./routes/index.tsx": $0,
|
||||||
|
},
|
||||||
|
islands: {},
|
||||||
|
baseUrl: import.meta.url,
|
||||||
|
};
|
||||||
|
|
||||||
|
export default manifest;
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
/// <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";
|
||||||
|
|
||||||
|
await start(manifest);
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
export default function Home() {
|
||||||
|
return <h1>it should error {{ foo: 123 }}</h1>;
|
||||||
|
}
|
||||||
@@ -689,6 +689,44 @@ Deno.test("jsx pragma works", {
|
|||||||
serverProcess.kill("SIGTERM");
|
serverProcess.kill("SIGTERM");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Deno.test("preact/debug is active in dev mode", {
|
||||||
|
sanitizeOps: false,
|
||||||
|
sanitizeResources: false,
|
||||||
|
}, async (t) => {
|
||||||
|
// Preparation
|
||||||
|
const { serverProcess, lines } = await startFreshServer({
|
||||||
|
args: ["run", "-A", "./tests/fixture_render_error/main.ts"],
|
||||||
|
});
|
||||||
|
|
||||||
|
await delay(100);
|
||||||
|
const url = "http://localhost:8000";
|
||||||
|
|
||||||
|
await t.step("SSR error is shown", async () => {
|
||||||
|
const resp = await fetch(url);
|
||||||
|
assertEquals(resp.status, Status.InternalServerError);
|
||||||
|
const text = await resp.text();
|
||||||
|
assertStringIncludes(text, "Objects are not valid as a child");
|
||||||
|
});
|
||||||
|
|
||||||
|
const browser = await puppeteer.launch({ args: ["--no-sandbox"] });
|
||||||
|
const page = await browser.newPage();
|
||||||
|
|
||||||
|
await page.goto(url, {
|
||||||
|
waitUntil: "networkidle2",
|
||||||
|
});
|
||||||
|
|
||||||
|
await t.step("error page is shown with error message", async () => {
|
||||||
|
const el = await page.waitForSelector(".frsh-error-page");
|
||||||
|
const text = await page.evaluate((el) => el.textContent, el);
|
||||||
|
assertStringIncludes(text, "Objects are not valid as a child");
|
||||||
|
});
|
||||||
|
|
||||||
|
await browser.close();
|
||||||
|
|
||||||
|
await lines.cancel();
|
||||||
|
serverProcess.kill("SIGTERM");
|
||||||
|
});
|
||||||
|
|
||||||
Deno.test("preloading javascript files", {
|
Deno.test("preloading javascript files", {
|
||||||
sanitizeOps: false,
|
sanitizeOps: false,
|
||||||
sanitizeResources: false,
|
sanitizeResources: false,
|
||||||
|
|||||||
Reference in New Issue
Block a user