diff --git a/.vscode/import_map.json b/.vscode/import_map.json
index eb692025..5416453a 100644
--- a/.vscode/import_map.json
+++ b/.vscode/import_map.json
@@ -6,11 +6,11 @@
"$fresh/": "../",
"twind": "https://esm.sh/twind@0.16.19",
"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.1",
- "@preact/signals": "https://esm.sh/*@preact/signals@1.1.3",
- "@preact/signals-core": "https://esm.sh/@preact/signals-core@1.2.3",
+ "preact": "https://esm.sh/preact@10.18.1",
+ "preact/": "https://esm.sh/preact@10.18.1/",
+ "preact-render-to-string": "https://esm.sh/*preact-render-to-string@6.2.2",
+ "@preact/signals": "https://esm.sh/*@preact/signals@1.2.1",
+ "@preact/signals-core": "https://esm.sh/@preact/signals-core@1.5.0",
"@preact/signals-core@1.2.3": "https://esm.sh/@preact/signals-core@1.2.3",
"@preact/signals-core@1.3.0": "https://esm.sh/@preact/signals-core@1.3.0",
"$std/": "https://deno.land/std@0.193.0/",
diff --git a/docs/canary/concepts/app-wrapper.md b/docs/canary/concepts/app-wrapper.md
new file mode 100644
index 00000000..13b51ff3
--- /dev/null
+++ b/docs/canary/concepts/app-wrapper.md
@@ -0,0 +1,106 @@
+---
+description: |
+ Add a global app wrapper to provide common meta tags or context for application routes.
+---
+
+An app wrapper is defined in an `_app.tsx` file in `routes/` folder and is
+typically used to create the outer structure of an HTML document. It must
+contain a default export that is a regular Preact component. Only one such
+wrapper is allowed per application.
+
+The component to be wrapped is received via props, in addition to a few other
+things. This allows for the introduction of a global container functioning as a
+template which can be conditioned based on state and params. Note that any state
+set by middleware is available via `props.state`.
+
+```tsx routes/_app.tsx
+import { AppProps } from "$fresh/server.ts";
+
+export default function App({ Component, state }: AppProps) {
+ // do something with state here
+ return (
+
+
+
+
+ My Fresh app
+
+
+
+
+
+ );
+}
+```
+
+## Async app wrapper
+
+Similar to routes and layouts, the app wrapper can be made asynchronous. This
+changes the function signature so that the first argument is the `Request`
+instance and the second one is the `AppContext`.
+
+```tsx routes/_app.tsx
+import { AppContext } from "$fresh/server.ts";
+
+export default async function App(req: Request, ctx: AppContext) {
+ const data = await loadData();
+
+ return (
+
+
+
+
+ My Fresh app
+
+
+
Hello {data.name}
+
+
+
+ );
+}
+```
+
+### Define helper
+
+To make it quicker to type the async app wrapper, Fresh includes a `defineApp`
+helper which already infers the correct types for you.
+
+```tsx routes/_app.tsx
+import { defineApp } from "$fresh/server.ts";
+
+export default defineApp(async (req, ctx) => {
+ const data = await loadData();
+
+ return (
+
+
+
+
+ My Fresh app
+
+
+
Hello {data.name}
+
+
+
+ );
+});
+```
+
+## Disabling the app wrapper
+
+Rendering the app wrapper can be skipped on a route or layout basis. To do that,
+set `skipAppWrapper: true` to the layout or route config.
+
+```tsx routes/my-special-route.tsx
+import { RouteConfig } from "$fresh/server.ts";
+
+export const config: RouteConfig = {
+ skipAppWrapper: true, // Skip the app wrapper during rendering
+};
+
+export default function Page() {
+ // ...
+}
+```
diff --git a/docs/latest/concepts/app-wrapper.md b/docs/latest/concepts/app-wrapper.md
index a564591b..13b51ff3 100644
--- a/docs/latest/concepts/app-wrapper.md
+++ b/docs/latest/concepts/app-wrapper.md
@@ -21,7 +21,7 @@ export default function App({ Component, state }: AppProps) {
return (
-
+
My Fresh app
@@ -48,7 +48,7 @@ export default async function App(req: Request, ctx: AppContext) {
return (
-
+
My Fresh app
@@ -75,7 +75,7 @@ export default defineApp(async (req, ctx) => {
return (
-
+
My Fresh app
diff --git a/docs/toc.ts b/docs/toc.ts
index 9ee2db66..31eb2444 100644
--- a/docs/toc.ts
+++ b/docs/toc.ts
@@ -48,7 +48,7 @@ const toc: RawTableOfContents = {
["server-components", "Server Components", "link:latest"],
["routing", "Routing", "link:latest"],
["routes", "Routes", "link:latest"],
- ["app-wrapper", "App wrapper", "link:latest"],
+ ["app-wrapper", "App wrapper", "link:canary"],
["layouts", "Layouts", "link:latest"],
["forms", "Forms", "link:latest"],
["islands", "Interactive islands", "link:latest"],
diff --git a/init.ts b/init.ts
index b2b36977..47571eaf 100644
--- a/init.ts
+++ b/init.ts
@@ -438,7 +438,7 @@ export default function App({ Component }: AppProps) {
return (
-
+
${basename(resolvedDirectory)}
@@ -455,7 +455,7 @@ export default function App({ Component }: AppProps) {
return (
-
+
${basename(resolvedDirectory)}
diff --git a/src/dev/imports.ts b/src/dev/imports.ts
index 54e47f8b..b257a2e7 100644
--- a/src/dev/imports.ts
+++ b/src/dev/imports.ts
@@ -1,7 +1,7 @@
-export const RECOMMENDED_PREACT_VERSION = "10.15.1";
-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_PREACT_VERSION = "10.18.1";
+export const RECOMMENDED_PREACT_RTS_VERSION = "6.2.2";
+export const RECOMMENDED_PREACT_SIGNALS_VERSION = "1.2.1";
+export const RECOMMENDED_PREACT_SIGNALS_CORE_VERSION = "1.5.0";
export const RECOMMENDED_TWIND_VERSION = "0.16.19";
export const RECOMMENDED_STD_VERSION = "0.193.0";
diff --git a/src/runtime/entrypoints/main.ts b/src/runtime/entrypoints/main.ts
index 79272485..3109fc98 100644
--- a/src/runtime/entrypoints/main.ts
+++ b/src/runtime/entrypoints/main.ts
@@ -97,7 +97,7 @@ export function revive(
[],
// Keep a root node in the vnode stack to save a couple of checks
// later during iteration
- [h(Fragment, null)],
+ [h(Fragment, null) as VNode],
document.body,
result,
);
@@ -324,11 +324,11 @@ function _walkInner(
});
vnodeStack.push(
- h(PartialComp, { name, key, mode: +mode }),
+ h(PartialComp, { name, key, mode: +mode }) as VNode,
);
} else if (comment.startsWith("frsh-key")) {
const key = comment.slice("frsh-key:".length);
- vnodeStack.push(h(Fragment, { key }));
+ vnodeStack.push(h(Fragment, { key }) as VNode);
} else if (comment.startsWith("/frsh-key")) {
const vnode = vnodeStack.pop();
const parent = vnodeStack[vnodeStack.length - 1]!;
@@ -453,7 +453,7 @@ function _walkInner(
kind: MarkerKind.Island,
});
- const vnode = h(islands[id][exportName], islandProps);
+ const vnode = h(islands[id][exportName], islandProps) as VNode;
if (key) vnode.key = key;
vnodeStack.push(vnode);
}
@@ -510,7 +510,7 @@ function _walkInner(
// Remove internal fresh key
if (hasKey) sib.removeAttribute(DATA_KEY_ATTR);
- const vnode = h(sib.localName, newProps);
+ const vnode = h(sib.localName, newProps) as VNode;
addPropsChild(parentVNode, vnode);
vnodeStack.push(vnode);
} else {
@@ -621,7 +621,7 @@ function collectPartials(
islands,
state[0] ?? [],
[],
- [h(Fragment, null)],
+ [h(Fragment, null) as VNode],
rootFrag,
encounteredPartials,
);
diff --git a/src/server/rendering/preact_hooks.ts b/src/server/rendering/preact_hooks.ts
index 44b29f04..455c6623 100644
--- a/src/server/rendering/preact_hooks.ts
+++ b/src/server/rendering/preact_hooks.ts
@@ -82,7 +82,7 @@ export function setRenderState(state: RenderState | null): void {
const supportsUnstableComments = renderToString(h(Fragment, {
// @ts-ignore unstable features not supported in types
UNSTABLE_comment: "foo",
-})) !== "";
+}) as VNode) !== "";
if (!supportsUnstableComments) {
console.warn(
@@ -347,7 +347,7 @@ options.__b = (vnode: VNode>) => {
);
}
- const child = h(originalType, props);
+ const child = h(originalType, props) as VNode;
patched.add(child);
islandProps.push(props);
diff --git a/src/server/rendering/template.tsx b/src/server/rendering/template.tsx
index ba6e420c..e3bb6f13 100644
--- a/src/server/rendering/template.tsx
+++ b/src/server/rendering/template.tsx
@@ -1,7 +1,14 @@
import { RenderState } from "./state.ts";
import { setRenderState } from "./preact_hooks.ts";
import { renderToString } from "preact-render-to-string";
-import { Fragment, h, isValidElement, toChildArray, VNode } from "preact";
+import {
+ ComponentType,
+ Fragment,
+ h,
+ isValidElement,
+ toChildArray,
+ VNode,
+} from "preact";
import { HEAD_CONTEXT } from "../../runtime/head.ts";
import { CSP_CONTEXT } from "../../runtime/csp.ts";
@@ -13,12 +20,12 @@ export function renderHtml(state: RenderState) {
const componentStack = state.componentStack;
try {
const routeComponent = componentStack[componentStack.length - 1];
- let finalComp = h(routeComponent, state.routeOptions);
+ let finalComp = h(routeComponent, state.routeOptions) as VNode;
// Skip page component
let i = componentStack.length - 1;
while (i--) {
- const component = componentStack[i];
+ const component = componentStack[i] as ComponentType;
const curComp = finalComp;
finalComp = h(component, {
@@ -26,7 +33,8 @@ export function renderHtml(state: RenderState) {
Component() {
return curComp;
},
- });
+ // deno-lint-ignore no-explicit-any
+ } as any) as VNode;
}
const app = h(
@@ -37,12 +45,12 @@ export function renderHtml(state: RenderState) {
value: state.headVNodes,
children: finalComp,
}),
- );
+ ) as VNode;
let html = renderToString(app);
for (const [id, children] of state.slots.entries()) {
- const slotHtml = renderToString(h(Fragment, null, children));
+ const slotHtml = renderToString(h(Fragment, null, children) as VNode);
const templateId = id.replace(/:/g, "-");
html += `${slotHtml}`;
}
@@ -103,7 +111,7 @@ export function renderOuterDocument(
h(
"head",
docHead,
- !renderedHtmlTag ? h("meta", { charSet: "utf-8" }) : null,
+ !renderedHtmlTag ? h("meta", { charset: "utf-8" }) : null,
!renderedHtmlTag
? (h("meta", {
name: "viewport",
@@ -124,7 +132,7 @@ export function renderOuterDocument(
...docBody,
dangerouslySetInnerHTML: { __html: opts.bodyHtml },
}),
- );
+ ) as VNode;
try {
setRenderState(state);
diff --git a/tests/fixture_async_app/routes/_app.tsx b/tests/fixture_async_app/routes/_app.tsx
index 48ad41c4..81ae68bd 100644
--- a/tests/fixture_async_app/routes/_app.tsx
+++ b/tests/fixture_async_app/routes/_app.tsx
@@ -7,7 +7,7 @@ export default async function App(req: Request, ctx: AppContext) {
return (
-
+
-
+
fresh title
diff --git a/tests/fixture_partials/routes/_app.tsx b/tests/fixture_partials/routes/_app.tsx
index 8bd4ed3c..1e55e7d3 100644
--- a/tests/fixture_partials/routes/_app.tsx
+++ b/tests/fixture_partials/routes/_app.tsx
@@ -4,7 +4,7 @@ export default defineApp((res, ctx) => {
return (
-
+
test
diff --git a/tests/fixture_partials/routes/client_nav/_layout.tsx b/tests/fixture_partials/routes/client_nav/_layout.tsx
index 810c8249..baf923d3 100644
--- a/tests/fixture_partials/routes/client_nav/_layout.tsx
+++ b/tests/fixture_partials/routes/client_nav/_layout.tsx
@@ -6,7 +6,7 @@ export default function AppLayout({ Component }: AppProps) {
return (
-
+
fresh title
diff --git a/tests/fixture_partials/routes/client_nav_opt_out/_layout.tsx b/tests/fixture_partials/routes/client_nav_opt_out/_layout.tsx
index 18a5e617..550bcab9 100644
--- a/tests/fixture_partials/routes/client_nav_opt_out/_layout.tsx
+++ b/tests/fixture_partials/routes/client_nav_opt_out/_layout.tsx
@@ -6,7 +6,7 @@ export default function AppLayout({ Component }: AppProps) {
return (
-
+
fresh title
diff --git a/tests/fixture_twind_app/routes/_app.tsx b/tests/fixture_twind_app/routes/_app.tsx
index 5183eaa7..9e889f93 100644
--- a/tests/fixture_twind_app/routes/_app.tsx
+++ b/tests/fixture_twind_app/routes/_app.tsx
@@ -4,7 +4,7 @@ export default function App({ Component }: AppProps) {
return (
-
+
fresh-foo
diff --git a/update.ts b/update.ts
index 4b6af4ab..a611d335 100644
--- a/update.ts
+++ b/update.ts
@@ -284,7 +284,7 @@ export default function App({ Component }: AppProps) {
return (
-
+
${basename(resolvedDirectory)}