refactor(vue-query): use shallowRef to improve performance #5493
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.
Hey there! 👋🏻
This PR refactors the
useQueries
composable to use ashallowRef
instead of aref
to define the state.If an object is assigned as a ref's value, the object is made deeply reactive. That is the case in the
useQueries
composable. Meaning if we had a hugedata
object, all its properties would be reactive, causing performance issues.A
shallowRef
, in comparison, does not convert the object. The inner value is stored and exposed as-is.This PR is in draft because I believe we can do the same optimization in the
useQuery
composable. I need to play with it and ensure nothing is breaking before making changes.Related PR on VueUse repository to add a
toShallowRef
helper that could be used inuseQuery
.Linked Discussion: #5400