fix(shared): unwrap refs in toDisplayString #7306
Merged
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.
Closes #5578.
From the docs, https://vuejs.org/guide/essentials/reactivity-fundamentals.html#ref-unwrapping-in-templates:
This isn't quite true. The value of the ref will be passed through
JSON.stringify()
, even if the value is a primitive. For a number or a boolean this will just yield the expected string, but for a string value it leads to extra quotes and escaping:https://sfc.vuejs.org/#eNo9j8FOw0AMRH/F+BKQ6OYeFSRufIQvbXAgUXa9Wjv0EO2/420qbh579Ga840fO4XdjHPCsY5mzgbJt+Z3SHLMUgx0KT1BhKhKhc2tHidIoSQ3kuvBo8AY7JYBJZGjm5+6T11WA8CZl/SJ86l4oVUrn/ohwuAvjmNeLsSuAfX/AglOg3s3/BnzFo8wpXnJYVJLXvUfS46CEw1Gi7bxk04Q/ZlmHvtdpbE8uGqR89z6FsiWbIwfWeLoWuSkXBxM2hIdXrH+TUWJK
This PR aims to fix that problem by making
{{ object.foo }}
and{{ object.foo.value }}
equivalent for a refobject.foo
.Notes:
isRef
check is only performed when the value is an object, so it won't occur in the most common cases.toDisplayString
now calls itself recursively. While that has the potential to be problematic, in practice I don't think this introduces any new problems, asreplacer
is doing the same thing.