diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 5abf8bae..c6d1c749 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -59,5 +59,10 @@ jobs:
- name: Type check project
run: deno task check:types
- - name: Run tests
+ - name: Run tests Windows
+ if: matrix.os == 'windows-latest'
+ run: deno test -A
+
+ - name: Run tests macOS + Linux
+ if: matrix.os != 'windows-latest'
run: deno test -A --parallel
diff --git a/.vscode/import_map.json b/.vscode/import_map.json
index 65af7d53..92598ca9 100644
--- a/.vscode/import_map.json
+++ b/.vscode/import_map.json
@@ -8,7 +8,7 @@
"twind/": "https://esm.sh/twind@0.16.19/",
"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.2.0",
+ "preact-render-to-string": "https://esm.sh/*preact-render-to-string@6.2.1",
"@preact/signals": "https://esm.sh/*@preact/signals@1.1.3",
"@preact/signals-core": "https://esm.sh/@preact/signals-core@1.2.3",
"@preact/signals-core@1.2.3": "https://esm.sh/@preact/signals-core@1.2.3",
diff --git a/demo/deno.json b/demo/deno.json
index 4cd7f216..8e5d0fb4 100644
--- a/demo/deno.json
+++ b/demo/deno.json
@@ -7,7 +7,7 @@
"$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.2.0",
+ "preact-render-to-string": "https://esm.sh/*preact-render-to-string@6.2.1",
"@preact/signals": "https://esm.sh/*@preact/signals@1.1.3",
"@preact/signals-core": "https://esm.sh/@preact/signals-core@1.2.3"
},
diff --git a/init.ts b/init.ts
index fb0fdad7..beeb3399 100644
--- a/init.ts
+++ b/init.ts
@@ -137,35 +137,29 @@ CMD ["run", "-A", "main.ts"]
);
}
-const ROUTES_INDEX_TSX = `import { Head } from "$fresh/runtime.ts";
-import { useSignal } from "@preact/signals";
+const ROUTES_INDEX_TSX = `import { useSignal } from "@preact/signals";
import Counter from "../islands/Counter.tsx";
export default function Home() {
const count = useSignal(3);
return (
- <>
-
- ${basename(resolvedDirectory)}
-
-
-
-

-
Welcome to Fresh
-
- Try updating this message in the
- ./routes/index.tsx file, and refresh.
-
-
-
+
+
+

+
Welcome to Fresh
+
+ Try updating this message in the
+ ./routes/index.tsx file, and refresh.
+
+
- >
+
);
}
`;
@@ -436,23 +430,34 @@ const APP_WRAPPER = useTwind
export default function App({ Component }: AppProps) {
return (
- <>
-
- >
+
+
+
+
+
${basename(resolvedDirectory)}
+
+
+
+
+
);
}
`
: `import { AppProps } from "$fresh/server.ts";
-import { Head } from "$fresh/runtime.ts";
export default function App({ Component }: AppProps) {
return (
- <>
-
+
+
+
+
+
${basename(resolvedDirectory)}
-
-
- >
+
+
+
+
+
);
}
`;
diff --git a/src/dev/imports.ts b/src/dev/imports.ts
index 43be1047..54e47f8b 100644
--- a/src/dev/imports.ts
+++ b/src/dev/imports.ts
@@ -1,5 +1,5 @@
export const RECOMMENDED_PREACT_VERSION = "10.15.1";
-export const RECOMMENDED_PREACT_RTS_VERSION = "6.2.0";
+export const RECOMMENDED_PREACT_RTS_VERSION = "6.2.1";
export const RECOMMENDED_PREACT_SIGNALS_VERSION = "1.1.3";
export const RECOMMENDED_PREACT_SIGNALS_CORE_VERSION = "1.2.3";
export const RECOMMENDED_TWIND_VERSION = "0.16.19";
diff --git a/src/server/render.ts b/src/server/render.ts
index 08425570..cfd68703 100644
--- a/src/server/render.ts
+++ b/src/server/render.ts
@@ -45,12 +45,36 @@ export interface AdvancedPreactOptions extends PreactOptions {
/** Attach a hook that is invoked before a vnode has rendered. */
__r?(vnode: VNode): void;
errorBoundaries?: boolean;
+ /** before diff hook */
+ __b?(vnode: VNode): void;
}
const options = preactOptions as AdvancedPreactOptions;
// Enable error boundaries in Preact.
options.errorBoundaries = true;
+// These values keep track of whether the user rendered the ,
+// and element. Basically, the outer document. We
+// keep track of this, because we only know the full sets of
+// elements we should put in `` after having completed
+// rendering the page.
+let RENDERING_USER_TEMPLATE = false;
+interface OuterDocument {
+ // deno-lint-ignore no-explicit-any
+ title: VNode
| null;
+ html: Record | null;
+ head: Record | null;
+ body: Record | null;
+ headNodes: { type: string; props: Record }[];
+}
+let OUTER_DOCUMENT: OuterDocument = {
+ title: null,
+ html: null,
+ head: null,
+ body: null,
+ headNodes: [],
+};
+
export interface RenderOptions {
request: Request;
// deno-lint-ignore no-explicit-any
@@ -209,6 +233,17 @@ export async function render(
// Clear previous slots
SLOTS_TRACKER.clear();
+ // Clear rendering state
+ RENDERING_USER_TEMPLATE = false;
+ headChildren = false;
+ OUTER_DOCUMENT = {
+ title: null,
+ body: null,
+ head: null,
+ html: null,
+ headNodes: [],
+ };
+
const ctx = new RenderContext(
crypto.randomUUID(),
opts.url,
@@ -432,7 +467,19 @@ export async function render(
};
}
+ RENDERING_USER_TEMPLATE = true;
await renderAsync();
+ RENDERING_USER_TEMPLATE = false;
+
+ const idx = headComponents.findIndex((vnode) =>
+ vnode !== null && typeof vnode === "object" && "type" in vnode &&
+ props !== null && vnode.type === "title"
+ );
+ if (idx !== -1) {
+ OUTER_DOCUMENT.title = headComponents[idx] as VNode<{ children: string }>;
+ headComponents.splice(idx, 1);
+ }
+
if (asyncRenderResponse !== undefined) {
return asyncRenderResponse;
}
@@ -563,48 +610,37 @@ export async function render(
}
const preloads = [...preloadSet];
- const html = template({
- bodyHtml,
- headComponents,
- moduleScripts,
- preloads,
- lang: ctx.lang,
- });
- return [html, csp];
-}
-
-export interface TemplateOptions {
- bodyHtml: string;
- headComponents: ComponentChildren[];
- moduleScripts: (readonly [string, string])[];
- preloads: string[];
- lang: string;
-}
-
-export function template(opts: TemplateOptions): string {
const page = h(
"html",
- { lang: opts.lang },
+ OUTER_DOCUMENT.html ?? { lang: ctx.lang },
h(
"head",
- null,
- h("meta", { charSet: "UTF-8" }),
- h("meta", {
- name: "viewport",
- content: "width=device-width, initial-scale=1.0",
- }),
- opts.preloads.map((src) =>
- h("link", { rel: "modulepreload", href: src })
- ),
- opts.moduleScripts.map(([src, nonce]) =>
+ OUTER_DOCUMENT.head,
+ // Add some tags ourselves if the user uses the legacy
+ // _app template rendering style where we provided the outer
+ // HTML document.
+ !renderedHtmlTag ? h("meta", { charSet: "UTF-8" }) : null,
+ !renderedHtmlTag
+ ? h("meta", {
+ name: "viewport",
+ content: "width=device-width, initial-scale=1.0",
+ })
+ : null,
+ OUTER_DOCUMENT.title,
+ OUTER_DOCUMENT.headNodes.map((node) => h(node.type, node.props)),
+ // Fresh scripts
+ preloads.map((src) => h("link", { rel: "modulepreload", href: src })),
+ moduleScripts.map(([src, nonce]) =>
h("script", { src: src, nonce: nonce, type: "module" })
),
- opts.headComponents,
+ headComponents,
),
- h("body", { dangerouslySetInnerHTML: { __html: opts.bodyHtml } }),
+ h("body", { dangerouslySetInnerHTML: { __html: bodyHtml } }),
);
- return "" + renderToString(page);
+ const html = "" + renderToString(page);
+
+ return [html, csp];
}
const supportsUnstableComments = renderToString(h(Fragment, {
@@ -666,6 +702,8 @@ const islandOwners = new Map();
const originalHook = options.vnode;
let ignoreNext = false;
+let headChildren = false;
+let renderedHtmlTag = false;
options.vnode = (vnode) => {
assetHashingHook(vnode);
const originalType = vnode.type as ComponentType;
@@ -737,7 +775,7 @@ options.vnode = (vnode) => {
);
};
}
- } else if (typeof vnode.type === "string" && vnode.props !== null) {
+ } else {
// Work around `preact/debug` string event handler error which
// errors when an event handler gets a string. This makes sense
// on the client where this is a common vector for XSS. On the
@@ -757,10 +795,48 @@ options.vnode = (vnode) => {
if (originalHook) originalHook(vnode);
};
+function excludeChildren(props: Record) {
+ const out: Record = {};
+ for (const k in props) {
+ if (k !== "children") out[k] = props[k];
+ }
+ return out;
+}
+
// Keep track of owners
+const oldDiff = options.__b;
const oldDiffed = options.diffed;
const oldRender = options.__r;
const oldCommit = options.__c;
+options.__b = (vnode: VNode>) => {
+ if (RENDERING_USER_TEMPLATE && typeof vnode.type === "string") {
+ if (vnode.type === "html") {
+ renderedHtmlTag = true;
+ OUTER_DOCUMENT.html = excludeChildren(vnode.props);
+ vnode.type = Fragment;
+ } else if (vnode.type === "head") {
+ OUTER_DOCUMENT.head = excludeChildren(vnode.props);
+ headChildren = true;
+ vnode.type = Fragment;
+ vnode.props = {
+ __freshHead: true,
+ children: vnode.props.children,
+ };
+ } else if (vnode.type === "body") {
+ OUTER_DOCUMENT.body = excludeChildren(vnode.props);
+ vnode.type = Fragment;
+ } else if (headChildren) {
+ if (vnode.type === "title") {
+ OUTER_DOCUMENT.title = h("title", vnode.props);
+ vnode.props = { children: null };
+ } else {
+ OUTER_DOCUMENT.headNodes.push({ type: vnode.type, props: vnode.props });
+ }
+ vnode.type = Fragment;
+ }
+ }
+ oldDiff?.(vnode);
+};
options.__r = (vnode) => {
if (
typeof vnode.type === "function" &&
@@ -770,10 +846,12 @@ options.__r = (vnode) => {
}
oldRender?.(vnode);
};
-options.diffed = (vnode) => {
+options.diffed = (vnode: VNode>) => {
if (typeof vnode.type === "function") {
if (vnode.type !== Fragment) {
ownerStack.pop();
+ } else if (vnode.props.__freshHead) {
+ headChildren = false;
}
}
oldDiffed?.(vnode);
diff --git a/src/server/render_test.ts b/src/server/render_test.ts
deleted file mode 100644
index 9e2172f7..00000000
--- a/src/server/render_test.ts
+++ /dev/null
@@ -1,14 +0,0 @@
-import { template } from "./render.ts";
-import { assertStringIncludes } from "../../tests/deps.ts";
-
-Deno.test("check lang", () => {
- const lang = "fr";
- const body = template({
- bodyHtml: "",
- headComponents: [],
- moduleScripts: [],
- preloads: [],
- lang,
- });
- assertStringIncludes(body, ``);
-});
diff --git a/tests/cli_test.ts b/tests/cli_test.ts
index 4ab7056f..761ff709 100644
--- a/tests/cli_test.ts
+++ b/tests/cli_test.ts
@@ -458,3 +458,59 @@ Deno.test("fresh-update", async function fn(t) {
assertEquals(code, 0);
}
});
+
+Deno.test("fresh-update add _app.tsx if not present", async function fn(t) {
+ // Preparation
+ const tmpDirName = await Deno.makeTempDir();
+
+ const cliProcess = new Deno.Command(Deno.execPath(), {
+ args: [
+ "run",
+ "-A",
+ path.join(Deno.cwd(), "init.ts"),
+ ".",
+ ],
+ cwd: tmpDirName,
+ stdin: "null",
+ stdout: "null",
+ });
+
+ await cliProcess.output();
+
+ const appTsx = path.join(tmpDirName, "routes", "_app.tsx");
+ await Deno.remove(appTsx);
+
+ await t.step("execute update command", async () => {
+ await updateAndVerify(
+ /The manifest has been generated for \d+ routes and \d+ islands./,
+ );
+ });
+
+ await t.step("add _app.tsx", async () => {
+ const raw = await Deno.readTextFile(appTsx);
+ assert(raw.includes(""), `-tag not found in _app.tsx`);
+ });
+
+ async function updateAndVerify(expected: RegExp) {
+ const cliProcess = new Deno.Command(Deno.execPath(), {
+ args: [
+ "run",
+ "-A",
+ path.join(Deno.cwd(), "update.ts"),
+ ".",
+ ],
+ cwd: tmpDirName,
+ stdin: "null",
+ stdout: "piped",
+ });
+
+ const { code, stdout } = await cliProcess.output();
+ const output = new TextDecoder().decode(stdout);
+
+ assertMatch(
+ output,
+ expected,
+ );
+ assertEquals(code, 0);
+ }
+});
diff --git a/tests/explicit_app_template_test.ts b/tests/explicit_app_template_test.ts
new file mode 100644
index 00000000..0d946349
--- /dev/null
+++ b/tests/explicit_app_template_test.ts
@@ -0,0 +1,68 @@
+import {
+ assertNotSelector,
+ assertSelector,
+ assertTextMany,
+ fetchHtml,
+ withFresh,
+} from "$fresh/tests/test_utils.ts";
+
+Deno.test("doesn't apply internal app template", async () => {
+ await withFresh(
+ "./tests/fixture_explicit_app/main.ts",
+ async (address) => {
+ const doc = await fetchHtml(`${address}`);
+
+ // Doesn't render internal app template
+ assertNotSelector(doc, "body body");
+
+ assertSelector(doc, "html > head");
+ assertSelector(doc, "html > body");
+ assertSelector(doc, `meta[charset="utf-8"]`);
+ assertSelector(
+ doc,
+ `meta[name="viewport"][content="width=device-width, initial-scale=1.0"]`,
+ );
+ assertTextMany(doc, "title", ["fresh title"]);
+
+ // Still renders page
+ assertSelector(doc, "body > .inner-body > .page");
+ },
+ );
+});
+
+Deno.test("user _app works with ", async () => {
+ await withFresh(
+ "./tests/fixture_explicit_app/main.ts",
+ async (address) => {
+ const doc = await fetchHtml(`${address}/head`);
+
+ // Doesn't render internal app template
+ assertNotSelector(doc, "body body");
+
+ assertSelector(doc, "html > head");
+ assertSelector(doc, "html > body");
+ assertSelector(doc, `meta[charset="utf-8"]`);
+ assertSelector(
+ doc,
+ `meta[name="viewport"][content="width=device-width, initial-scale=1.0"]`,
+ );
+ assertSelector(
+ doc,
+ `meta[name="fresh"][content="test"]`,
+ );
+
+ // Still renders page
+ assertSelector(doc, "body > .inner-body > .page");
+ },
+ );
+});
+
+Deno.test("don't duplicate ", async () => {
+ await withFresh(
+ "./tests/fixture_explicit_app/main.ts",
+ async (address) => {
+ const doc = await fetchHtml(`${address}/title`);
+ assertTextMany(doc, "title", ["foo bar"]);
+ },
+ );
+});
diff --git a/tests/fixture/deno.json b/tests/fixture/deno.json
index bbc066e9..2b73c679 100644
--- a/tests/fixture/deno.json
+++ b/tests/fixture/deno.json
@@ -4,7 +4,7 @@
"$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.2.0",
+ "preact-render-to-string": "https://esm.sh/*preact-render-to-string@6.2.1",
"@preact/signals": "https://esm.sh/*@preact/signals@1.1.5",
"@preact/signals-core": "https://esm.sh/@preact/signals-core@1.3.1"
},
diff --git a/tests/fixture_custom_500/deno.json b/tests/fixture_custom_500/deno.json
index 04ee3099..2b2fa78e 100644
--- a/tests/fixture_custom_500/deno.json
+++ b/tests/fixture_custom_500/deno.json
@@ -4,7 +4,7 @@
"$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.2.0"
+ "preact-render-to-string": "https://esm.sh/*preact-render-to-string@6.2.1"
},
"compilerOptions": {
"jsx": "react-jsx",
diff --git a/tests/fixture_error/deno.json b/tests/fixture_error/deno.json
index 04ee3099..2b2fa78e 100644
--- a/tests/fixture_error/deno.json
+++ b/tests/fixture_error/deno.json
@@ -4,7 +4,7 @@
"$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.2.0"
+ "preact-render-to-string": "https://esm.sh/*preact-render-to-string@6.2.1"
},
"compilerOptions": {
"jsx": "react-jsx",
diff --git a/tests/fixture_explicit_app/dev.ts b/tests/fixture_explicit_app/dev.ts
new file mode 100644
index 00000000..2d85d6c1
--- /dev/null
+++ b/tests/fixture_explicit_app/dev.ts
@@ -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");
diff --git a/tests/fixture_explicit_app/fresh.gen.ts b/tests/fixture_explicit_app/fresh.gen.ts
new file mode 100644
index 00000000..3032075c
--- /dev/null
+++ b/tests/fixture_explicit_app/fresh.gen.ts
@@ -0,0 +1,21 @@
+// 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/_app.tsx";
+import * as $1 from "./routes/head.tsx";
+import * as $2 from "./routes/index.tsx";
+import * as $3 from "./routes/title.tsx";
+
+const manifest = {
+ routes: {
+ "./routes/_app.tsx": $0,
+ "./routes/head.tsx": $1,
+ "./routes/index.tsx": $2,
+ "./routes/title.tsx": $3,
+ },
+ islands: {},
+ baseUrl: import.meta.url,
+};
+
+export default manifest;
diff --git a/tests/fixture_explicit_app/main.ts b/tests/fixture_explicit_app/main.ts
new file mode 100644
index 00000000..0f15e8de
--- /dev/null
+++ b/tests/fixture_explicit_app/main.ts
@@ -0,0 +1,10 @@
+///
+///
+///
+///
+///
+
+import { start } from "$fresh/server.ts";
+import manifest from "./fresh.gen.ts";
+
+await start(manifest);
diff --git a/tests/fixture_explicit_app/routes/_app.tsx b/tests/fixture_explicit_app/routes/_app.tsx
new file mode 100644
index 00000000..14980273
--- /dev/null
+++ b/tests/fixture_explicit_app/routes/_app.tsx
@@ -0,0 +1,25 @@
+import { AppProps, Handler } from "$fresh/server.ts";
+
+export const handler: Handler = (_req, ctx) => {
+ ctx.state.lang = "de";
+ return ctx.render();
+};
+
+export default function App(
+ { Component, state }: AppProps,
+) {
+ return (
+
+
+
+
+ fresh title
+
+
+
+
+
+
+
+ );
+}
diff --git a/tests/fixture_explicit_app/routes/head.tsx b/tests/fixture_explicit_app/routes/head.tsx
new file mode 100644
index 00000000..82e2fdd1
--- /dev/null
+++ b/tests/fixture_explicit_app/routes/head.tsx
@@ -0,0 +1,12 @@
+import { Head } from "$fresh/runtime.ts";
+
+export default function Home() {
+ return (
+
+
+
+
+ /head
+
+ );
+}
diff --git a/tests/fixture_explicit_app/routes/index.tsx b/tests/fixture_explicit_app/routes/index.tsx
new file mode 100644
index 00000000..7f6cc82f
--- /dev/null
+++ b/tests/fixture_explicit_app/routes/index.tsx
@@ -0,0 +1,7 @@
+export default function Home() {
+ return (
+
+ Home
+
+ );
+}
diff --git a/tests/fixture_explicit_app/routes/title.tsx b/tests/fixture_explicit_app/routes/title.tsx
new file mode 100644
index 00000000..cdf4e776
--- /dev/null
+++ b/tests/fixture_explicit_app/routes/title.tsx
@@ -0,0 +1,12 @@
+import { Head } from "$fresh/runtime.ts";
+
+export default function Home() {
+ return (
+
+
+
foo bar
+
+ /title
+
+ );
+}
diff --git a/tests/fixture_invalid_handlers/deno.json b/tests/fixture_invalid_handlers/deno.json
index 04ee3099..2b2fa78e 100644
--- a/tests/fixture_invalid_handlers/deno.json
+++ b/tests/fixture_invalid_handlers/deno.json
@@ -4,7 +4,7 @@
"$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.2.0"
+ "preact-render-to-string": "https://esm.sh/*preact-render-to-string@6.2.1"
},
"compilerOptions": {
"jsx": "react-jsx",
diff --git a/tests/fixture_island_nesting/deno.json b/tests/fixture_island_nesting/deno.json
index 30d3b607..2ba46538 100644
--- a/tests/fixture_island_nesting/deno.json
+++ b/tests/fixture_island_nesting/deno.json
@@ -7,7 +7,7 @@
"$fresh/": "../../",
"preact": "https://esm.sh/preact@10.16.0",
"preact/": "https://esm.sh/preact@10.16.0/",
- "preact-render-to-string": "https://esm.sh/*preact-render-to-string@6.2.0",
+ "preact-render-to-string": "https://esm.sh/*preact-render-to-string@6.2.1",
"@preact/signals": "https://esm.sh/*@preact/signals@1.1.3",
"@preact/signals-core": "https://esm.sh/@preact/signals-core@1.2.3"
},
diff --git a/tests/fixture_npm/deno.json b/tests/fixture_npm/deno.json
index 9d782057..85b23d14 100644
--- a/tests/fixture_npm/deno.json
+++ b/tests/fixture_npm/deno.json
@@ -4,7 +4,7 @@
"$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.2.0",
+ "preact-render-to-string": "https://esm.sh/*preact-render-to-string@6.2.1",
"@preact/signals": "https://esm.sh/*@preact/signals@1.1.3",
"@preact/signals-core": "https://esm.sh/@preact/signals-core@1.2.3"
},
diff --git a/tests/fixture_plugin/deno.json b/tests/fixture_plugin/deno.json
index 04ee3099..2b2fa78e 100644
--- a/tests/fixture_plugin/deno.json
+++ b/tests/fixture_plugin/deno.json
@@ -4,7 +4,7 @@
"$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.2.0"
+ "preact-render-to-string": "https://esm.sh/*preact-render-to-string@6.2.1"
},
"compilerOptions": {
"jsx": "react-jsx",
diff --git a/tests/fixture_render_error/deno.json b/tests/fixture_render_error/deno.json
index 04ee3099..2b2fa78e 100644
--- a/tests/fixture_render_error/deno.json
+++ b/tests/fixture_render_error/deno.json
@@ -4,7 +4,7 @@
"$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.2.0"
+ "preact-render-to-string": "https://esm.sh/*preact-render-to-string@6.2.1"
},
"compilerOptions": {
"jsx": "react-jsx",
diff --git a/tests/fixture_twind_hydrate/deno.json b/tests/fixture_twind_hydrate/deno.json
index 226bf747..f4864075 100644
--- a/tests/fixture_twind_hydrate/deno.json
+++ b/tests/fixture_twind_hydrate/deno.json
@@ -7,7 +7,7 @@
"$fresh/": "../../",
"preact": "https://esm.sh/preact@10.11.0",
"preact/": "https://esm.sh/preact@10.11.0/",
- "preact-render-to-string": "https://esm.sh/*preact-render-to-string@6.2.0",
+ "preact-render-to-string": "https://esm.sh/*preact-render-to-string@6.2.1",
"@preact/signals": "https://esm.sh/*@preact/signals@1.0.3",
"@preact/signals-core": "https://esm.sh/*@preact/signals-core@1.0.1"
},
diff --git a/update.ts b/update.ts
index c8ab0501..5436c4a8 100644
--- a/update.ts
+++ b/update.ts
@@ -1,4 +1,5 @@
import {
+ basename,
dirname,
existsSync,
extname,
@@ -230,6 +231,34 @@ await start(manifest, { plugins: [twindPlugin(twindConfig)] });\n`;
}
}
+// Add default _app.tsx if not present
+const routes = Array.from(Deno.readDirSync(join(srcDirectory, "routes")));
+if (!routes.find((entry) => entry.isFile && entry.name.startsWith("_app."))) {
+ const APP_TSX = `import { AppProps } from "$fresh/server.ts";
+
+export default function App({ Component }: AppProps) {
+ return (
+
+
+
+
+ ${basename(resolvedDirectory)}
+
+
+
+
+
+ );
+}`;
+ await Deno.writeTextFile(
+ join(srcDirectory, "routes", "_app.tsx"),
+ APP_TSX,
+ );
+}
+
+console.log(routes);
+// await Deno.writeTextFile(MAIN_TS_PATH, MAIN_TS);
+
const manifest = await collect(srcDirectory);
await generate(srcDirectory, manifest);
diff --git a/www/deno.json b/www/deno.json
index 9034e96a..e5df9da7 100644
--- a/www/deno.json
+++ b/www/deno.json
@@ -9,7 +9,7 @@
"twind/": "https://esm.sh/twind@0.16.19/",
"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.2.0",
+ "preact-render-to-string": "https://esm.sh/*preact-render-to-string@6.2.1",
"@preact/signals": "https://esm.sh/*@preact/signals@1.1.3",
"@preact/signals-core": "https://esm.sh/@preact/signals-core@1.2.3",
"$std/": "https://deno.land/std@0.193.0/",