feat(vercel): support queues in local dev#4264
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
📝 WalkthroughWalkthroughThis PR adds local development support for Vercel Queues in Nitro by introducing a new ChangesVercel Queues Local Development
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint skipped: no ESLint configuration detected in root package.json. To enable, add 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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
src/presets/vercel/runtime/queue.dev.ts (1)
50-53: ⚡ Quick winAvoid silent teardown failures in
closehookThe empty
catchhides unregister failures, making local queue teardown issues hard to diagnose. Log/capture the error instead of swallowing it.Suggested diff
nitroApp.hooks.hook("close", () => { for (const unregister of unregisters) { try { unregister(); - } catch {} + } catch (error) { + nitroApp.captureError?.(error as Error, { + tags: ["vercel:queue", "close"], + }); + } } });🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/presets/vercel/runtime/queue.dev.ts` around lines 50 - 53, The close hook currently swallows errors from unregister() with an empty catch; update the catch to capture the exception and log it (e.g., catch (err) { console.error('Failed to unregister local queue in close hook:', err) } or use an existing logger like processLogger.error) so failures in unregister() are visible; keep the call to unregister() and ensure the log includes context and the error object for debugging.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/presets/vercel/runtime/queue.dev.ts`:
- Line 36: Replace the direct console.error call in queue.dev.ts with the
preset/dev logger: use nitroApp.logger.error(...) if a nitroApp instance is in
scope, otherwise import and use consola.error(...); specifically change the
console.error("[vercel:queue]", error) invocation to call the appropriate
logger, and add the required import or ensure nitroApp is available in the
surrounding function where the error is handled.
- Line 5: The import path and symbol are wrong: replace the import of
registerVercelQueueConsumer from "env-runner/runners/vercel/queue-dev" with the
correct export from "env-runner/runners/vercel" (verify the exact exported
function name in that package and update the import to match), update any
references to registerVercelQueueConsumer if the exported name differs, change
the console.error call at the place currently using console.error to
consola.error, and inside the teardown catch block (the empty catch around
teardown logic) add explicit error handling/logging (e.g., log the error via
consola.error with context) so errors are not silently swallowed.
---
Nitpick comments:
In `@src/presets/vercel/runtime/queue.dev.ts`:
- Around line 50-53: The close hook currently swallows errors from unregister()
with an empty catch; update the catch to capture the exception and log it (e.g.,
catch (err) { console.error('Failed to unregister local queue in close hook:',
err) } or use an existing logger like processLogger.error) so failures in
unregister() are visible; keep the call to unregister() and ensure the log
includes context and the error object for debugging.
🪄 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: 9ccb08c1-7a29-4496-bf7c-d75f658bd36e
📒 Files selected for processing (5)
docs/2.deploy/20.providers/vercel.mdsrc/presets/_types.gen.tssrc/presets/vercel/dev.tssrc/presets/vercel/preset.tssrc/presets/vercel/runtime/queue.dev.ts
| import type { MessageMetadata } from "@vercel/queue"; | ||
| import type { NitroAppPlugin } from "nitro/types"; | ||
| import { useRuntimeConfig } from "nitro/runtime-config"; | ||
| import { registerVercelQueueConsumer } from "env-runner/runners/vercel/queue-dev"; |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "1) Locate any queue-dev implementation in repo:"
fd -i 'queue-dev.ts|queue-dev.mjs|queue-dev.js'
echo
echo "2) Find all usages of registerVercelQueueConsumer:"
rg -n --type=ts -C3 '\bregisterVercelQueueConsumer\b'
echo
echo "3) Find all imports from env-runner in TS files:"
rg -n --type=ts -C2 'from "env-runner[^"]*"'
echo
echo "4) Check alias/path mapping for env-runner:"
fd -i 'tsconfig*.json' --exec sh -c 'echo "--- $1"; jq ".compilerOptions.paths // {}" "$1"' sh {}Repository: nitrojs/nitro
Length of output: 30841
🏁 Script executed:
# Check if env-runner is listed as a dependency
fd -i 'package.json' -type f | head -5 | xargs -I {} sh -c 'echo "=== {} ==="; cat "{}" | grep -A 50 -B 5 "env-runner" || true'Repository: nitrojs/nitro
Length of output: 228
🌐 Web query:
env-runner npm package runners/vercel/queue-dev
💡 Result:
The string “env-runner npm package runners/vercel/queue-dev” doesn’t resolve cleanly to a specific, documented npm package path or file name in the sources I found. What I could confirm: 1) The npm package “env-runner” (unjs/env-runner) exists and provides “runners” including a Vercel runner at the import path env-runner/runners/vercel (not “queue-dev”). It also documents that it can run across multiple environments/runtimes and exposes a Vercel runner that simulates a Vercel deployment environment with Vercel-like header injection. [1][2] 2) Vercel-specific behavior for env-runner is implemented via “VercelEnvRunner”. Its changes include injection of Vercel-related request headers such as x-vercel-deployment-url and x-vercel-id, and it sets process.env values like VERCEL, VERCEL_ENV, VERCEL_REGION, and NOW_REGION in the worker context. [3][4] 3) Vercel Queues are a separate Vercel product (queues durable event streaming). Vercel’s own docs describe authentication and API behavior for Queues, but those docs don’t mention an env-runner “queue-dev” runner. [5][6] If you meant something else by “queue-dev” (for example, a specific file/directory name inside env-runner like runners/vercel/queue-dev, or a tag/example used for local queue development), tell me one of the following and I can re-search precisely: - the full npm package name (including scope/version) you intend, or - the exact GitHub file path you saw (repo + path), or - a snippet of the import/require statement you’re using. Citations: - env-runner README shows available runners and explicitly includes VercelEnvRunner at env-runner/runners/vercel and describes Vercel context/header injection. [1] - env-runner repository overview similarly lists Vercel runner and its purpose. [2] - env-runner commit implementing Vercel env var + header injection (VercelEnvRunner). [3] - env-runner commit adding VERCEL_DEPLOYMENT_ID and testing it in VercelEnvRunner. [4] - Vercel Queues docs (product/API) don’t reference env-runner “queue-dev”. [5][6]
Citations:
- 1: https://github.com/unjs/env-runner/blob/main/README.md
- 2: https://github.com/unjs/env-runner
- 3: unjs/env-runner@caa3625
- 4: unjs/env-runner@d8e4071
- 5: https://vercel.com/docs/queues
- 6: https://vercel.com/docs/queues/api
🌐 Web query:
registerVercelQueueConsumer env-runner function
💡 Result:
There is no documented function named registerVercelQueueConsumer in either the Vercel Queues SDK/docs or the unjs/env-runner project docs. What you likely want (Vercel Queues “push-mode” consumer registration): 1) Configure your consumer endpoint trigger in vercel.json using a queue/v2beta experimentalTriggers entry for your route. Vercel invokes that route automatically in push mode. [1][2][3] Example: { "functions": { "app/api/queues/process-order/route.ts": { "experimentalTriggers": [{ "type": "queue/v2beta", "topic": "orders" }] } } } 2) Export your handler using @vercel/queue’s handleCallback (or handleNodeCallback for certain routers). Messages are acknowledged when your handler completes and retried if the handler throws. [4][3][5] Example: import { handleCallback } from '@vercel/queue'; export const POST = handleCallback(async (message, metadata) => { await processOrder(message); }); How unjs/env-runner fits in: - env-runner is a generic runtime “environment runner” (it can simulate Vercel via VercelEnvRunner), but its docs don’t mention any Vercel Queue consumer registration helper like registerVercelQueueConsumer. [6][7] - So, in practice, you would still register a Vercel Queues consumer the Vercel way (vercel.json trigger + handleCallback handler), while env-runner may help simulate the Vercel runtime environment during local testing. [6][7][5] If you can share where you saw “registerVercelQueueConsumer” (repo/package/link or the relevant file), I can pinpoint whether it’s from a different library or an internal wrapper and map it to the equivalent Vercel Queues APIs.
Citations:
- 1: https://vercel.co/docs/queues/quickstart
- 2: https://vercel.com/docs/queues
- 3: https://vercel.com/docs/queues/quickstart
- 4: https://vercel.co/docs/queues/sdk
- 5: https://vercel.com/docs/queues/sdk
- 6: https://github.com/unjs/env-runner
- 7: https://github.com/unjs/env-runner/blob/main/README.md
🏁 Script executed:
# Also check the file to understand what this function is supposed to do
cat -n src/presets/vercel/runtime/queue.dev.ts | head -60Repository: nitrojs/nitro
Length of output: 2055
Critical: unresolved env-runner/runners/vercel/queue-dev import path
This import does not exist in the env-runner package. The package provides env-runner/runners/vercel but not a queue-dev subpath, and registerVercelQueueConsumer is not an exported function. Verify the correct import path and function name.
Additionally:
- Line 36: replace
console.errorwithconsola.error(required forsrc/presets/**) - Lines 50–52: empty catch block silently swallows teardown errors; add explicit error handling or logging
🧰 Tools
🪛 GitHub Check: tests-checks (ubuntu-latest)
[failure] 5-5:
Cannot find module 'env-runner/runners/vercel/queue-dev' or its corresponding type declarations.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/presets/vercel/runtime/queue.dev.ts` at line 5, The import path and
symbol are wrong: replace the import of registerVercelQueueConsumer from
"env-runner/runners/vercel/queue-dev" with the correct export from
"env-runner/runners/vercel" (verify the exact exported function name in that
package and update the import to match), update any references to
registerVercelQueueConsumer if the exported name differs, change the
console.error call at the place currently using console.error to consola.error,
and inside the teardown catch block (the empty catch around teardown logic) add
explicit error handling/logging (e.g., log the error via consola.error with
context) so errors are not silently swallowed.
| send, | ||
| }); | ||
| } catch (error) { | ||
| console.error("[vercel:queue]", error); |
There was a problem hiding this comment.
🛠️ Refactor suggestion | 🟠 Major | ⚡ Quick win
Use Nitro/consola logger instead of console.error
Switch this to nitroApp.logger (or consola) to keep logging consistent with preset/dev conventions.
Suggested diff
- console.error("[vercel:queue]", error);
+ nitroApp.logger.error("[vercel:queue]", error);As per coding guidelines src/{build,dev,cli,presets}/**/*.{ts,js,mjs}: Use consola for logging in build/dev code, or nitro.logger when available.
📝 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.
| console.error("[vercel:queue]", error); | |
| nitroApp.logger.error("[vercel:queue]", error); |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/presets/vercel/runtime/queue.dev.ts` at line 36, Replace the direct
console.error call in queue.dev.ts with the preset/dev logger: use
nitroApp.logger.error(...) if a nitroApp instance is in scope, otherwise import
and use consola.error(...); specifically change the
console.error("[vercel:queue]", error) invocation to call the appropriate
logger, and add the required import or ensure nitroApp is available in the
surrounding function where the error is handled.
🔗 Linked issue
#4127
Blocked by unjs/env-runner#16
❓ Type of change
📚 Description
Support Vercel Queues during local development. Calling
send()from@vercel/queuewill call the consumers registered withinnitro.config.ts.Also introduces usage of Vercel env-runner preset during dev when Vercel preset is set.
📝 Checklist