Skip to content

fix(preset): keep lazy handlers code-split in dev#4436

Open
jibin7jose wants to merge 4 commits into
nitrojs:mainfrom
jibin7jose:fix-dev-lazy-handlers
Open

fix(preset): keep lazy handlers code-split in dev#4436
jibin7jose wants to merge 4 commits into
nitrojs:mainfrom
jibin7jose:fix-dev-lazy-handlers

Conversation

@jibin7jose

@jibin7jose jibin7jose commented Jul 16, 2026

Copy link
Copy Markdown

Description

This PR fixes an issue where an import-time error in a single lazy route handler takes down the entire dev server and breaks unrelated routes with a misleading Cannot access '<x>' before initialization error.

Cause:
The nitro-dev preset was setting inlineDynamicImports: true. This caused Rollup to inline all lazy handler bodies into the single index.mjs startup bundle. An error evaluating one route would abort the execution of the bundle, leaving subsequent routes permanently in the Temporal Dead Zone (TDZ).

Fix:
We've set inlineDynamicImports: false in the nitro-dev preset. This ensures lazy handlers remain code-split during local development, so an import-time failure in one module will not disrupt the evaluation of the rest of the server or other routes. When a broken route is accessed, the dev server will now accurately report the original initialization error.

Fixes #4435

@jibin7jose
jibin7jose requested a review from pi0 as a code owner July 16, 2026 15:04
@vercel

vercel Bot commented Jul 16, 2026

Copy link
Copy Markdown

@jibin7jose is attempting to deploy a commit to the Nitro Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 35ff2855-fe37-4fc4-8078-31048668a773

📥 Commits

Reviewing files that changed from the base of the PR and between a217da5 and a6ab1a4.

📒 Files selected for processing (4)
  • src/presets/_nitro/nitro-dev.ts
  • test/fixtures/dev-import-error/routes/boom.get.ts
  • test/fixtures/dev-import-error/routes/ok.get.ts
  • test/unit/dev-import-error.test.ts

📝 Walkthrough

Walkthrough

The Nitro dev preset now keeps dynamic imports un-inlined and updates related preset configuration. Regression fixtures and a Vitest suite verify that an import-time error in one route does not prevent an unrelated route from responding.

Changes

Nitro dev import error handling

Layer / File(s) Summary
Update Nitro dev preset
src/presets/_nitro/nitro-dev.ts
Updates preset imports and paths, disables dynamic import inlining, changes external tracing and source map options, and removes the custom task handler.
Add import-error regression coverage
test/fixtures/dev-import-error/routes/*, test/unit/dev-import-error.test.ts
Adds healthy and import-failing routes and verifies their independent dev-server responses, error content, reload setup, and cleanup.

Estimated code review effort: 3 (Moderate) | ~20 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title uses a valid conventional commits format and summarizes the dev code-splitting fix.
Description check ✅ Passed The description clearly matches the dev-server lazy-handler import error fix.
Linked Issues check ✅ Passed The changes implement #4435 by keeping lazy handlers code-split in dev and adding a regression test.
Out of Scope Changes check ✅ Passed The additional preset and test fixture changes stay within the lazy-handler dev-server fix scope.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

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.

Dev: import-time error in a lazy route reported as unrelated Cannot access '<x>' before initialization

1 participant