feat: export http utils from nitro#4097
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
📝 WalkthroughWalkthroughUpdated many docs and example imports to use Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
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 |
commit: |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
src/runtime/nitro.ts (1)
15-17: Drop the new section comment.The
// H3 handlerline is just restating the export and adds a new explanatory comment insrc/, which this repo asks us to avoid.✂️ Suggested cleanup
- -// H3 handler export { defineHandler } from "h3";As per coding guidelines,
src/**/*.{js,ts,mjs,mts}: Do not add comments explaining what the line does unless prompted.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/runtime/nitro.ts` around lines 15 - 17, Remove the extraneous comment line "// H3 handler" above the export; leave the existing export statement "export { defineHandler } from \"h3\";" unchanged so the symbol defineHandler is still re-exported from the h3 module and the file conforms to src/* comment guidelines.
🤖 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/1.docs/99.migration.md`:
- Around line 181-183: Update the migration example to show both the import
change and the handler wrapper rename: replace imports of
eventHandler/defineEventHandler with defineHandler and update exported handlers
to use defineHandler(...) instead of eventHandler(...) or
defineEventHandler(...); ensure the example includes an export default
defineHandler((event) => { ... }) snippet so readers see both the import and
call-site change.
In `@examples/auto-imports/server.ts`:
- Around line 1-4: The snippet still explicitly imports makeGreeting, so remove
the manual import line and let the auto-import feature provide makeGreeting;
specifically delete the import statement that references
"./server/utils/hello.ts" and keep the default export using defineHandler(() =>
`<h1>${makeGreeting("Nitro")}</h1>`), ensuring makeGreeting remains exported
from server/utils/hello.ts so the example demonstrates auto-imports correctly.
---
Nitpick comments:
In `@src/runtime/nitro.ts`:
- Around line 15-17: Remove the extraneous comment line "// H3 handler" above
the export; leave the existing export statement "export { defineHandler } from
\"h3\";" unchanged so the symbol defineHandler is still re-exported from the h3
module and the file conforms to src/* comment guidelines.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 7bad120f-006d-47ce-ab46-6a0867162e34
📒 Files selected for processing (44)
docs/1.docs/2.quick-start.mddocs/1.docs/4.renderer.mddocs/1.docs/5.routing.mddocs/1.docs/50.assets.mddocs/1.docs/50.configuration.mddocs/1.docs/50.database.mddocs/1.docs/50.lifecycle.mddocs/1.docs/50.tasks.mddocs/1.docs/6.server-entry.mddocs/1.docs/7.cache.mddocs/1.docs/99.migration.mddocs/2.deploy/20.providers/cloudflare.mddocs/4.examples/api-routes.mddocs/4.examples/auto-imports.mddocs/4.examples/custom-error-handler.mddocs/4.examples/database.mddocs/4.examples/middleware.mddocs/4.examples/nano-jsx.mddocs/4.examples/renderer.mddocs/4.examples/runtime-config.mddocs/4.examples/server-fetch.mdexamples/api-routes/README.mdexamples/api-routes/api/hello.tsexamples/api-routes/api/hello/[name].tsexamples/api-routes/api/test.get.tsexamples/api-routes/api/test.post.tsexamples/auto-imports/README.mdexamples/auto-imports/server.tsexamples/custom-error-handler/README.mdexamples/custom-error-handler/server.tsexamples/database/README.mdexamples/database/server.tsexamples/middleware/README.mdexamples/middleware/server.tsexamples/nano-jsx/README.mdexamples/nano-jsx/server.tsxexamples/renderer/README.mdexamples/renderer/api/hello.tsexamples/runtime-config/README.mdexamples/runtime-config/server.tsexamples/server-fetch/README.mdexamples/server-fetch/routes/hello.tsexamples/server-fetch/routes/index.tssrc/runtime/nitro.ts
| -- import { eventHandler, defineEventHandler } from "nitro/h3" | ||
| ++ import { defineHandler } from "nitro/h3" | ||
| ++ import { defineHandler } from "nitro" | ||
| ``` |
There was a problem hiding this comment.
🧩 Analysis chain
🌐 Web query:
In H3 v2 / Nitro v3 migration guidance, were eventHandleranddefineEventHandlerreplaced bydefineHandler, and what is the recommended before/after example for that migration?
💡 Result:
Yes. H3 v2 migration guidance deprecates eventHandler / defineEventHandler in favor of defineHandler (or just exporting a plain function handler). [1]
Before (H3 v1 / Nitro v2):
import { defineEventHandler } from "h3";
export default defineEventHandler((event) => {
return { ok: true };
});After (H3 v2 / Nitro v3):
import { defineHandler } from "nitro/h3"; // (or from "h3" if you're using H3 directly)
export default defineHandler((event) => {
return { ok: true };
});[1][2][3]
Sources: H3 v2 migration guide [1], Nitro v3 docs example using defineHandler [2], H3 “Event Handlers” docs [3].
Include the handler call-site rename in the migration example.
The diff currently shows only the import path change, but the actual migration also requires renaming the handler wrapper from eventHandler(...) or defineEventHandler(...) to defineHandler(...). Without this, users may update imports alone and leave broken handler calls in their code.
✏️ Suggested doc expansion
```diff
-- import { eventHandler, defineEventHandler } from "nitro/h3"
++ import { defineHandler } from "nitro"
-```
+
+- export default eventHandler((event) => {
++ export default defineHandler((event) => {
++ // ...
++ })
+```🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@docs/1.docs/99.migration.md` around lines 181 - 183, Update the migration
example to show both the import change and the handler wrapper rename: replace
imports of eventHandler/defineEventHandler with defineHandler and update
exported handlers to use defineHandler(...) instead of eventHandler(...) or
defineEventHandler(...); ensure the example includes an export default
defineHandler((event) => { ... }) snippet so readers see both the import and
call-site change.
| import { defineHandler } from "nitro"; | ||
| import { makeGreeting } from "./server/utils/hello.ts"; | ||
|
|
||
| export default defineHandler(() => `<h1>${makeGreeting("Nitro")}</h1>`); |
There was a problem hiding this comment.
The auto-import example still uses a manual import.
Line 2 imports makeGreeting, so this snippet never demonstrates the feature it is supposed to showcase. Because this example is mirrored in the docs, keeping the explicit import makes the auto-import story misleading for copy-paste users.
💡 Suggested fix
import { defineHandler } from "nitro";
-import { makeGreeting } from "./server/utils/hello.ts";
export default defineHandler(() => `<h1>${makeGreeting("Nitro")}</h1>`);📝 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.
| import { defineHandler } from "nitro"; | |
| import { makeGreeting } from "./server/utils/hello.ts"; | |
| export default defineHandler(() => `<h1>${makeGreeting("Nitro")}</h1>`); | |
| import { defineHandler } from "nitro"; | |
| export default defineHandler(() => `<h1>${makeGreeting("Nitro")}</h1>`); |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@examples/auto-imports/server.ts` around lines 1 - 4, The snippet still
explicitly imports makeGreeting, so remove the manual import line and let the
auto-import feature provide makeGreeting; specifically delete the import
statement that references "./server/utils/hello.ts" and keep the default export
using defineHandler(() => `<h1>${makeGreeting("Nitro")}</h1>`), ensuring
makeGreeting remains exported from server/utils/hello.ts so the example
demonstrates auto-imports correctly.
defineHandler from nitronitro
There was a problem hiding this comment.
♻️ Duplicate comments (1)
docs/1.docs/99.migration.md (1)
181-193:⚠️ Potential issue | 🟡 MinorComplete the handler migration example and narrow the root-export wording.
This still shows only the import replacement. For Nitro 2 → 3, readers also need the wrapper rename (
eventHandler(...)/defineEventHandler(...)→defineHandler(...)), and the surrounding H3 v2 prose should clarify that only selected helpers are re-exported from rootnitrorather than “all H3 utilities.” Otherwise the guide encourages partial migrations and contradicts itself.📝 Suggested doc update
### Handler Utils ```diff -- import { eventHandler, defineEventHandler } from "nitro/h3" ++ import { defineHandler } from "nitro" + +- export default eventHandler((event) => { ++ export default defineHandler((event) => { ++ // ... ++ })</details> ```web In Nitro v3 / H3 v2 migration guidance, should `eventHandler(...)` and `defineEventHandler(...)` be migrated to `defineHandler(...)`, and are `defineHandler` / `HTTPError` documented as root exports from `nitro` rather than only `nitro/h3`?Based on learnings: Add migration notes for breaking changes.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@docs/1.docs/99.migration.md` around lines 181 - 193, Update the migration docs to show the full handler wrapper rename and clarify root-export scope: replace the example import line with the new import (defineHandler from "nitro"), change the example default export wrapper from eventHandler(...) or defineEventHandler(...) to defineHandler(...), and add a brief note that only selected H3 utilities like defineHandler and HTTPError are exported from the root "nitro" (not all h3 helpers), referencing the symbols eventHandler, defineEventHandler, defineHandler, HTTPError, and nitro/h3 so readers know which helpers move or remain.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Duplicate comments:
In `@docs/1.docs/99.migration.md`:
- Around line 181-193: Update the migration docs to show the full handler
wrapper rename and clarify root-export scope: replace the example import line
with the new import (defineHandler from "nitro"), change the example default
export wrapper from eventHandler(...) or defineEventHandler(...) to
defineHandler(...), and add a brief note that only selected H3 utilities like
defineHandler and HTTPError are exported from the root "nitro" (not all h3
helpers), referencing the symbols eventHandler, defineEventHandler,
defineHandler, HTTPError, and nitro/h3 so readers know which helpers move or
remain.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: ecc0f920-f7c4-4250-9de3-bdb9f3fc4d3c
📒 Files selected for processing (27)
automd.config.tsdocs/1.docs/5.routing.mddocs/1.docs/50.tasks.mddocs/1.docs/7.cache.mddocs/1.docs/99.migration.mddocs/4.examples/cached-handler.mddocs/4.examples/custom-error-handler.mddocs/4.examples/database.mddocs/4.examples/middleware.mddocs/4.examples/nano-jsx.mddocs/4.examples/renderer.mddocs/4.examples/runtime-config.mddocs/4.examples/vite-rsc.mddocs/4.examples/vite-ssr-tss-react.mddocs/4.examples/vite-trpc.mddocs/4.examples/websocket.mdexamples/cached-handler/README.mdexamples/cached-handler/server.tsexamples/custom-error-handler/README.mdexamples/custom-error-handler/server.tsexamples/middleware/README.mdexamples/middleware/server/middleware/auth.tsexamples/nano-jsx/README.mdexamples/nano-jsx/server.tsxexamples/websocket/README.mdexamples/websocket/routes/_ws.tssrc/runtime/nitro.ts
💤 Files with no reviewable changes (3)
- docs/4.examples/vite-rsc.md
- docs/4.examples/vite-ssr-tss-react.md
- docs/4.examples/vite-trpc.md
🚧 Files skipped from review as they are similar to previous changes (9)
- docs/4.examples/database.md
- docs/4.examples/middleware.md
- docs/1.docs/5.routing.md
- examples/nano-jsx/server.tsx
- examples/custom-error-handler/README.md
- docs/1.docs/50.tasks.md
- docs/4.examples/renderer.md
- docs/4.examples/nano-jsx.md
- docs/1.docs/7.cache.md
Using
defineHandleris very common across Nitro apps. This PR adds a simple re-export ofdefineHandlerfrom main subpath.