diff --git a/src/app_test.tsx b/src/app_test.tsx
index 86c43b64..f2c6570c 100644
--- a/src/app_test.tsx
+++ b/src/app_test.tsx
@@ -697,3 +697,83 @@ Deno.test("App - .get/post/patch/put/delete/head/all() - lazy", async () => {
res = await server.head("/");
expect(await res.text()).toEqual("ok");
});
+
+Deno.test("App - .appWrapper()", async () => {
+ const app = new App()
+ .appWrapper(({ Component }) => (
+ <>
+ app/
+ >
+ ))
+ .get("/", (ctx) => ctx.render(<>index>));
+
+ const server = new FakeServer(app.handler());
+
+ const res = await server.get("/");
+ expect(await res.text()).toContain("
app/index<");
+});
+
+Deno.test.ignore("App - .layout()", async () => {
+ const app = new App()
+ .layout("/", ({ Component }) => (
+ <>
+ layout/
+ >
+ ))
+ .layout("/foo", ({ Component }) => (
+ <>
+ foo/
+ >
+ ))
+ .get("/foo", (ctx) => ctx.render(<>index>));
+
+ const server = new FakeServer(app.handler());
+
+ // The `/foo` layout is not applied for GET `/foo`, is that correct?
+ const res = await server.get("/foo");
+ expect(await res.text()).toContain("layout/foo/index<");
+});
+
+Deno.test("App - .appWrapper() + .layout()", async () => {
+ const app = new App()
+ .appWrapper(({ Component }) => (
+ <>
+ app/
+ >
+ ))
+ .layout("/", ({ Component }) => (
+ <>
+ layout/
+ >
+ ))
+ .get("/", (ctx) => ctx.render(<>index>));
+
+ const server = new FakeServer(app.handler());
+
+ const res = await server.get("/");
+ expect(await res.text()).toContain("app/layout/index<");
+});
+
+Deno.test("App - ctx.render() without app wrapper or layout", async () => {
+ const app = new App()
+ .appWrapper(({ Component }) => (
+ <>
+ app/
+ >
+ ))
+ .layout("/", ({ Component }) => (
+ <>
+ layout/
+ >
+ ))
+ .get("/", (ctx) =>
+ ctx.render(<>index>, undefined, {
+ skipAppWrapper: true,
+ skipInheritedLayouts: true,
+ }));
+
+ const server = new FakeServer(app.handler());
+
+ const res = await server.get("/");
+ expect(await res.text()).toContain("index<");
+});
diff --git a/src/context.ts b/src/context.ts
index 7d6d5490..a829ef4a 100644
--- a/src/context.ts
+++ b/src/context.ts
@@ -10,6 +10,7 @@ import {
import { SpanStatusCode } from "@opentelemetry/api";
import type { ResolvedFreshConfig } from "./config.ts";
import type { BuildCache } from "./build_cache.ts";
+import type { LayoutConfig } from "./types.ts";
import { RenderState, setRenderState } from "./runtime/server/preact_hooks.tsx";
import { PARTIAL_SEARCH_PARAM } from "./constants.ts";
import { tracer } from "./otel.ts";
@@ -187,6 +188,7 @@ export class Context {
// deno-lint-ignore no-explicit-any
vnode: VNode | null,
init: ResponseInit | undefined = {},
+ config: LayoutConfig = {},
): Promise {
if (arguments.length === 0) {
throw new Error(`No arguments passed to: ctx.render()`);
@@ -194,8 +196,8 @@ export class Context {
throw new Error(`Non-JSX element passed to: ctx.render()`);
}
- const defs = this.#internal.layouts;
- const appDef = this.#internal.app;
+ const defs = config.skipInheritedLayouts ? [] : this.#internal.layouts;
+ const appDef = config.skipAppWrapper ? null : this.#internal.app;
const props = this as Context;
// Compose final vnode tree