Skip to content

Conversation

@TheAlexLichter
Copy link
Member

🔗 Linked issue

Resolves #33418

📚 Description

When using rolldown-vite, the replacement plugin was used but the preventAssignment option wasn't passed, leading to issues loading the app. This should be fixed with this PR.

@bolt-new-by-stackblitz
Copy link

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

@coderabbitai
Copy link

coderabbitai bot commented Oct 20, 2025

Walkthrough

The change modifies the ReplacePlugin in packages/vite/src/plugins/replace.ts to pass an additional options object when calling replacePlugin in the conditional branch where rolldownVersion is present. Specifically, it adds { preventAssignment: true } as a second argument to the function call, aligning the behaviour with the else branch that already includes this option via object spreading.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Rationale: This is a localised, single-file modification that adds consistent parameter passing across conditional branches. The change is straightforward—adding a configuration option to a function call—with no complex logic or architectural implications. The repetition of the same option across both branches reduces cognitive load for verification.

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 (4 passed)
Check name Status Explanation
Title Check ✅ Passed The pull request title "fix(vite): prevent assignment for rolldown's replacement plugin" directly and specifically summarizes the main change in the changeset. The title clearly identifies the scope (vite), the nature of the fix (preventing assignment), and the target component (rolldown's replacement plugin). This is concise, descriptive, and accurately reflects the code modification shown in the raw summary where preventAssignment: true is added to the replacePlugin call.
Linked Issues Check ✅ Passed The code change directly addresses the objectives outlined in linked issue #33418. The issue describes rolldown-vite initialization failures with symptoms including missing console logs, uninitialized custom plugins, and warnings about the replacePlugin configuration. The pull request resolves this by adding the missing preventAssignment: true option to the replacePlugin call in the ReplacePlugin when rolldownVersion is present, which aligns with the root cause analysis and expected fix for the initialization problem described in the linked issue.
Out of Scope Changes Check ✅ Passed All changes in this pull request are directly scoped to addressing the issue described in #33418. The modification to packages/vite/src/plugins/replace.ts adds the preventAssignment: true option to the replacePlugin call for the rolldown version path, which is precisely what is required to fix the rolldown-vite initialization problem. There are no unrelated changes, refactorings, or modifications to other areas that fall outside the scope of resolving this specific issue.
Description Check ✅ Passed The pull request description is directly related to the changeset and provides meaningful context about the fix. It clearly references the linked issue (#33418), explains the problem (missing preventAssignment option when using rolldown-vite), describes the symptom (issues loading the app), and states the solution (passing the preventAssignment option to the replacement plugin). The description appropriately connects the code change to the broader problem being solved.
✨ 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 TheAlexLichter-patch-1

📜 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 568cd34 and 0fccec7.

📒 Files selected for processing (1)
  • packages/vite/src/plugins/replace.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx}

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

Follow standard TypeScript conventions and best practices

Files:

  • packages/vite/src/plugins/replace.ts
🧠 Learnings (1)
📚 Learning: 2025-04-18T18:33:41.753Z
Learnt from: TheAlexLichter
PR: nuxt/nuxt#31812
File: packages/nuxt/src/components/plugins/islands-transform.ts:202-202
Timestamp: 2025-04-18T18:33:41.753Z
Learning: In Nuxt, using `rolldownVersion` (not `rollupVersion`) is intentional when detecting if rolldown-vite is being used, even though TypeScript may show an error because the property isn't in standard type definitions yet.

Applied to files:

  • packages/vite/src/plugins/replace.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). (2)
  • GitHub Check: build
  • GitHub Check: code
🔇 Additional comments (1)
packages/vite/src/plugins/replace.ts (1)

24-24: LGTM! Critical fix for rolldown-vite compatibility.

The addition of { preventAssignment: true } correctly aligns the rolldown code path with the standard rollup path (line 26) and fixes the initialisation issue described in #33418. The API signature difference between rolldown's experimental replacePlugin (which takes options as a second parameter) and the standard @rollup/plugin-replace (which takes all options in a single object) is properly handled.


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.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Oct 20, 2025

Open in StackBlitz

@nuxt/kit

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

nuxt

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

@nuxt/rspack-builder

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

@nuxt/schema

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

@nuxt/vite-builder

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

@nuxt/webpack-builder

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

commit: 0fccec7

@codspeed-hq
Copy link

codspeed-hq bot commented Oct 20, 2025

CodSpeed Performance Report

Merging #33526 will not alter performance

Comparing TheAlexLichter-patch-1 (0fccec7) with main (b7ed1d3)1

Summary

✅ 10 untouched

Footnotes

  1. No successful run was found on main (568cd34) during the generation of this report, so b7ed1d3 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@danielroe danielroe merged commit 2cf7709 into main Oct 20, 2025
99 of 101 checks passed
@danielroe danielroe deleted the TheAlexLichter-patch-1 branch October 20, 2025 10:43
@danielroe
Copy link
Member

thank you 🙏

@github-actions github-actions bot mentioned this pull request Oct 20, 2025
@yschroe
Copy link

yschroe commented Oct 20, 2025

@TheAlexLichter Out of interest I tried this fix via patching @nuxt/vite-builder myself and unfortunately it's still the same behaviour. Nuxt does not start correctly.

Edit: The following explanation is probably wrong since I assume the plugin works on source code (=text) level so replacing a string with a string is fine.

I had a quick look at the source code and I think the issue is the following:

The following object is passed to the replacePlugin config:

{
  'import.meta.dev': true,
  'import.meta.test': false,
  'import.meta.server': true,
  'import.meta.client': false,
  'import.meta.browser': false 
}

The replacePlugin function looks like this:

function replacePlugin(values = {}, options = {}) {
	let hasNonStringValues = false;
	Object.keys(values).forEach((key) => {
		const value = values[key];
		if (typeof value !== "string") {
            console.log(value);
			hasNonStringValues = true;
			values[key] = String(value);
		}
	});
	if (hasNonStringValues) logger.warn("Some values provided to `replacePlugin` are not strings. They will be converted to strings, but for better performance consider converting them manually.");
	return new BuiltinPlugin("builtin:replace", {
		...options,
		values
	});
}

In there all values of the object are converted to strings via String(value), so the boolean values are all strings now. This likely causes issues and would explain the Some values provided to replacePlugin are not strings warning.

@TheAlexLichter
Copy link
Member Author

@TheAlexLichter Out of interest I tried this fix via patching @nuxt/vite-builder myself and unfortunately it's still the same behaviour. Nuxt does not start correctly.
Edit: The following explanation is probably wrong since I assume the plugin works on source code (=text) level so replacing a string with a string is fine.

I had a quick look at the source code and I think the issue is the following:

The following object is passed to the replacePlugin config:

{
  'import.meta.dev': true,
  'import.meta.test': false,
  'import.meta.server': true,
  'import.meta.client': false,
  'import.meta.browser': false 
}

The replacePlugin function looks like this:

function replacePlugin(values = {}, options = {}) {
	let hasNonStringValues = false;
	Object.keys(values).forEach((key) => {
		const value = values[key];
		if (typeof value !== "string") {
            console.log(value);
			hasNonStringValues = true;
			values[key] = String(value);
		}
	});
	if (hasNonStringValues) logger.warn("Some values provided to `replacePlugin` are not strings. They will be converted to strings, but for better performance consider converting them manually.");
	return new BuiltinPlugin("builtin:replace", {
		...options,
		values
	});
}

In there all values of the object are converted to strings via String(value), so the boolean values are all strings now. This likely causes issues and would explain the Some values provided to replacePlugin are not strings warning.

In fact, the Rollup plugin does that already under the hood (converting values to strings), but without notifying you.

@yschroe
Copy link

yschroe commented Oct 21, 2025

In fact, the Rollup plugin does that already under the hood (converting values to strings), but without notifying you.

Yes, my bad. I initially thought that maybe something like false === 'false' could be the cause for the issue, but then realized that the plugin probably treats the source code as text files and on that level everything is a string/text anyways.

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.

[v4.1.3] rolldown-vite: Nuxt does not initialize correctly

4 participants