Skip to content

Commit 7f42bc1

Browse files
committed
fix: handle void hook result
1 parent f4ceeee commit 7f42bc1

3 files changed

Lines changed: 14 additions & 8 deletions

File tree

src/presets/cloudflare/runtime/_module-handler.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export function createHandler<Env>(hooks: {
5050
controller,
5151
env,
5252
context,
53-
})
53+
}) || Promise.resolve()
5454
);
5555
if (import.meta._tasks) {
5656
context.waitUntil(
@@ -75,7 +75,7 @@ export function createHandler<Env>(hooks: {
7575
event: message, // backward compat
7676
env,
7777
context,
78-
})
78+
}) || Promise.resolve()
7979
);
8080
},
8181

@@ -87,7 +87,7 @@ export function createHandler<Env>(hooks: {
8787
event: batch,
8888
env,
8989
context,
90-
})
90+
}) || Promise.resolve()
9191
);
9292
},
9393

@@ -98,7 +98,7 @@ export function createHandler<Env>(hooks: {
9898
traces,
9999
env,
100100
context,
101-
})
101+
}) || Promise.resolve()
102102
);
103103
},
104104

@@ -109,7 +109,7 @@ export function createHandler<Env>(hooks: {
109109
traces,
110110
env,
111111
context,
112-
})
112+
}) || Promise.resolve()
113113
);
114114
},
115115
} satisfies ExportedHandler<Env>;

src/presets/cloudflare/runtime/cloudflare-durable.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export class $DurableObject extends DurableObject {
6464
nitroHooks.callHook("cloudflare:durable:init", this, {
6565
state,
6666
env,
67-
})
67+
}) || Promise.resolve()
6868
);
6969
if (hasWebSocket) {
7070
ws!.handleDurableInit(this, state, env);
@@ -83,7 +83,9 @@ export class $DurableObject extends DurableObject {
8383
}
8484

8585
override alarm(): void | Promise<void> {
86-
this.ctx.waitUntil(nitroHooks.callHook("cloudflare:durable:alarm", this));
86+
this.ctx.waitUntil(
87+
nitroHooks.callHook("cloudflare:durable:alarm", this) || Promise.resolve()
88+
);
8789
}
8890

8991
override async webSocketMessage(

src/runtime/internal/app.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,11 @@ function createNitroApp(): NitroApp {
112112
if (errors) {
113113
errors.push({ error, context: errorCtx });
114114
}
115-
if (hasHooks && typeof errorCtx.event.req.waitUntil === "function") {
115+
if (
116+
hasHooks &&
117+
promise &&
118+
typeof errorCtx.event.req.waitUntil === "function"
119+
) {
116120
errorCtx.event.req.waitUntil(promise);
117121
}
118122
}

0 commit comments

Comments
 (0)