Repository navigation
feat(compiler-core): warn instead of assign for v-model on reactive on reactive objects (fix #13693) - #13694
feat(compiler-core): warn instead of assign for v-model on reactive on reactive objects (fix #13693)#13694Ray-D-Song wants to merge 1 commit into
Conversation
WalkthroughThe changes introduce a new runtime warning mechanism for improper usage of Changes
Estimated code review effort2 (~15 minutes) Suggested labels
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (3)
🧬 Code Graph Analysis (1)packages/compiler-core/src/transforms/vModel.ts (4)
🧰 Additional context used🧬 Code Graph Analysis (1)packages/compiler-core/src/transforms/vModel.ts (4)
⏰ 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). (3)
🔇 Additional comments (8)
✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
|
Thank you for your PR, but this change is incorrect because we only show warnings in DEV. |
|
Thank you for your reply, but I have a question.
|
|
During the bundling phase, rolldown can emit warnings that are better than runtime warnings (perhaps compiler-core should do the same), allowing developers to detect issues earlier. By modifying the compilation result to remove rolldown's ILLEGAL_REASSIGNMENT error and moving the warning to runtime, this approach is unreasonable. Both this PR and #11275 warn users at runtime about "Assignment to constant variable" in the code. Ultimately, users will need to adjust their code in either case. |
|
I understand your point. This is just my personal opinion, but v-model on reactive objects has become similar to undefined behavior in C compilers. I hope you can adopt a more compatible approach. Thank you for your patience.❤️ |
This PR fixes a compatibility issue with rolldown bundler and prevents potential runtime errors by replacing assignment statements with warnings when
v-modelis used directly on reactive objects.Problem Statement
When using
v-modeldirectly on reactive objects in<script setup>, Vue's compiler generates assignment code that attempts to reassignconstvariables:Generated problematic code:
This causes several issues:
ILLEGAL_REASSIGNMENTerrors in rolldown-based Vite buildsuseModel()proxies instead of the parent's update handlerWhy this worked before:
useModel()proxiesWhy it fails now:
Solution
Replace the problematic assignment with a warning that guides developers toward correct usage:
Before:
After:
Examples
Summary by CodeRabbit
New Features
v-modeldirectly on reactive constant variables, guiding users to use a reactive property or ref instead.Bug Fixes
v-modelon a property of a reactive constant variable does not trigger the new warning.Tests
v-model.