-
Notifications
You must be signed in to change notification settings - Fork 786
useSubscription triggers unnecessary rerenders #3549
Comments
Same issue here |
My team is also seeing this issue. Causing way too many re-renders. We're going to try the same approach as mentioned by @borremosch. |
EDIT: re-reading your original issue, I think my below is actually irrelevant, and the real reason is just that the @borremosch @filipmares I'm not 100% if this will solve your issues, but if you are defining your The general way to resolve this is to use React's Digging deeper to confirm the theory, I found the related code at the following:
public setOptions(
newOptions: CommonOptions<TOptions>,
storePrevious: boolean = false
) {
if (storePrevious && !equal(this.options, newOptions)) {
this.previousOptions = this.options;
}
this.options = newOptions;
} In particular, the /**
* Performs a deep equality check on two JavaScript values, tolerating cycles.
*/
export function equal(a: any, b: any): boolean {
// ..snip..
} |
I am seeing this happening when enabling reconnect. A rerender is triggered every XX seconds (depends on timeout/keep-alive). Any idea on how to prevent this rerender? |
Today I faced the same issue with @0xdevalias , could you elaborate your solution for me? It sounds good, but I'm not sure I follow. |
Hi @filipmares , did you resolve this issue? If yes, could you tell me how to? |
I am using
useSubscription
in one of my components. I do not use any of the return values, because I am using a complicated protocol in my subscription, and I do not want to act on every message I receive. Instead, I am using theonSubscriptionData
callback function. I was surprised to see that even though I only update state on some of the received messages, my component is rerendering continuously. It seems that usinguseSubscription
will trigger a re-render every time subscription data is received, even if it is discarded.It would be very useful to have a version of
useSubscription
that does not trigger a re-render whenever data is received, and instead let the user decide when to make state changes inonSubscriptionData
. For now, I have had to put my subscription in a sub-component, just to make the superfluous re-rendering computationally cheaper.I am using @apollo/react-hooks version
3.1.2
.The text was updated successfully, but these errors were encountered: