Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't return a Response in inngest/next if in serverless #421

Merged
merged 2 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/silly-dolphins-pump.md
Original file line number Diff line number Diff line change
@@ -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
20 changes: 14 additions & 6 deletions packages/inngest/src/next.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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] });
Expand Down Expand Up @@ -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.
Expand Down
Loading