T
TanStack•3y ago
conscious-sapphire

Option to reconcile result object

I am wondering how does solid query handle reactivity for results. If my query result returns an object, and I query it again and the result is the same object with 1 different key, will solid query handle this? I looked into the code and there's no use of solid's reconcile method.
9 Replies
conscious-sapphire
conscious-sapphireOP•3y ago
so I suspect that the entire object is replaced at the moment without keeping any reactivity. Can someone confirm this? If so, would it be possible to provide an option to reconcile the result across queries to maintain reactivity?
adverse-sapphire
adverse-sapphire•3y ago
Hello! Apologies for the late reply. Yeah currently the data is immutable between key changes. But your suggestion is great! I have been thinking about adding a reconcile option to solid-query. We will definitely keep this in mind for the next major release of solid-query!
adverse-sapphire
adverse-sapphire•3y ago
As for now, there is Keyed component maintained by the SolidJS community you can use to prevent your components from being re run https://github.com/solidjs-community/solid-primitives/tree/main/packages/keyed#key
GitHub
solid-primitives/packages/keyed at main · solidjs-community/solid-p...
A library of high-quality primitives that extend SolidJS reactivity. - solid-primitives/packages/keyed at main · solidjs-community/solid-primitives
conscious-sapphire
conscious-sapphireOP•3y ago
Oh thanks! Is there an ETA for the next major version? Also, couldn't this be released in a minor? It wouldn't be a breaking change as it would be optional
adverse-sapphire
adverse-sapphire•3y ago
Hi there! Actually hehe. We already support it now! You can use the structuralSharing option on your query options to reconcile your data between query updates!
adverse-sapphire
adverse-sapphire•3y ago
No description
plain-purple
plain-purple•3y ago
Just confirmed that this works as expected - can set this globally in the root client default options like so:
import { reconcile } from 'solid-js/store'

const queryClient = new QueryClient({
defaultOptions: {
queries: {
structuralSharing(oldData, newData) {
return reconcile(newData)(oldData)
},
},
},
})
import { reconcile } from 'solid-js/store'

const queryClient = new QueryClient({
defaultOptions: {
queries: {
structuralSharing(oldData, newData) {
return reconcile(newData)(oldData)
},
},
},
})
@Aryan I have a branch that overrides the default structuralSharing fn with this custom one in solid-query, but on second thought perhaps it's better left to the user to setup ala the above? We could add a note to the docs with the example 🤔.
adverse-sapphire
adverse-sapphire•3y ago
Yeah having the structuralSharing function be un-opinionated is probably better. I can add an example in the docs to show how reconcile will work with this option
xenial-black
xenial-black•11mo ago
I think this fixed my issue, did you update the docs. i cant find it, if not i can make a pr soonish
{
defaultOptions: {
queries: {
reconcile(oldData, newData) {
return reconcile(newData)(oldData);
},
},
},
}
{
defaultOptions: {
queries: {
reconcile(oldData, newData) {
return reconcile(newData)(oldData);
},
},
},
}

Did you find this page helpful?