8000 fix(kit): add forward compatible nitro v3 types by danielroe · Pull Request #34053 · nuxt/nuxt · GitHub
[go: up one dir, main page]

Skip to content

fix(kit): add forward compatible nitro v3 types#34053

Merged
danielroe merged 1 commit intomainfrom
fix/kit-nitro
Jan 9, 2026
Merged

fix(kit): add forward compatible nitro v3 types#34053
danielroe merged 1 commit intomainfrom
fix/kit-nitro

Conversation

@danielroe
Copy link
Member

🔗 Linked issue

📚 Description

extracted from #33005

@bolt-new-by-stackblitz
Copy link

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@coderabbitai
Copy link
Contributor
coderabbitai bot commented Jan 9, 2026

Walkthrough

This pull request modifies the Nitro type compatibility layer in the Kit package to support both NitroV2 and NitroV3 simultaneously. A new isNitroV3 type gate is introduced to detect NitroV3 presence. Five exported types—Nitro, NitroDevEventHandler, NitroEventHandler, NitroRouteConfig, and NitroRuntimeConfig—are updated from simple binary conditionals to nested conditionals that yield union types when both Nitro versions exist. Additional changes relax type checking in the nitro.ts, pages.ts, and runtime-config.ts files through strategic any type casts.

Possibly related PRs

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% 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 'fix(kit): add forward compatible nitro v3 types' accurately summarises the main change—adding Nitro V3 type support alongside V2 for forward compatibility.
Description check ✅ Passed The description references extraction from a related Nuxt PR and follows the expected template structure, though it lacks a specific linked issue number.

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

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/kit-nitro

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.

Copy link
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: 0

🧹 Nitpick comments (1)
packages/kit/src/nitro-types.ts (1)

16-20: Consider reformatting for readability.

The nested ternary expressions are functionally correct but quite long. Consider reformatting with line breaks to improve maintainability.

♻️ Suggested formatting
-export type Nitro = isNitroV2 extends true ? isNitroV3 extends true ? NitroV2.Nitro | NitroV3.Nitro : NitroV2.Nitro : NitroV3.Nitro
-export type NitroDevEventHandler = isNitroV2 extends true ? isNitroV3 extends true ? NitroV2.NitroDevEventHandler | NitroV3.NitroDevEventHandler : NitroV2.NitroDevEventHandler : NitroV3.NitroDevEventHandler
-export type NitroEventHandler = isNitroV2 extends true ? isNitroV3 extends true ? NitroV2.NitroEventHandler | NitroV3.NitroEventHandler : NitroV2.NitroEventHandler : NitroV3.NitroEventHandler
-export type NitroRouteConfig = isNitroV2 extends true ? isNitroV3 extends true ? NitroV2.NitroRouteConfig | NitroV3.NitroRouteConfig : NitroV2.NitroRouteConfig : NitroV3.NitroRouteConfig
-export type NitroRuntimeConfig = isNitroV2 extends true ? isNitroV3 extends true ? NitroV2.NitroRuntimeConfig | NitroV3.NitroRuntimeConfig : NitroV2.NitroRuntimeConfig : NitroV3.NitroRuntimeConfig
+export type Nitro = isNitroV2 extends true
+  ? isNitroV3 extends true ? NitroV2.Nitro | NitroV3.Nitro : NitroV2.Nitro
+  : NitroV3.Nitro
+
+export type NitroDevEventHandler = isNitroV2 extends true
+  ? isNitroV3 extends true ? NitroV2.NitroDevEventHandler | NitroV3.NitroDevEventHandler : NitroV2.NitroDevEventHandler
+  : NitroV3.NitroDevEventHandler
+
+export type NitroEventHandler = isNitroV2 extends true
+  ? isNitroV3 extends true ? NitroV2.NitroEventHandler | NitroV3.NitroEventHandler : NitroV2.NitroEventHandler
+  : NitroV3.NitroEventHandler
+
+export type NitroRouteConfig = isNitroV2 extends true
+  ? isNitroV3 extends true ? NitroV2.NitroRouteConfig | NitroV3.NitroRouteConfig : NitroV2.NitroRouteConfig
+  : NitroV3.NitroRouteConfig
+
+export type NitroRuntimeConfig = isNitroV2 extends true
+  ? isNitroV3 extends true ? NitroV2.NitroRuntimeConfig | NitroV3.NitroRuntimeConfig : NitroV2.NitroRuntimeConfig
+  : NitroV3.NitroRuntimeConfig
📜 Review details

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 139ef2b and ecd8123.

📒 Files selected for processing (4)
  • packages/kit/src/nitro-types.ts
  • packages/kit/src/nitro.ts
  • packages/kit/src/pages.ts
  • packages/kit/src/runtime-config.ts
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{ts,tsx,vue}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Follow standard TypeScript conventions and best practices

Files:

  • packages/kit/src/nitro.ts
  • packages/kit/src/pages.ts
  • packages/kit/src/runtime-config.ts
  • packages/kit/src/nitro-types.ts
**/*.{ts,tsx,js,jsx,vue}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

**/*.{ts,tsx,js,jsx,vue}: Use clear, descriptive variable and function names
Add comments only to explain complex logic or non-obvious implementations
Keep functions focused and manageable (generally under 50 lines), and extract complex logic into separate domain-specific files
Remove code that is not used or needed
Use error handling patterns consistently

