Skip to content

Commit

Permalink
fix: missing Component with async app + layout
Browse files Browse the repository at this point in the history
  • Loading branch information
marvinhagemeister committed Oct 4, 2023
1 parent f246722 commit e69182f
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/server/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,15 @@ export async function render<Data>(
componentFn.displayName = (fn as any).displayName || fn.name;
componentStack[i] = componentFn;
} else {
componentStack[i] = fn;
componentStack[i] = () => {
return h(fn, {
...props,
Component() {
return h(componentStack[i + 1], null);
},
// deno-lint-ignore no-explicit-any
} as any);
};
}
}

Expand Down
5 changes: 5 additions & 0 deletions tests/fixture_layouts_2/dev.ts
Original file line number Diff line number Diff line change
@@ -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");
19 changes: 19 additions & 0 deletions tests/fixture_layouts_2/fresh.gen.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// 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/_layout.tsx";
import * as $2 from "./routes/index.tsx";

const manifest = {
routes: {
"./routes/_app.tsx": $0,
"./routes/_layout.tsx": $1,
"./routes/index.tsx": $2,
},
islands: {},
baseUrl: import.meta.url,
};

export default manifest;
10 changes: 10 additions & 0 deletions tests/fixture_layouts_2/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/// <reference no-default-lib="true" />
/// <reference lib="dom" />
/// <reference lib="dom.asynciterable" />
/// <reference lib="deno.ns" />
/// <reference lib="deno.unstable" />

import { start } from "$fresh/server.ts";
import manifest from "./fresh.gen.ts";

await start(manifest);
9 changes: 9 additions & 0 deletions tests/fixture_layouts_2/routes/_app.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { defineApp } from "$fresh/server.ts";

export default defineApp((req, { Component }) => {
return (
<div class="app">
<Component />
</div>
);
});
11 changes: 11 additions & 0 deletions tests/fixture_layouts_2/routes/_layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { LayoutProps } from "$fresh/server.ts";

export default function RootLayout(
{ Component }: LayoutProps<unknown>,
) {
return (
<div class="root-layout">
<Component />
</div>
);
}
7 changes: 7 additions & 0 deletions tests/fixture_layouts_2/routes/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default function Home() {
return (
<div class="home-page">
Home
</div>
);
}
10 changes: 10 additions & 0 deletions tests/layouts_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,3 +191,13 @@ Deno.test({
);
},
});

Deno.test("mix async app and layouts", async () => {
await withFakeServe(
"./tests/fixture_layouts_2/main.ts",
async (server) => {
const doc = await server.getHtml(`/`);
assertSelector(doc, ".app > .root-layout > .home-page");
},
);
});

0 comments on commit e69182f

Please sign in to comment.