fix(server): make LayoutProps generic (#1592)
This commit is contained in:
+3
-1
@@ -172,7 +172,9 @@ export interface AppModule {
|
||||
default: ComponentType<AppProps>;
|
||||
}
|
||||
|
||||
export interface LayoutProps extends PageProps {
|
||||
// deno-lint-ignore no-explicit-any
|
||||
export interface LayoutProps<T = any, S = Record<string, unknown>>
|
||||
extends PageProps<T, S> {
|
||||
Component: ComponentType<Record<never, never>>;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,41 +4,43 @@
|
||||
|
||||
import * as $0 from "./routes/_app.tsx";
|
||||
import * as $1 from "./routes/_layout.tsx";
|
||||
import * as $2 from "./routes/files/js/_layout.js";
|
||||
import * as $3 from "./routes/files/js/index.js";
|
||||
import * as $4 from "./routes/files/jsx/_layout.jsx";
|
||||
import * as $5 from "./routes/files/jsx/index.jsx";
|
||||
import * as $6 from "./routes/files/ts/_layout.ts";
|
||||
import * as $7 from "./routes/files/ts/index.ts";
|
||||
import * as $8 from "./routes/files/tsx/_layout.tsx";
|
||||
import * as $9 from "./routes/files/tsx/index.tsx";
|
||||
import * as $10 from "./routes/foo/_layout.tsx";
|
||||
import * as $11 from "./routes/foo/bar.tsx";
|
||||
import * as $12 from "./routes/foo/index.tsx";
|
||||
import * as $13 from "./routes/index.tsx";
|
||||
import * as $14 from "./routes/other.tsx";
|
||||
import * as $15 from "./routes/skip/sub/_layout.tsx";
|
||||
import * as $16 from "./routes/skip/sub/index.tsx";
|
||||
import * as $2 from "./routes/_middleware.ts";
|
||||
import * as $3 from "./routes/files/js/_layout.js";
|
||||
import * as $4 from "./routes/files/js/index.js";
|
||||
import * as $5 from "./routes/files/jsx/_layout.jsx";
|
||||
import * as $6 from "./routes/files/jsx/index.jsx";
|
||||
import * as $7 from "./routes/files/ts/_layout.ts";
|
||||
import * as $8 from "./routes/files/ts/index.ts";
|
||||
import * as $9 from "./routes/files/tsx/_layout.tsx";
|
||||
import * as $10 from "./routes/files/tsx/index.tsx";
|
||||
import * as $11 from "./routes/foo/_layout.tsx";
|
||||
import * as $12 from "./routes/foo/bar.tsx";
|
||||
import * as $13 from "./routes/foo/index.tsx";
|
||||
import * as $14 from "./routes/index.tsx";
|
||||
import * as $15 from "./routes/other.tsx";
|
||||
import * as $16 from "./routes/skip/sub/_layout.tsx";
|
||||
import * as $17 from "./routes/skip/sub/index.tsx";
|
||||
|
||||
const manifest = {
|
||||
routes: {
|
||||
"./routes/_app.tsx": $0,
|
||||
"./routes/_layout.tsx": $1,
|
||||
"./routes/files/js/_layout.js": $2,
|
||||
"./routes/files/js/index.js": $3,
|
||||
"./routes/files/jsx/_layout.jsx": $4,
|
||||
"./routes/files/jsx/index.jsx": $5,
|
||||
"./routes/files/ts/_layout.ts": $6,
|
||||
"./routes/files/ts/index.ts": $7,
|
||||
"./routes/files/tsx/_layout.tsx": $8,
|
||||
"./routes/files/tsx/index.tsx": $9,
|
||||
"./routes/foo/_layout.tsx": $10,
|
||||
"./routes/foo/bar.tsx": $11,
|
||||
"./routes/foo/index.tsx": $12,
|
||||
"./routes/index.tsx": $13,
|
||||
"./routes/other.tsx": $14,
|
||||
"./routes/skip/sub/_layout.tsx": $15,
|
||||
"./routes/skip/sub/index.tsx": $16,
|
||||
"./routes/_middleware.ts": $2,
|
||||
"./routes/files/js/_layout.js": $3,
|
||||
"./routes/files/js/index.js": $4,
|
||||
"./routes/files/jsx/_layout.jsx": $5,
|
||||
"./routes/files/jsx/index.jsx": $6,
|
||||
"./routes/files/ts/_layout.ts": $7,
|
||||
"./routes/files/ts/index.ts": $8,
|
||||
"./routes/files/tsx/_layout.tsx": $9,
|
||||
"./routes/files/tsx/index.tsx": $10,
|
||||
"./routes/foo/_layout.tsx": $11,
|
||||
"./routes/foo/bar.tsx": $12,
|
||||
"./routes/foo/index.tsx": $13,
|
||||
"./routes/index.tsx": $14,
|
||||
"./routes/other.tsx": $15,
|
||||
"./routes/skip/sub/_layout.tsx": $16,
|
||||
"./routes/skip/sub/index.tsx": $17,
|
||||
},
|
||||
islands: {},
|
||||
baseUrl: import.meta.url,
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
import { LayoutProps } from "$fresh/server.ts";
|
||||
import { LayoutState } from "./_middleware.ts";
|
||||
|
||||
export default function RootLayout({ Component }: LayoutProps) {
|
||||
export default function RootLayout(
|
||||
{ Component, state }: LayoutProps<unknown, LayoutState>,
|
||||
) {
|
||||
return (
|
||||
<div class="root-layout">
|
||||
{state.something === "it works" ? "it works\n" : "it doesn't work\n"}
|
||||
<Component />
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
import { MiddlewareHandlerContext } from "$fresh/server.ts";
|
||||
|
||||
export type LayoutState = {
|
||||
something: string;
|
||||
};
|
||||
|
||||
export const handler = (
|
||||
_req: Request,
|
||||
ctx: MiddlewareHandlerContext<LayoutState>,
|
||||
) => {
|
||||
ctx.state.something = "it works";
|
||||
return ctx.next();
|
||||
};
|
||||
@@ -1,3 +1,4 @@
|
||||
import { assert } from "./deps.ts";
|
||||
import { assertSelector, fetchHtml, withFresh } from "./test_utils.ts";
|
||||
|
||||
Deno.test("apply root _layout and _app", async () => {
|
||||
@@ -5,6 +6,7 @@ Deno.test("apply root _layout and _app", async () => {
|
||||
"./tests/fixture_layouts/main.ts",
|
||||
async (address) => {
|
||||
const doc = await fetchHtml(address);
|
||||
assert(doc.body.textContent?.includes("it works"));
|
||||
assertSelector(doc, ".app .root-layout .home-page");
|
||||
|
||||
const doc2 = await fetchHtml(`${address}/other`);
|
||||
|
||||
Reference in New Issue
Block a user