feat: support async app template (#1626)

Co-authored-by: Asher Gomez <ashersaupingomez@gmail.com>
This commit is contained in:
Marvin Hagemeister
2023-08-14 14:52:48 +02:00
committed by GitHub
co-authored by Asher Gomez
parent 563b61d849
commit ba67d895ce
14 changed files with 217 additions and 158 deletions
+5
View File
@@ -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
View File
@@ -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
View File
@@ -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);
+25
View File
@@ -0,0 +1,25 @@
import { delay } from "$std/async/delay.ts";
import { AppContext } from "$fresh/src/server/types.ts";
export default async function App(req: Request, ctx: AppContext) {
await delay(100);
return (
<html lang="fr">
<head>
<meta charSet="utf-8" />
<meta
name="viewport"
content="width=device-width, initial-scale=1.0"
/>
<title>fresh title</title>
</head>
<body>
<div class="app">
App template
<ctx.Component />
</div>
</body>
</html>
);
}
@@ -0,0 +1,15 @@
import { LayoutContext } from "$fresh/server.ts";
import { delay } from "$std/async/delay.ts";
export default async function AsyncLayout(
req: Request,
ctx: LayoutContext,
) {
await delay(10);
return (
<div class="layout">
<p>Async layout</p>
<ctx.Component />
</div>
);
}
+8
View File
@@ -0,0 +1,8 @@
// deno-lint-ignore require-await
export default async function Home() {
return (
<div class="page">
Home
</div>
);
}
@@ -1,15 +1,15 @@
import { LayoutProps, RouteContext } from "$fresh/server.ts";
import { LayoutContext } from "$fresh/server.ts";
import { delay } from "$fresh/tests/deps.ts";
export default async function AsyncLayout(
req: Request,
ctx: RouteContext,
{ Component }: LayoutProps,
ctx: LayoutContext,
) {
await new Promise((r) => setTimeout(r, 10));
await delay(10);
return (
<div class="async-layout">
<p>Async layout</p>
<Component />
<ctx.Component />
</div>
);
}
@@ -1,10 +1,9 @@
import { LayoutProps, RouteContext } from "$fresh/server.ts";
import { LayoutContext } from "$fresh/server.ts";
import { delay } from "$std/async/mod.ts";
export default async function AsyncSubLayout(
req: Request,
ctx: RouteContext,
{ Component }: LayoutProps,
ctx: LayoutContext,
) {
await delay(10);
return new Response(null, {
@@ -1,15 +1,14 @@
import { LayoutProps, RouteContext } from "$fresh/server.ts";
import { LayoutContext } from "$fresh/server.ts";
export default async function AsyncSubLayout(
req: Request,
ctx: RouteContext,
{ Component }: LayoutProps,
ctx: LayoutContext,
) {
await new Promise((r) => setTimeout(r, 10));
return (
<div class="async-sub-layout">
<p>Async Sub layout</p>
<Component />
<ctx.Component />
</div>
);
}
+15
View File
@@ -1,5 +1,6 @@
import { assertEquals } from "./deps.ts";
import {
assertSelector,
assertTextMany,
fetchHtml,
withFresh,
@@ -156,3 +157,17 @@ Deno.test({
sanitizeOps: false,
sanitizeResources: false,
});
Deno.test({
name: "renders async app template",
async fn() {
await withFresh(
"./tests/fixture_async_app/main.ts",
async (address) => {
const doc = await fetchHtml(`${address}`);
assertSelector(doc, "html > body > .app > .layout > .page");
},
);
},
});