Skip to content

Commit

Permalink
Check for env before assigning the new render func
Browse files Browse the repository at this point in the history
Signed-off-by: Marcos Candeia <marrcooos@gmail.com>
  • Loading branch information
mcandeia committed Aug 4, 2024
1 parent 57ff539 commit efadad3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion runtime/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export interface DecoOptions<TAppManifest extends AppManifest = AppManifest> {
}

export class Deco<TAppManifest extends AppManifest = AppManifest> {
private _handler: ReturnType<typeof handlerFor> | null = null;
private constructor(
public site: string,
private ctx: DecoContext<TAppManifest>,
Expand Down Expand Up @@ -82,7 +83,10 @@ export class Deco<TAppManifest extends AppManifest = AppManifest> {
}

get handler() {
return handlerFor(this);
return this._handler ??= handlerFor(this);
}
get fetch() {
return (req: Request) => this.handler(req);
}

async resolve<T, TContext extends BaseContext>(
Expand Down
2 changes: 1 addition & 1 deletion runtime/handler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export const handlerFor = <TAppManifest extends AppManifest = AppManifest>(
const bindings = deco.bindings;
const hono = bindings?.server ?? new Hono<DecoRouteState<TAppManifest>>();
hono.use(async (ctx, next) => {
const renderFn = ctx.env.RENDER_FN ?? bindings?.renderer?.renderFn;
const renderFn = ctx.env?.RENDER_FN ?? bindings?.renderer?.renderFn;
renderFn && ctx.setRenderer(
renderFn,
);
Expand Down

0 comments on commit efadad3

Please sign in to comment.