Skip to content

feat(vercel): queues#4127

Open
RihanArfan wants to merge 23 commits intomainfrom
feat/vercel-queues
Open

feat(vercel): queues#4127
RihanArfan wants to merge 23 commits intomainfrom
feat/vercel-queues

Conversation

@RihanArfan
Copy link
Copy Markdown
Member

Warning

Waiting on #4124

🔗 Linked issue

Related #1974

❓ Type of change

  • 📖 Documentation (updates to the documentation, readme, or JSdoc annotations)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • 👌 Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

📚 Description

Support Vercel Queues triggers through Nitro hooks, and documents using it with Nitro Tasks.

📝 Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@vercel
Copy link
Copy Markdown

vercel bot commented Mar 18, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
nitro.build Error Error Mar 28, 2026 3:37am

Request Review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 18, 2026

📝 Walkthrough

Walkthrough

Adds Vercel Queues integration to Nitro, including per-route serverless function configuration via vercel.functionRules. Introduces queue trigger registration, message handling hooks, runtime queue consumers, and task dispatch capabilities alongside comprehensive documentation and example projects.

Changes

Cohort / File(s) Summary
Documentation
docs/2.deploy/20.providers/vercel.md, docs/4.examples/vercel-queues.md
Added documentation for per-route function configuration via functionRules and Vercel Queues integration, including queue trigger setup, message handling, and task dispatch patterns.
Example Project - Vercel Queues
examples/vercel-queues/*
New standalone example project demonstrating Nitro with Vercel Queues: includes config, route handler for sending messages, plugin for handling queue callbacks, and a task for processing notifications.
Vercel Preset - Type Definitions
src/presets/vercel/types.ts
Extended VercelOptions with functionRules for per-route config overrides and queues configuration; added vercel:queue hook declaration for runtime queue message handling.
Vercel Preset - Runtime Handler
src/presets/vercel/runtime/queue-handler.ts
New request handler that delegates incoming queue callbacks to Vercel's handleCallback and triggers the vercel:queue Nitro hook.
Vercel Preset - Core Logic
src/presets/vercel/preset.ts, src/presets/vercel/utils.ts
Added queue consumer route registration during build:before hook; refactored utils to support per-route function config via route matching, merged config directory creation, and sanitized consumer naming for queue triggers.
Dependencies
package.json
Added @vercel/queue as a dev dependency.
Test Configuration & Fixtures
test/fixture/nitro.config.ts, test/presets/vercel.test.ts
Extended fixture with vercel.functionRules examples; added comprehensive test suite covering per-route function directory creation, config merging, snapshot assertions, and new queue consumer assertions.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'feat(vercel): queues' follows conventional commits format with a 'feat' type, scope 'vercel', and clear subject about the new queues feature, matching the main changeset addition of Vercel Queues support.
Description check ✅ Passed The description explains the PR adds Vercel Queues trigger support via Nitro hooks and documents integration with Nitro Tasks, which directly relates to all the substantial changes in the changeset including docs, examples, and runtime implementation.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/vercel-queues
⚔️ Resolve merge conflicts
  • Resolve merge conflict in branch feat/vercel-queues

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@RihanArfan RihanArfan marked this pull request as ready for review March 27, 2026 23:36
@RihanArfan RihanArfan requested a review from pi0 as a code owner March 27, 2026 23:36
Base automatically changed from feat/vercel-per-function-config to main March 27, 2026 23:55
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (1)
src/presets/vercel/runtime/queue-handler.ts (1)

9-11: Remove the unnecessary type cast as Request.

The event.req object is already a Request instance in the Vercel runtime context (as evidenced by cron-handler.ts using event.req.headers.get() and event.req.waitUntil without casting). The type cast is redundant and should be removed for consistency with other handlers:

return handler(event.req);

instead of:

return handler(event.req as Request);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/presets/vercel/runtime/queue-handler.ts` around lines 9 - 11, The return
statement in the defineHandler wrapper unnecessarily casts event.req to Request;
update the defineHandler callback so it calls handler(event.req) without the
redundant "as Request" cast (locate the defineHandler(...) wrapper and the call
to handler in queue-handler.ts and remove the type assertion on event.req).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@docs/2.deploy/20.providers/vercel.md`:
- Around line 58-86: The docs incorrectly reference vercel.routeFunctionConfig;
update all occurrences (text and the example in the nitro config) to use
vercel.functionRules so the sample matches the implementation/types;
specifically replace the symbol vercel.routeFunctionConfig with
vercel.functionRules in the example config block and any explanatory text, and
keep the rest of the example keys (e.g., maxDuration, memory, regions,
experimentalTriggers) unchanged.

In `@examples/vercel-queues/package.json`:
- Around line 3-12: The package.json scripts reference Vite ("dev": "vite dev",
"build": "vite build") but Vite is not listed in devDependencies; update the
devDependencies section to include "vite" (e.g., add a "vite": "latest" or
specific version) so the "dev" and "build" scripts resolve reliably alongside
existing entries like "nitro".

In `@src/presets/vercel/utils.ts`:
- Around line 64-69: Typo fix: change "accesible" to "accessible" in the warning
message. Update the string passed to nitro.logger.warn that references
`experimentalTriggers` on `vercel.functions` so the sentence reads "Routes with
queue triggers are not accessible on the web." Keep the rest of the message
intact and ensure references to `vercel.functionRules` remain unchanged.

---

Nitpick comments:
In `@src/presets/vercel/runtime/queue-handler.ts`:
- Around line 9-11: The return statement in the defineHandler wrapper
unnecessarily casts event.req to Request; update the defineHandler callback so
it calls handler(event.req) without the redundant "as Request" cast (locate the
defineHandler(...) wrapper and the call to handler in queue-handler.ts and
remove the type assertion on event.req).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 51894fd6-4700-46c8-8dc2-c7adc93647c3

📥 Commits

Reviewing files that changed from the base of the PR and between 589e8ad and 5fe65f0.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (17)
  • docs/2.deploy/20.providers/vercel.md
  • docs/4.examples/vercel-queues.md
  • examples/vercel-queues/README.md
  • examples/vercel-queues/nitro.config.ts
  • examples/vercel-queues/package.json
  • examples/vercel-queues/plugins/queue.ts
  • examples/vercel-queues/routes/send.ts
  • examples/vercel-queues/tasks/notifications/send.ts
  • examples/vercel-queues/tsconfig.json
  • examples/vercel-queues/vite.config.ts
  • package.json
  • src/presets/vercel/preset.ts
  • src/presets/vercel/runtime/queue-handler.ts
  • src/presets/vercel/types.ts
  • src/presets/vercel/utils.ts
  • test/fixture/nitro.config.ts
  • test/presets/vercel.test.ts

Comment on lines +58 to +86
## Per-route function configuration

Use `vercel.routeFunctionConfig` to override [serverless function settings](https://vercel.com/docs/build-output-api/primitives#serverless-function-configuration) for specific routes. Each key is a route pattern and its value is a partial function configuration object that gets merged with the base `vercel.functions` config. Note: array properties (e.g., `regions`) from route config will replace the base config arrays rather than merging them.

This is useful when certain routes need different resource limits, regions, or features like [Vercel Queues triggers](https://vercel.com/docs/queues).

```ts [nitro.config.ts]
import { defineNitroConfig } from "nitro/config";

export default defineNitroConfig({
vercel: {
routeFunctionConfig: {
"/api/heavy-computation": {
maxDuration: 800,
memory: 4096,
},
"/api/regional": {
regions: ["lhr1", "cdg1"],
},
"/api/queues/process-order": {
experimentalTriggers: [{ type: "queue/v2beta", topic: "orders" }],
},
},
},
});
```

Route patterns support wildcards via [rou3](https://github.com/h3js/rou3) matching (e.g., `/api/slow/**` matches all routes under `/api/slow/`).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify the actual property name in types
rg -n "routeFunctionConfig|functionRules" src/presets/vercel/types.ts

Repository: nitrojs/nitro

Length of output: 152


🏁 Script executed:

# Search for routeFunctionConfig anywhere in the codebase
rg "routeFunctionConfig" --type ts --type js --type md

# Also check the implementation to see what property is actually read
rg -n "functionRules" src/presets/vercel/ -A 2 -B 2

Repository: nitrojs/nitro

Length of output: 4432


Documentation uses incorrect property name routeFunctionConfig; should be functionRules.

The documentation references vercel.routeFunctionConfig but the actual TypeScript types and implementation use vercel.functionRules. Users following the documentation will have their configuration silently ignored by the build process.

📝 Suggested fix
-Use `vercel.routeFunctionConfig` to override [serverless function settings](https://vercel.com/docs/build-output-api/primitives#serverless-function-configuration) for specific routes.
+Use `vercel.functionRules` to override [serverless function settings](https://vercel.com/docs/build-output-api/primitives#serverless-function-configuration) for specific routes.
   vercel: {
-    routeFunctionConfig: {
+    functionRules: {
       "/api/heavy-computation": {
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@docs/2.deploy/20.providers/vercel.md` around lines 58 - 86, The docs
incorrectly reference vercel.routeFunctionConfig; update all occurrences (text
and the example in the nitro config) to use vercel.functionRules so the sample
matches the implementation/types; specifically replace the symbol
vercel.routeFunctionConfig with vercel.functionRules in the example config block
and any explanatory text, and keep the rest of the example keys (e.g.,
maxDuration, memory, regions, experimentalTriggers) unchanged.

Comment on lines +3 to +12
"scripts": {
"dev": "vite dev",
"build": "vite build"
},
"dependencies": {
"@vercel/queue": "latest"
},
"devDependencies": {
"nitro": "latest"
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Missing vite dependency.

The scripts use vite dev and vite build, but vite is not declared as a dependency. Add it to devDependencies.

Proposed fix
   "devDependencies": {
-    "nitro": "latest"
+    "nitro": "latest",
+    "vite": "latest"
   }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
"scripts": {
"dev": "vite dev",
"build": "vite build"
},
"dependencies": {
"@vercel/queue": "latest"
},
"devDependencies": {
"nitro": "latest"
}
"scripts": {
"dev": "vite dev",
"build": "vite build"
},
"dependencies": {
"@vercel/queue": "latest"
},
"devDependencies": {
"nitro": "latest",
"vite": "latest"
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@examples/vercel-queues/package.json` around lines 3 - 12, The package.json
scripts reference Vite ("dev": "vite dev", "build": "vite build") but Vite is
not listed in devDependencies; update the devDependencies section to include
"vite" (e.g., add a "vite": "latest" or specific version) so the "dev" and
"build" scripts resolve reliably alongside existing entries like "nitro".

Comment on lines +64 to +69
nitro.logger.warn(
"`experimentalTriggers` on the base `vercel.functions` config applies to the catch-all function and is likely not what you want. " +
"Routes with queue triggers are not accesible on the web." +
"Use `vercel.functionRules` to attach triggers to specific routes instead."
);
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Typo: "accesible" should be "accessible".

📝 Fix
     nitro.logger.warn(
       "`experimentalTriggers` on the base `vercel.functions` config applies to the catch-all function and is likely not what you want. " +
-        "Routes with queue triggers are not accesible on the web." +
+        "Routes with queue triggers are not accessible on the web. " +
         "Use `vercel.functionRules` to attach triggers to specific routes instead."
     );
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
nitro.logger.warn(
"`experimentalTriggers` on the base `vercel.functions` config applies to the catch-all function and is likely not what you want. " +
"Routes with queue triggers are not accesible on the web." +
"Use `vercel.functionRules` to attach triggers to specific routes instead."
);
}
nitro.logger.warn(
"`experimentalTriggers` on the base `vercel.functions` config applies to the catch-all function and is likely not what you want. " +
"Routes with queue triggers are not accessible on the web. " +
"Use `vercel.functionRules` to attach triggers to specific routes instead."
);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/presets/vercel/utils.ts` around lines 64 - 69, Typo fix: change
"accesible" to "accessible" in the warning message. Update the string passed to
nitro.logger.warn that references `experimentalTriggers` on `vercel.functions`
so the sentence reads "Routes with queue triggers are not accessible on the
web." Keep the rest of the message intact and ensure references to
`vercel.functionRules` remain unchanged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants