-
Notifications
You must be signed in to change notification settings - Fork 20
Turn off structural sharing for bigint queries #404
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@timostamm was seeing a noisy log after upgrading tanstack-query that said:
We could also implement a |
Signed-off-by: Steve Ayers <sayers@buf.build>
d077c52
to
2f12c77
Compare
I think we can enable this in the default options we provide. Just on my phone so don't have a link but it should work if we add it there. |
Do you mean adding it here? Would we want to disable this for all queries though by default? Or is this only used on a case-by-case basis and not added automatically to every query. |
Given the current default options hash function is also only really needed for bigint support, I think it follows that disabling structural sharing would be also be required. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's take a look at the feature before we turn it off:
React Query uses a technique called "structural sharing" to ensure that as many references as possible will be kept intact between re-renders. If data is fetched over the network, usually, you'll get a completely new reference by json parsing the response. However, React Query will keep the original reference if nothing changed in the data. If a subset changed, React Query will keep the unchanged parts and only replace the changed parts.
Given that React Query invalidates queries somewhat regularly, it would be nice not to re-render if the data hasn't changed. This can be implemented with a per-query option that uses protobuf-es' equals()
.
It might be better to defer until we finish compat with protobuf-es v2, since it will also require changes to query keys and the safe updater. I suggest we create an issue to track support for structural sharing - and mention how to disable the feature.
I'd be down for that |
OK, I'll close this PR and create an issue instead to figure out a better solution. |
Tanstack seems to have added a noisy
console.error
log for queries that return data that is not JSON-serializable. They recommend to either turn offstructuralSharing
in your queries or to return JSON serializable data from your queryFn.For the sake of simplicity, we are simply turning off
structuralSharing
in the tests that return a BigInt as part of their response.