Skip to content

refactor(vite): keep SSR bundle external dependencies#3854

Merged
pi0 merged 2 commits intomainfrom
refactor/vite-rollup
Dec 10, 2025
Merged

refactor(vite): keep SSR bundle external dependencies#3854
pi0 merged 2 commits intomainfrom
refactor/vite-rollup

Conversation

@pi0
Copy link
Copy Markdown
Member

@pi0 pi0 commented Dec 10, 2025

Enable full external dependencies for SSR intermediate bundle by removing custom noExternal config

This PR adds a workaround for process.env.NODE_ENV static replacement for tanstack-start devtools until adding development/production export conditions.

@vercel
Copy link
Copy Markdown

vercel bot commented Dec 10, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
nitro.build Ready Ready Preview Comment Dec 10, 2025 8:43pm

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Dec 10, 2025

📝 Walkthrough

Walkthrough

Type definitions for Vite's RollupCommonJSOptions are imported. The createNitroEnvironment function's rollupOptions handling is refactored to use direct type references instead of any casts, and a process.env.NODE_ENV define block is added. A development build exclusion for noExternal in createServiceEnvironment is removed.

Changes

Cohort / File(s) Summary
Vite environment configuration
src/build/vite/env.ts
Extended imports to include RollupCommonJSOptions from vite; refactored createNitroEnvironment to use typed ctx.rollupConfig!.config instead of any cast; commonjsOptions now explicitly typed as RollupCommonJSOptions; added define block to set process.env.NODE_ENV based on dev flag; removed conditional noExternal exclusion for development builds in createServiceEnvironment

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • The removal of the noExternal conditional in createServiceEnvironment may warrant verification against the rationale for that change
  • Confirm that adding the process.env.NODE_ENV define block aligns with build configuration requirements and doesn't conflict with existing environment setup

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title follows conventional commits format with 'refactor' scope and accurately describes the main change of keeping external dependencies in the SSR bundle.
Description check ✅ Passed The description is directly related to the changeset, explaining the purpose of removing noExternal config and adding process.env.NODE_ENV workaround for devtools support.
✨ 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 refactor/vite-rollup

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f661802 and a30f777.

📒 Files selected for processing (1)
  • src/build/vite/env.ts (3 hunks)
⏰ 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). (1)
  • GitHub Check: publish-pkg-pr-new
🔇 Additional comments (5)
src/build/vite/env.ts (5)

1-1: LGTM! Proper type import added.

The addition of RollupCommonJSOptions import improves type safety for the commonjsOptions configuration on line 29.


25-25: LGTM! Improved type safety by removing as any cast.

Removing the type assertion improves compile-time type checking and makes the code more maintainable.


29-29: Note the change from defensive copy to direct reference.

The previous code used object spreading ({ ...ctx.nitro!.options.commonJS }) which created a shallow copy, while the new code directly assigns the reference with a type cast. This is likely fine as Vite typically doesn't mutate configuration objects, but be aware that any mutations to commonjsOptions by Vite would now affect the original object.


44-49: LGTM! Standard Vite define pattern for NODE_ENV.

The define block correctly sets process.env.NODE_ENV at build time using JSON.stringify, which is the standard approach for Vite. The comment clearly documents the tanstack-start devtools use case.


62-92: Address recurring issues with external dependency handling in service builds.

The removal of noExternal configuration from service environments (commit d34a045) was intended to keep dependencies external, but git history reveals this caused immediate breakage: commit 9b276e1 ("temp fix for react bundling") re-added noExternal: [/react/] specifically to fix React bundling failures with tanstack-start. The current code shows no explicit handling for React or other external dependencies in production service builds.

Service environments rely solely on externalConditions filtering (which excludes browser/wasm conditions), but lack the previous noExternal safeguards that were intentionally removed. This behavioral change needs validation to ensure service builds correctly handle framework dependencies like React in both development and production modes, particularly for frameworks like tanstack-start that depend on proper bundling behavior.


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.

@pi0 pi0 changed the title refactor(vite): remove noExternal rule for react refactor(vite): remove noExternal rule Dec 10, 2025
@pi0 pi0 changed the title refactor(vite): remove noExternal rule refactor(vite): keep SSR bundle external dependencies Dec 10, 2025
@pi0 pi0 marked this pull request as ready for review December 10, 2025 20:43
@pi0 pi0 merged commit 4fbfed7 into main Dec 10, 2025
10 of 11 checks passed
@pi0 pi0 deleted the refactor/vite-rollup branch December 10, 2025 20:45
@coderabbitai coderabbitai 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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant