diff --git a/blocks/section.ts b/blocks/section.ts index a4ce6d9da..35aa6248d 100644 --- a/blocks/section.ts +++ b/blocks/section.ts @@ -73,7 +73,8 @@ export interface SectionModule< ReturnType>, PreactComponent > { - LoadingFallback?: ComponentType; + // Fix this ComponentType + LoadingFallback?: ComponentType; ErrorFallback?: ComponentType<{ error?: Error }>; loader?: PropsLoader; action?: PropsLoader; diff --git a/components/section.tsx b/components/section.tsx index a9d01483d..5021e481b 100644 --- a/components/section.tsx +++ b/components/section.tsx @@ -3,7 +3,7 @@ import { Component, type ComponentType, createContext, Fragment } from "preact"; import { useContext } from "preact/hooks"; import type { HttpContext } from "../blocks/handler.ts"; import type { RequestState } from "../blocks/utils.tsx"; -import { Context } from "../deco.ts"; +import { Context, RequestContext } from "../deco.ts"; import { Murmurhash3 } from "../deps.ts"; import type { ComponentFunc } from "../engine/block.ts"; import type { FieldResolver } from "../engine/core/resolver.ts"; @@ -17,7 +17,7 @@ export interface SectionContext extends HttpContext { renderSalt?: string; device: Device; framework: "fresh" | "htmx"; - deploymentId?: string + deploymentId?: string; } export const SectionContext = createContext( @@ -146,6 +146,11 @@ export const withSection = ( }; let device: Device | null = null; + /** + * Get the signal created during the request; + */ + const signal = RequestContext.signal; + return { props, Component: (props: TProps) => { @@ -162,6 +167,12 @@ export const withSection = ( const id = `${idPrefix}-${renderSalt}`; // all children of the same parent will have the same renderSalt, but different renderCount renderCount = ++renderCount % MAX_RENDER_COUNT; + const Throw = () => { + // If the signal from request is aborted, then throw + signal?.throwIfAborted(); + return null; + }; + return ( ( loading={() => ( {/* @ts-ignore difficult typing this */} - + >(props, { + get: (value: Partial, prop) => { + try { + return Reflect.get(value, prop); + } catch (_) { + return undefined; + } + }, + })} + /> )} error={({ error }) => ( @@ -204,6 +225,7 @@ export const withSection = ( ) )} > + {} diff --git a/deno.json b/deno.json index 460fb2fb9..5255ea233 100644 --- a/deno.json +++ b/deno.json @@ -35,7 +35,7 @@ "preact": "https://esm.sh/preact@10.16.0?pin=102", "partytown/": "https://deno.land/x/partytown@0.3.0/", "std/": "https://deno.land/std@0.203.0/", - "$fresh/": "https://denopkg.com/denoland/fresh@1.6.5/", + "$fresh/": "https://denopkg.com/denoland/fresh@1.6.8/", "deco/": "./" }, "compilerOptions": {