Skip to content

Conversation

@EduardMcfly
Copy link
Member

This pull request refactors the subscription management logic in the useQuery React hook to improve how updates are handled during re-observation and to simplify the RxJS integration. The changes introduce a mechanism to pause and resume change notifications, ensuring that updates are not emitted during certain operations, such as re-observing with new options.

Improvements to subscription and update management:

  • Removed the use of observeOn(asapScheduler) and instead introduced a pauseChanges flag to control when updates are emitted to React, preventing unnecessary renders during certain operations.
  • Added a lastSubscription symbol property to the observable, storing the current subscription along with pauseChanges and activateChanges methods to allow pausing and resuming change notifications.
  • Updated the unsubscribe logic to immediately unsubscribe instead of using a delayed timeout, simplifying resource cleanup.

Enhancements to re-observation behavior:

  • Modified the useResubscribeIfNecessary function to pause change notifications before calling reobserve and resume them afterward, preventing intermediate updates during the re-observation process.

@github-actions
Copy link

size-limit report 📦

Path Size
import { ApolloClient, InMemoryCache, HttpLink } from "@apollo/client" (CJS) 42.84 KB (0%)
import { ApolloClient, InMemoryCache, HttpLink } from "@apollo/client" (production) (CJS) 37.8 KB (0%)
import { ApolloClient, InMemoryCache, HttpLink } from "@apollo/client" 32.65 KB (0%)
import { ApolloClient, InMemoryCache, HttpLink } from "@apollo/client" (production) 26.81 KB (0%)
import { ApolloProvider } from "@apollo/client/react" 5.91 KB (0%)
import { ApolloProvider } from "@apollo/client/react" (production) 994 B (0%)
import { useQuery } from "@apollo/client/react" 7.39 KB (+0.56% 🔺)
import { useQuery } from "@apollo/client/react" (production) 2.41 KB (+0.95% 🔺)
import { useLazyQuery } from "@apollo/client/react" 7.11 KB (0%)
import { useLazyQuery } from "@apollo/client/react" (production) 2.16 KB (0%)
import { useMutation } from "@apollo/client/react" 6.47 KB (0%)
import { useMutation } from "@apollo/client/react" (production) 1.52 KB (0%)
import { useSubscription } from "@apollo/client/react" 6.79 KB (0%)
import { useSubscription } from "@apollo/client/react" (production) 1.82 KB (0%)
import { useSuspenseQuery } from "@apollo/client/react" 8.55 KB (0%)
import { useSuspenseQuery } from "@apollo/client/react" (production) 3.63 KB (0%)
import { useBackgroundQuery } from "@apollo/client/react" 8.34 KB (0%)
import { useBackgroundQuery } from "@apollo/client/react" (production) 3.4 KB (0%)
import { useLoadableQuery } from "@apollo/client/react" 8.29 KB (0%)
import { useLoadableQuery } from "@apollo/client/react" (production) 3.39 KB (0%)
import { useReadQuery } from "@apollo/client/react" 6.6 KB (0%)
import { useReadQuery } from "@apollo/client/react" (production) 1.65 KB (0%)
import { useFragment } from "@apollo/client/react" 6.66 KB (0%)
import { useFragment } from "@apollo/client/react" (production) 1.71 KB (0%)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant