From 8f813fad90e5c4b97a2356c7b34ae87fd6805824 Mon Sep 17 00:00:00 2001 From: Asher Gomez Date: Fri, 27 Jun 2025 17:54:53 +1000 Subject: [PATCH] fix(core): use `PageProps` instead of `FreshContext` in `define*()` compat functions (#3064) In Fresh 1, define apps used `RouteContext`, which align with `PageProps` in Fresh 2, rather than `FreshContext`. E.g. before this PR, one would get a type error if they tried to use `ctx.Component` within `defineApp()` and now they shouldn't. --- src/compat.ts | 6 +++--- src/compat_test.tsx | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/compat.ts b/src/compat.ts index f85ea088..f37f9c97 100644 --- a/src/compat.ts +++ b/src/compat.ts @@ -1,5 +1,5 @@ import type { ComponentChildren } from "preact"; -import type { FreshContext } from "./context.ts"; +import type { FreshContext, PageProps } from "./context.ts"; import type { HandlerFn, RouteHandler } from "./handlers.ts"; /** @@ -45,13 +45,13 @@ export type Handler> = HandlerFn< function defineFn( fn: ( - ctx: FreshContext, + ctx: PageProps, ) => | ComponentChildren | Response | Promise, ): ( - ctx: FreshContext, + ctx: PageProps, ) => | ComponentChildren | Response diff --git a/src/compat_test.tsx b/src/compat_test.tsx index 8480305c..fdf0f7d6 100644 --- a/src/compat_test.tsx +++ b/src/compat_test.tsx @@ -1,10 +1,10 @@ -import type { FreshContext } from "./context.ts"; +import type { PageProps } from "./context.ts"; import { assertType, type IsExact } from "@std/testing/types"; import { expect } from "@std/expect"; import { type defineApp, type defineLayout, defineRoute } from "./compat.ts"; Deno.test("compat - defineFn works", () => { - const ctx = {} as FreshContext; + const ctx = {} as PageProps; expect(defineRoute(() => new Response("test"))(ctx)).toBeInstanceOf(Response); expect(defineRoute(() => test)(ctx)).toBeInstanceOf(Object); expect(defineRoute(() => null)(ctx)).toEqual(null);