diff --git a/.changeset/silly-dolphins-pump.md b/.changeset/silly-dolphins-pump.md new file mode 100644 index 000000000..e4bcee62e --- /dev/null +++ b/.changeset/silly-dolphins-pump.md @@ -0,0 +1,5 @@ +--- +"inngest": patch +--- + +Fix serverless use of `inngest/next` with `next@>=13.0.0 <13.5.0` failing to return a response, as well as `next@>=13.5.0` logging the same error diff --git a/packages/inngest/src/next.ts b/packages/inngest/src/next.ts index 28565db65..c832c2d6d 100644 --- a/packages/inngest/src/next.ts +++ b/packages/inngest/src/next.ts @@ -14,6 +14,8 @@ export const frameworkName: SupportedFrameworkName = "nextjs"; * In Next.js, serve and register any declared functions with Inngest, making * them available to be triggered by events. * + * Supports Next.js 12+, both serverless and edge. + * * @example Next.js <=12 or the pages router can export the handler directly * ```ts * export default serve({ client: inngest, functions: [fn1, fn2] }); @@ -150,15 +152,21 @@ export const serve = (options: ServeHandlerOptions) => { typeof res?.send === "function" ) { res.status(status).send(body); + + /** + * If we're here, we're in a serverless endpoint (not edge), so + * we've correctly sent the response and can return `undefined`. + * + * Next.js 13 edge requires that the return value is typed as + * `Response`, so we still enforce that as we cannot dynamically + * adjust typing based on the environment. + */ + return undefined as unknown as Response; } /** - * Next.js 13 requires that the return value is always `Response`, - * though this serve handler can't understand if we're using 12 or 13. - * - * 12 doesn't seem to care if we also return a response from the - * handler, so we'll just return `undefined` here, which will be safe - * at runtime and enforce types for use with Next.js 13. + * If we're here, we're in an edge environment and need to return a + * `Response` object. * * We also don't know if the current environment has a native * `Response` object, so we'll grab that first.