Skip to content

fix(vite): broaden checks for existing client input#4077

Open
RihanArfan wants to merge 2 commits intomainfrom
fix/client-entry-tss
Open

fix(vite): broaden checks for existing client input#4077
RihanArfan wants to merge 2 commits intomainfrom
fix/client-entry-tss

Conversation

@RihanArfan
Copy link
Member

🔗 Linked issue

Closes #4069

❓ Type of change

  • 📖 Documentation (updates to the documentation, readme, or JSdoc annotations)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • 👌 Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

📚 Description

Removes using getEntry() since we don't need the exact input, just to know whether an existing client entrypoint is configured.

📝 Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@RihanArfan RihanArfan requested a review from pi0 as a code owner March 5, 2026 22:44
@vercel
Copy link

vercel bot commented Mar 5, 2026

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

Project Deployment Actions Updated (UTC)
nitro.build Ready Ready Preview, Comment Mar 5, 2026 11:04pm

Request Review

@coderabbitai
Copy link

coderabbitai bot commented Mar 5, 2026

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: bae6ef2c-6f8f-478c-8b5d-282ca4b6149e

📥 Commits

Reviewing files that changed from the base of the PR and between 0d39f67 and 9a916c0.

📒 Files selected for processing (1)
  • src/build/vite/plugin.ts

📝 Walkthrough

Walkthrough

Replaced validation-based detection of a configured client entry with a direct boolean check that treats the presence of either rolldownOptions.input or rollupOptions.input as indicating the client entry is configured.

Changes

Cohort / File(s) Summary
Client Entry Detection
src/build/vite/plugin.ts
Compute clientEntryConfigured by coercing the presence of `rolldownOptions.input

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ 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%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title follows conventional commits format with 'fix(vite):' prefix and clearly describes the change: broadening checks for existing client input.
Description check ✅ Passed The description is directly related to the changeset, explaining the removal of getEntry() usage and linking to issue #4069 which documents the regression.
Linked Issues check ✅ Passed The PR directly addresses issue #4069 by preventing duplicate client Rollup inputs when a virtual client entry is already configured, matching the stated objective.
Out of Scope Changes check ✅ Passed The changes are minimal and focused solely on the vite plugin's client entry detection logic, staying within the scope of fixing the duplicate input issue.

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

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/client-entry-tss

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

@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.

🧹 Nitpick comments (1)
src/build/vite/plugin.ts (1)

101-104: Consider a more robust emptiness check to handle edge cases.

The change correctly fixes the duplicate entry issue by detecting non-index keyed inputs like { main: "virtual:..." } that getEntry() would miss. However, using !! coercion treats empty objects {} and empty arrays [] as "configured" (both are truthy in JavaScript), which could skip auto-detection when no actual entry exists.

Suggested more robust check
-      let clientEntryConfigured = !!(
-        userConfig.environments?.client?.build?.rolldownOptions?.input ||
-          userConfig.environments?.client?.build?.rollupOptions?.input
-      );
+      const clientInput =
+        userConfig.environments?.client?.build?.rolldownOptions?.input ||
+        userConfig.environments?.client?.build?.rollupOptions?.input;
+      let clientEntryConfigured =
+        typeof clientInput === "string"
+          ? clientInput.length > 0
+          : Array.isArray(clientInput)
+            ? clientInput.length > 0
+            : clientInput != null && Object.keys(clientInput).length > 0;

Alternatively, a simpler approach could use the existing getEntry() but extend it to handle any object key (not just index):

 function getEntry(input: InputOption | undefined): string | undefined {
   if (typeof input === "string") {
     return input;
   } else if (Array.isArray(input) && input.length > 0) {
     return input[0];
-  } else if (input && "index" in input) {
-    return input.index as string;
+  } else if (input && typeof input === "object") {
+    const values = Object.values(input);
+    return values.length > 0 ? (values[0] as string) : undefined;
   }
 }

This would make getEntry() work with { main: "..." } inputs, allowing the original pattern !!getEntry(...) to work while rejecting empty objects.

Based on learnings: Changes in src/build affect build output and require careful review for backwards compatibility.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/build/vite/plugin.ts` around lines 101 - 104, The current
clientEntryConfigured uses !! coercion which treats empty arrays/objects as
configured; change it to explicitly check that the rollup/rolldown input is
non-empty: locate the clientEntryConfigured assignment and replace the boolean
coercion with a check that reads the input value (from
userConfig.environments?.client?.build?.rolldownOptions?.input ||
userConfig.environments?.client?.build?.rollupOptions?.input) and returns true
only if it's a non-empty string, a non-empty array (length > 0), or an object
with at least one own enumerable key (Object.keys(...).length > 0);
alternatively extend getEntry(...) to recognize any object key (not only
"index") and then use !!getEntry(...) as before, referencing getEntry,
clientEntryConfigured, and userConfig.environments?.client?.build in your
change.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/build/vite/plugin.ts`:
- Around line 101-104: The current clientEntryConfigured uses !! coercion which
treats empty arrays/objects as configured; change it to explicitly check that
the rollup/rolldown input is non-empty: locate the clientEntryConfigured
assignment and replace the boolean coercion with a check that reads the input
value (from userConfig.environments?.client?.build?.rolldownOptions?.input ||
userConfig.environments?.client?.build?.rollupOptions?.input) and returns true
only if it's a non-empty string, a non-empty array (length > 0), or an object
with at least one own enumerable key (Object.keys(...).length > 0);
alternatively extend getEntry(...) to recognize any object key (not only
"index") and then use !!getEntry(...) as before, referencing getEntry,
clientEntryConfigured, and userConfig.environments?.client?.build in your
change.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 4e519234-780f-48bb-a6a8-e4d9dd0f1752

📥 Commits

Reviewing files that changed from the base of the PR and between bfbb207 and 0d39f67.

📒 Files selected for processing (1)
  • src/build/vite/plugin.ts

@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 5, 2026

Open in StackBlitz

npm i https://pkg.pr.new/nitro@4077

commit: ddde9c3

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.

Vite plugin adds src/entry-client.tsx as second client rollup input when used with TanStack Start (regression in 20260227-181935)

1 participant