fix(runtime-code): warn using array created without ref as a ref inside v for in script setup (fix: #10655) #10784
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Close #10655
In production mode, after inlining the
<script setup>
, variables created are not exposed in thesetupResult
nor compiled to provide ref props with the actual reference, as it is for references created usingref()
. This causes string refs to lose their reactivity in therenderTemplateRef.ts
file. However, in development mode, all variables are exposed in thesetupResult
, and string refs with array values work as expected.To address this issue, I have added a warning in the PR for this specific case. One potential solution could be to forbid the use of string refs other than those created with
ref()
, as other cases (e.g., reactive, ...) seem to be unhandled inrenderTemplateRef.ts
. We could introduce a compile-time error if anything other thanref()
is used as a string ref for<script setup>
.Implementation details: I could not use setupResults as it unrefs the ref, and reactive and ref are indistinguishable, so I used
devtoolsRawSetupState
. However, there might be a better way or a need to introduce anotherrawSetupState
variable specifically for the development mode. I'm open to suggestions on how to handle this more effectively.I'm looking forward to the team's input and suggestions on how to best resolve this issue. Please share your thoughts and insights to help us find an optimal solution.
Screen.Recording.2024-04-24.at.5.46.32.PM.mov