Files:

  • packages/kit/src/nitro.ts
  • packages/kit/src/pages.ts
  • packages/kit/src/runtime-config.ts
  • packages/kit/src/nitro-types.ts
🧠 Learnings (2)
📚 Learning: 2024-11-28T21:22:40.496Z
Learnt from: GalacticHypernova
Repo: nuxt/nuxt PR: 29661
File: packages/kit/src/template.ts:227-229
Timestamp: 2024-11-28T21:22:40.496Z
Learning: In `packages/kit/src/template.ts`, when updating the `EXTENSION_RE` regular expression for TypeScript configuration, avoid using patterns like `(\.\w+)+$` as they can result in catastrophic backtracking.

Applied to files:

  • packages/kit/src/pages.ts
📚 Learning: 2024-12-12T12:36:34.871Z
Learnt from: huang-julien
Repo: nuxt/nuxt PR: 29366
File: packages/nuxt/src/app/components/nuxt-root.vue:16-19
Timestamp: 2024-12-12T12:36:34.871Z
Learning: In `packages/nuxt/src/app/components/nuxt-root.vue`, when optimizing bundle size by conditionally importing components based on route metadata, prefer using inline conditional imports like:

```js
const IsolatedPage = route?.meta?.isolate ? defineAsyncComponent(() => import('#build/isolated-page.mjs')) : null
```

instead of wrapping the import in a computed property or importing the component unconditionally.

Applied to files:

  • packages/kit/src/pages.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (14)
  • GitHub Check: test-fixtures (windows-latest, built, webpack, async, manifest-on, json, lts/-1)
  • GitHub Check: test-fixtures (windows-latest, dev, vite-env-api, async, manifest-on, json, lts/-1)
  • GitHub Check: test-fixtures (windows-latest, dev, vite-env-api, default, manifest-on, json, lts/-1)
  • GitHub Check: test-fixtures (windows-latest, dev, vite, async, manifest-off, json, lts/-1)
  • GitHub Check: test-fixtures (windows-latest, built, vite, default, manifest-on, json, lts/-1)
  • GitHub Check: test-fixtures (ubuntu-latest, dev, vite-env-api, default, manifest-on, json, lts/-1)
  • GitHub Check: test-fixtures (ubuntu-latest, built, vite-env-api, default, manifest-on, json, lts/-1)
  • GitHub Check: test-fixtures (ubuntu-latest, dev, vite, default, manifest-on, json, lts/-1)
  • GitHub Check: test-fixtures (ubuntu-latest, dev, vite-env-api, async, manifest-on, json, lts/-1)
  • GitHub Check: test-fixtures (ubuntu-latest, dev, vite, async, manifest-on, json, lts/-1)
  • GitHub Check: typecheck (windows-latest, bundler)
  • GitHub Check: typecheck (ubuntu-latest, bundler)
  • GitHub Check: test-benchmark
  • GitHub Check: code
🔇 Additional comments (4)
packages/kit/src/nitro-types.ts (1)

10-14: LGTM!

The isNitroV3 type guard correctly mirrors the existing isNitroV2 pattern, checking for the presence of a valid Nitro type by verifying the options key exists and the ___INVALID marker is absent.

packages/kit/src/nitro.ts (1)

36-38: Acceptable trade-off for cross-version compatibility.

The as any cast mirrors the existing pattern in addServerHandler (line 29) and is a reasonable workaround for the union type complexity introduced by dual Nitro version support.

packages/kit/src/runtime-config.ts (1)

31-35: Appropriate type relaxation for forward compatibility.

Casting to Record<string, any> removes the dependency on NitroRuntimeConfig which may differ between Nitro v2 and v3. The existing try/catch properly handles the uninitialised Nitro case.

packages/kit/src/pages.ts (1)

25-28: Consistent type handling for dual-version support.

The as any casts are necessary to avoid defu type conflicts when NitroRouteConfig resolves to a union type. Runtime behaviour remains unchanged.

@codspeed-hq
Copy link
codspeed-hq bot commented Jan 9, 2026

Merging this PR will not alter performance

✅ 10 untouched benchmarks


Comparing fix/kit-nitro (ecd8123) with main (139ef2b)

Open in CodSpeed

@pkg-pr-new
Copy link
pkg-pr-new bot commented Jan 9, 2026

Open in StackBlitz

@nuxt/kit

npm i https://pkg.pr.new/@nuxt/kit@34053

@nuxt/nitro-server

npm i https://pkg.pr.new/@nuxt/nitro-server@34053

nuxt

npm i https://pkg.pr.new/nuxt@34053

@nuxt/rspack-builder

npm i https://pkg.pr.new/@nuxt/rspack-builder@34053

@nuxt/schema

npm i https://pkg.pr.new/@nuxt/schema@34053

@nuxt/vite-builder

npm i https://pkg.pr.new/@nuxt/vite-builder@34053

@nuxt/webpack-builder

npm i https://pkg.pr.new/@nuxt/webpack-builder@34053

commit: ecd8123

@danielroe danielroe merged commit b5613d2 into main Jan 9, 2026
99 of 101 checks passed
@danielroe danielroe deleted the fix/kit-nitro branch January 9, 2026 21:40
@github-actions github-actions bot mentioned this pull request Jan 9, 2026
@github-actions github-actions bot mentioned this pull request Jan 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

0