Skip to content

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

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

fix(preset): keep lazy handlers code-split in dev#4436
jibin7jose wants to merge 2 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

📝 Walkthrough

Walkthrough

The Nitro dev preset changes inlineDynamicImports from true to false; all other preset wiring and outputs remain unchanged.

Changes

Nitro dev preset

Layer / File(s) Summary
Dynamic import configuration
src/presets/_nitro/nitro-dev.ts
Sets inlineDynamicImports to false in the dev preset.

Estimated code review effort: 1 (Trivial) | ~2 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title follows conventional commit format and clearly describes the dev code-splitting fix.
Description check ✅ Passed The description matches the changeset and explains the nitro-dev inlineDynamicImports change.
✨ 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