Repository navigation
Conversation
useApolloClientDevTools ran its effect unconditionally, so passing an undefined or null ApolloClient (e.g. while it is still being created in state) threw a TypeError inside getCurrentState's setTimeout when getAllMutations read client.queryManager.mutationStore, and again on apolloClient.__actionHookForDevTools. Hooks cannot be called conditionally, so callers had no workaround. The effect now returns early when the client is falsy and re-runs once the client exists, since apolloClient is already in the dependency array. The parameter type is widened to ApolloClientType | null | undefined so this usage type-checks.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
useApolloClientDevToolsno longer throws aTypeErrorwhen the Apollo client isundefinedornull. Fixes #41.The client is unset on the first render when the app creates it asynchronously, for example in a
useEffectafter it restores a persisted cache. Hooks cannot be called conditionally, so callers had no workaround.In
packages/apollo-client/src/useApolloClientDevTools.tsthe effect now returns early when the client is not set.apolloClientis already in the dependency array, so the effect runs again when the client becomes available. The parameter type is nowApolloClientType | null | undefined, so a client held in state type-checks without a cast.#33 handled a null client with optional chaining inside the helper functions. I used one guard at the top of the effect instead: optional chaining stops the crash, but the hook still registers listeners and sends empty state for a client that does not exist yet. I can switch to the optional-chaining approach if you prefer it.
build/is not regenerated, same as #85.The new
src/__tests__/useApolloClientDevTools.test.tscoversundefinedandnullclients, and a mock client that must still get the listeners,__actionHookForDevToolsand the initialGQL:response. The two null-client tests fail without the fix (Cannot read properties of undefined (reading 'queryManager')) and pass with it.