From 060f87c43088e68960897a5e0bb968616dab0d3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20De=20Boey?= Date: Tue, 25 Apr 2023 20:29:49 +0200 Subject: [PATCH 1/2] feat: support async `getLoadContext` in all adapters --- packages/remix-architect/server.ts | 4 ++-- packages/remix-cloudflare-pages/worker.ts | 6 +++--- packages/remix-cloudflare-workers/worker.ts | 8 +++++--- packages/remix-express/server.ts | 4 ++-- packages/remix-netlify/server.ts | 4 ++-- packages/remix-vercel/server.ts | 4 ++-- 6 files changed, 16 insertions(+), 14 deletions(-) diff --git a/packages/remix-architect/server.ts b/packages/remix-architect/server.ts index cbbfa9f1bd6..15ec86c157c 100644 --- a/packages/remix-architect/server.ts +++ b/packages/remix-architect/server.ts @@ -29,7 +29,7 @@ import { isBinaryType } from "./binaryTypes"; */ export type GetLoadContextFunction = ( event: APIGatewayProxyEventV2 -) => AppLoadContext; +) => Promise | AppLoadContext; export type RequestHandler = APIGatewayProxyHandlerV2; @@ -50,7 +50,7 @@ export function createRequestHandler({ return async (event) => { let request = createRemixRequest(event); - let loadContext = getLoadContext?.(event); + let loadContext = await getLoadContext?.(event); let response = (await handleRequest(request, loadContext)) as NodeResponse; diff --git a/packages/remix-cloudflare-pages/worker.ts b/packages/remix-cloudflare-pages/worker.ts index 5f1c70e15a2..5b4034a803f 100644 --- a/packages/remix-cloudflare-pages/worker.ts +++ b/packages/remix-cloudflare-pages/worker.ts @@ -10,7 +10,7 @@ import { createRequestHandler as createRemixRequestHandler } from "@remix-run/cl */ export type GetLoadContextFunction = ( context: Parameters>[0] -) => AppLoadContext; +) => Promise | AppLoadContext; export type RequestHandler = PagesFunction; @@ -27,8 +27,8 @@ export function createRequestHandler({ }: createPagesFunctionHandlerParams): RequestHandler { let handleRequest = createRemixRequestHandler(build, mode); - return (context) => { - let loadContext = getLoadContext?.(context); + return async (context) => { + let loadContext = await getLoadContext?.(context); return handleRequest(context.request, loadContext); }; diff --git a/packages/remix-cloudflare-workers/worker.ts b/packages/remix-cloudflare-workers/worker.ts index c783121b2ff..db54b63bd9d 100644 --- a/packages/remix-cloudflare-workers/worker.ts +++ b/packages/remix-cloudflare-workers/worker.ts @@ -17,7 +17,9 @@ import { createRequestHandler as createRemixRequestHandler } from "@remix-run/cl * You can think of this as an escape hatch that allows you to pass * environment/platform-specific values through to your loader/action. */ -export type GetLoadContextFunction = (event: FetchEvent) => AppLoadContext; +export type GetLoadContextFunction = ( + event: FetchEvent +) => Promise | AppLoadContext; export type RequestHandler = (event: FetchEvent) => Promise; @@ -36,8 +38,8 @@ export function createRequestHandler({ }): RequestHandler { let handleRequest = createRemixRequestHandler(build, mode); - return (event: FetchEvent) => { - let loadContext = getLoadContext?.(event); + return async (event: FetchEvent) => { + let loadContext = await getLoadContext?.(event); return handleRequest(event.request, loadContext); }; diff --git a/packages/remix-express/server.ts b/packages/remix-express/server.ts index 009652fd36c..76abf32c5ee 100644 --- a/packages/remix-express/server.ts +++ b/packages/remix-express/server.ts @@ -24,7 +24,7 @@ import { export type GetLoadContextFunction = ( req: express.Request, res: express.Response -) => AppLoadContext; +) => Promise | AppLoadContext; export type RequestHandler = ( req: express.Request, @@ -53,7 +53,7 @@ export function createRequestHandler({ ) => { try { let request = createRemixRequest(req, res); - let loadContext = getLoadContext?.(req, res); + let loadContext = await getLoadContext?.(req, res); let response = (await handleRequest( request, diff --git a/packages/remix-netlify/server.ts b/packages/remix-netlify/server.ts index 5932d3f041d..4fe8e139cc1 100644 --- a/packages/remix-netlify/server.ts +++ b/packages/remix-netlify/server.ts @@ -30,7 +30,7 @@ import { isBinaryType } from "./binaryTypes"; export type GetLoadContextFunction = ( event: HandlerEvent, context: HandlerContext -) => AppLoadContext; +) => Promise | AppLoadContext; export type RequestHandler = Handler; @@ -47,7 +47,7 @@ export function createRequestHandler({ return async (event, context) => { let request = createRemixRequest(event); - let loadContext = getLoadContext?.(event, context); + let loadContext = await getLoadContext?.(event, context); let response = (await handleRequest(request, loadContext)) as NodeResponse; diff --git a/packages/remix-vercel/server.ts b/packages/remix-vercel/server.ts index 6707693cbe5..ba32640e756 100644 --- a/packages/remix-vercel/server.ts +++ b/packages/remix-vercel/server.ts @@ -23,7 +23,7 @@ import { export type GetLoadContextFunction = ( req: VercelRequest, res: VercelResponse -) => AppLoadContext; +) => Promise | AppLoadContext; export type RequestHandler = ( req: VercelRequest, @@ -47,7 +47,7 @@ export function createRequestHandler({ return async (req, res) => { let request = createRemixRequest(req, res); - let loadContext = getLoadContext?.(req, res); + let loadContext = await getLoadContext?.(req, res); let response = (await handleRequest(request, loadContext)) as NodeResponse; From b575fb6ee0adb1944f7910bb404ac3e01cb4e47f Mon Sep 17 00:00:00 2001 From: Jacob Ebey Date: Tue, 25 Apr 2023 15:53:36 -0700 Subject: [PATCH 2/2] Create async-load-context.md --- .changeset/async-load-context.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 .changeset/async-load-context.md diff --git a/.changeset/async-load-context.md b/.changeset/async-load-context.md new file mode 100644 index 00000000000..334006fc0d9 --- /dev/null +++ b/.changeset/async-load-context.md @@ -0,0 +1,12 @@ +--- +"remix": patch +"@remix-run/architect": patch +"@remix-run/cloudflare": patch +"@remix-run/cloudflare-pages": patch +"@remix-run/cloudflare-workers": patch +"@remix-run/express": patch +"@remix-run/netlify": patch +"@remix-run/vercel": patch +--- + +feat: support async `getLoadContext` in all adapters