diff --git a/deno.json b/deno.json index 836369373..fe55e644d 100644 --- a/deno.json +++ b/deno.json @@ -9,7 +9,7 @@ "std/": "https://deno.land/std@0.204.0/", "partytown/": "https://deno.land/x/partytown@0.4.8/", "deco-sites/std/": "https://denopkg.com/deco-sites/std@1.24.2/", - "deco/": "https://denopkg.com/deco-cx/deco@17e82e5da44aaee2e1932fe5944e07d493ea7cee/" + "deco/": "https://denopkg.com/deco-cx/deco@d3fda66b4845932da3e8039be36289166d1053da/" }, "lock": false, "tasks": { diff --git a/website/handlers/fresh.ts b/website/handlers/fresh.ts index 83cbe339c..9342b0c6e 100644 --- a/website/handlers/fresh.ts +++ b/website/handlers/fresh.ts @@ -1,6 +1,6 @@ import { HandlerContext } from "$fresh/server.ts"; import { Page } from "deco/blocks/page.tsx"; -import { CancelationToken } from "deco/deco.ts"; +import { RequestContext } from "deco/deco.ts"; import { asResolved, BaseContext, @@ -31,7 +31,10 @@ export const isFreshCtx = ( */ export default function Fresh( freshConfig: FreshConfig, - appContext: Pick, + appContext: Pick< + AppContext, + "monitoring" | "response" | "caching" | "firstByteThresholdMS" + >, ) { return async (req: Request, ctx: ConnInfo) => { if (req.method === "HEAD") { @@ -44,24 +47,28 @@ export default function Fresh( // Setup abort signals const ctrl = new AbortController(); - CancelationToken.set(ctrl.signal); + req.signal.addEventListener("abort", () => ctrl.abort()); // Add more cases when not allowed to abort due to MAX_AWAIT_TIME - const delay = appContext.delay || 100; + const delay = Number(appContext.firstByteThresholdMS); if (asJson == null && delay) { setTimeout(() => ctrl.abort(), delay); } + const getPage = RequestContext.bind( + { signal: ctrl.signal }, + async () => + isDeferred(freshConfig.page) + ? await freshConfig.page({ context: ctx }) + : freshConfig.page, + ); + const page = await appContext?.monitoring?.tracer?.startActiveSpan?.( "load-data", async (span) => { try { - return isDeferred( - freshConfig.page, - ) - ? await freshConfig.page({ context: ctx }) - : freshConfig.page; + return await getPage(); } catch (e) { span.recordException(e); throw e; diff --git a/website/mod.ts b/website/mod.ts index adaeab888..9ab24bd1a 100644 --- a/website/mod.ts +++ b/website/mod.ts @@ -66,10 +66,10 @@ export interface Props { /** * @title Async Rendering - * @description Number of milliseconds to wait before rendering preview. Set to 0 to disable it + * @description Number of milliseconds to wait before rendering preview. Set to 0 to disable it. * @default 0 */ - delay?: number; + firstByteThresholdMS?: 0 | 100 | 300 | 500 | 700; } /**