docs: update Fresh 2 migration info (#3161)

This commit is contained in:
Marvin Hagemeister
2025-07-31 10:46:44 +02:00
committed by GitHub
parent c08710f7dd
commit 62f8bb008e
7 changed files with 28 additions and 29 deletions
+6 -7
View File
@@ -1,30 +1,29 @@
import type { ComponentChildren } from "preact";
import type { FreshContext } from "./context.ts";
import type { Context } from "./context.ts";
import type { PageProps } from "./render.ts";
import type { HandlerFn, RouteHandler } from "./handlers.ts";
/**
* @deprecated Use {@linkcode PageProps} instead.
*/
export type AppProps<_Data = unknown, T = unknown> = FreshContext<T>;
export type AppProps<_Data = unknown, T = unknown> = Context<T>;
/**
* @deprecated Use {@linkcode PageProps} instead.
*/
export type LayoutProps<_Data = unknown, T = unknown> = FreshContext<T>;
export type LayoutProps<_Data = unknown, T = unknown> = Context<T>;
/**
* @deprecated Use {@linkcode PageProps} instead.
*/
export type UnknownPageProps<_Data = unknown, T = unknown> = FreshContext<T>;
export type UnknownPageProps<_Data = unknown, T = unknown> = Context<T>;
/**
* @deprecated Use {@linkcode PageProps} instead.
*/
export type ErrorPageProps<_Data = unknown, T = unknown> = FreshContext<T>;
export type ErrorPageProps<_Data = unknown, T = unknown> = Context<T>;
/**
* @deprecated Use {@linkcode FreshContext} instead.
*/
export type RouteContext<_T = never, S = Record<string, unknown>> =
FreshContext<S>;
export type RouteContext<_T = never, S = Record<string, unknown>> = Context<S>;
/**
* @deprecated Use {@linkcode RouteHandler} instead.
+3 -3
View File
@@ -21,7 +21,7 @@ export interface Define<State> {
* import { define } from "../utils.ts";
*
* export const handler = define.handlers((ctx) => {
* ctx.url; // ctx is inferred to be a FreshContext object, so this is a URL
* ctx.url; // ctx is inferred to be a Context object, so this is a URL
* return new Response("Hello, world!");
* });
* ```
@@ -70,7 +70,7 @@ export interface Define<State> {
* import { define } from "../utils.ts";
*
* export default define.page((props) => {
* const slug = props.params.slug; // Because props is inferred to be a FreshContext object, slug is inferred to be a string
* const slug = props.params.slug; // Because props is inferred to be a Context object, slug is inferred to be a string
* return <h1>{slug}</h1>;
* });
* ```
@@ -124,7 +124,7 @@ export interface Define<State> {
* import { define } from "../utils.ts";
*
* export const middleware = define.middleware((ctx) => {
* ctx.url; // ctx is inferred to be a FreshContext object, so this is a URL
* ctx.url; // ctx is inferred to be a Context object, so this is a URL
* return ctx.next();
* });
* ```
+3 -3
View File
@@ -1,4 +1,4 @@
import type { FreshContext } from "./context.ts";
import type { Context } from "./context.ts";
import type { Method } from "./router.ts";
export interface PageResponse<T> {
@@ -106,7 +106,7 @@ export function isHandlerByMethod<D, S>(
/**
* A handler function that is invoked when a request is made to a route. The
* handler function is passed a {@link FreshContext} object that contains the
* handler function is passed a {@link Context} object that contains the
* original request object, as well as any state related to the current request.
*
* The handler function can either return a {@link Response} object, which will
@@ -191,7 +191,7 @@ export function isHandlerByMethod<D, S>(
* ```
*/
export interface HandlerFn<Data, State> {
(ctx: FreshContext<State>):
(ctx: Context<State>):
| Response
| PageResponse<Data>
| Promise<Response | PageResponse<Data>>;
+2 -2
View File
@@ -34,8 +34,8 @@ export type CORSOptions<State> = {
/**
* CORS Middleware to set [`Cross-Origin-Resource-Sharing`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/CORS) headers.
*
* @param {CORSOptions} [options] - The options for the CORS middleware.
* @returns {(req: Request, ctx: FreshContext) => Promise<Response>} The Fresh middleware handler function.
* @param [options] - The options for the CORS middleware.
* @returns The Fresh middleware handler function.
*
* @example
* ```ts