File tree Expand file tree Collapse file tree 5 files changed +42
-11
lines changed
Expand file tree Collapse file tree 5 files changed +42
-11
lines changed Original file line number Diff line number Diff line change 1- import type { AppLoadContext , ServerBuild } from "react-router" ;
1+ import type {
2+ AppLoadContext ,
3+ UNSAFE_MiddlewareEnabled as MiddlewareEnabled ,
4+ ServerBuild ,
5+ unstable_InitialContext ,
6+ } from "react-router" ;
27import { createRequestHandler as createReactRouterRequestHandler } from "react-router" ;
38import { readableStreamToString } from "@react-router/node" ;
49import type {
@@ -10,6 +15,8 @@ import type {
1015
1116import { isBinaryType } from "./binaryTypes" ;
1217
18+ type MaybePromise < T > = T | Promise < T > ;
19+
1320/**
1421 * A function that returns the value to use as `context` in route `loader` and
1522 * `action` functions.
@@ -19,7 +26,9 @@ import { isBinaryType } from "./binaryTypes";
1926 */
2027export type GetLoadContextFunction = (
2128 event : APIGatewayProxyEventV2
22- ) => Promise < AppLoadContext > | AppLoadContext ;
29+ ) => MiddlewareEnabled extends true
30+ ? MaybePromise < unstable_InitialContext >
31+ : MaybePromise < AppLoadContext > ;
2332
2433export type RequestHandler = APIGatewayProxyHandlerV2 ;
2534
Original file line number Diff line number Diff line change 1- import type { AppLoadContext , ServerBuild } from "react-router" ;
1+ import type {
2+ AppLoadContext ,
3+ UNSAFE_MiddlewareEnabled as MiddlewareEnabled ,
4+ ServerBuild ,
5+ unstable_InitialContext ,
6+ } from "react-router" ;
27import { createRequestHandler as createReactRouterRequestHandler } from "react-router" ;
38import { type CacheStorage } from "@cloudflare/workers-types" ;
49
10+ type MaybePromise < T > = T | Promise < T > ;
11+
512/**
613 * A function that returns the value to use as `context` in route `loader` and
714 * `action` functions.
@@ -29,7 +36,9 @@ export type GetLoadContextFunction<
2936 caches : CacheStorage ;
3037 } ;
3138 } ;
32- } ) => AppLoadContext | Promise < AppLoadContext > ;
39+ } ) => MiddlewareEnabled extends true
40+ ? MaybePromise < unstable_InitialContext >
41+ : MaybePromise < AppLoadContext > ;
3342
3443export type RequestHandler < Env = any > = PagesFunction < Env > ;
3544
Original file line number Diff line number Diff line change 33/// <reference lib="DOM.Iterable" />
44
55import type * as express from "express" ;
6- import type { AppLoadContext , ServerBuild } from "react-router" ;
6+ import type {
7+ AppLoadContext ,
8+ ServerBuild ,
9+ UNSAFE_MiddlewareEnabled as MiddlewareEnabled ,
10+ unstable_InitialContext ,
11+ } from "react-router" ;
712import { createRequestHandler as createRemixRequestHandler } from "react-router" ;
813import {
914 createReadableStreamFromReadable ,
1015 writeReadableStreamToWritable ,
1116} from "@react-router/node" ;
1217
18+ type MaybePromise < T > = T | Promise < T > ;
19+
1320/**
1421 * A function that returns the value to use as `context` in route `loader` and
1522 * `action` functions.
@@ -21,7 +28,9 @@ import {
2128export type GetLoadContextFunction = (
2229 req : express . Request ,
2330 res : express . Response
24- ) => Promise < AppLoadContext > | AppLoadContext ;
31+ ) => MiddlewareEnabled extends true
32+ ? MaybePromise < unstable_InitialContext >
33+ : MaybePromise < AppLoadContext > ;
2534
2635export type RequestHandler = (
2736 req : express . Request ,
Original file line number Diff line number Diff line change @@ -269,7 +269,10 @@ export type {
269269 FlashSessionData ,
270270} from "./lib/server-runtime/sessions" ;
271271
272- export type { Future } from "./lib/types/future.ts" ;
272+ export type {
273+ Future ,
274+ MiddlewareEnabled as UNSAFE_MiddlewareEnabled ,
275+ } from "./lib/types/future.ts" ;
273276export type { unstable_SerializesTo } from "./lib/types/serializes-to.ts" ;
274277export type { Register } from "./lib/types/register" ;
275278export { href } from "./lib/href" ;
Original file line number Diff line number Diff line change 11import type { StaticHandler , StaticHandlerContext } from "../router/router" ;
2- import type { ErrorResponse } from "../router/utils" ;
2+ import type { ErrorResponse , unstable_InitialContext } from "../router/utils" ;
33import { unstable_RouterContextProvider } from "../router/utils" ;
44import {
55 isRouteErrorResponse ,
@@ -90,11 +90,12 @@ export const createRequestHandler: CreateRequestHandlerFunction = (
9090 return async function requestHandler ( request , _loadContext ) {
9191 _build = typeof build === "function" ? await build ( ) : build ;
9292
93- // TODO: Accept `initialContext` from `getLoadContext` when the flag is enabled
9493 let loadContext : AppLoadContext = _build . future . unstable_middleware
9594 ? // @ts -expect-error This type changes when middleware is enabled
96- ( new unstable_RouterContextProvider ( ) as AppLoadContext )
97- : _loadContext ?? { } ;
95+ ( new unstable_RouterContextProvider (
96+ _loadContext as unknown as unstable_InitialContext
97+ ) as AppLoadContext )
98+ : _loadContext || { } ;
9899
99100 if ( typeof build === "function" ) {
100101 let derived = derive ( _build , mode ) ;
You can’t perform that action at this time.
0 commit comments