From 138d4c457cc349a8c6178011a3b23ab629aa1dd3 Mon Sep 17 00:00:00 2001 From: Marvin Hagemeister Date: Thu, 27 Jun 2024 12:34:56 +0200 Subject: [PATCH] fix: remove unnecessary URL allocation (#2554) --- src/app.ts | 1 + src/context.ts | 3 ++- src/test_utils.ts | 1 + www/routes/thanks.tsx | 3 +-- 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/app.ts b/src/app.ts index 790c1d50..86bbe2e6 100644 --- a/src/app.ts +++ b/src/app.ts @@ -203,6 +203,7 @@ export class App { const { params, handlers } = matched; const ctx = new FreshReqContext( req, + url, conn, params, this.config, diff --git a/src/context.ts b/src/context.ts index f9b0d778..12e00ada 100644 --- a/src/context.ts +++ b/src/context.ts @@ -111,6 +111,7 @@ export class FreshReqContext constructor( req: Request, + url: URL, info: Deno.ServeHandlerInfo | Deno.ServeUnixHandlerInfo, params: Record, config: ResolvedFreshConfig, @@ -118,7 +119,7 @@ export class FreshReqContext islandRegistry: ServerIslandRegistry, buildCache: BuildCache, ) { - this.url = new URL(req.url); + this.url = url; this.req = req; this.info = info; this.params = params; diff --git a/src/test_utils.ts b/src/test_utils.ts index 59bab7f9..68e678cc 100644 --- a/src/test_utils.ts +++ b/src/test_utils.ts @@ -78,6 +78,7 @@ export function serveMiddleware( const ctx = new FreshReqContext( req, + new URL(req.url), DEFAULT_CONN_INFO, {}, config, diff --git a/www/routes/thanks.tsx b/www/routes/thanks.tsx index b509fd77..afbe4b7f 100644 --- a/www/routes/thanks.tsx +++ b/www/routes/thanks.tsx @@ -5,8 +5,7 @@ import { define } from "../utils/state.ts"; export const handler = define.handlers({ GET(ctx) { - const url = new URL(ctx.req.url); - const search = new URLSearchParams(url.search); + const search = new URLSearchParams(ctx.url.search); const vote = search.get("vote"); return page({ vote }); },