-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Remove freezeResults option, assuming always true. #5153
Conversation
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.
Looks great @benjamn - exciting! 🎉
I'm really glad we are doing this, but I do wonder if we can prune more of the freezing behavior to be part of the dev only build? There are a couple call sites to |
As promised in the Apollo Client 2.6 blog post, all cache results will be frozen/immutable in the next major version (3.0): https://blog.apollographql.com/whats-new-in-apollo-client-2-6-b3acf28ecad1
@jbaxleyiii There's one spot that I see in if (process.env.NODE_ENV !== 'production') {
assertSelectionSetForIdValue(contextValue.store, field, readStoreResult.result);
maybeDeepFreeze(readStoreResult);
} As you can see, it's wrapped with a However, that guard does not remove the I think this situation will improve once we move the relevant |
f14d6b2
to
af94014
Compare
// In development, we need to clone scalar values so that they can be | ||
// safely frozen with maybeDeepFreeze in readFromStore.ts. In production, | ||
// it's cheaper to store the scalar values directly in the cache. | ||
return process.env.NODE_ENV === 'production' ? value : cloneDeep(value); |
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.
@jbaxleyiii Thanks to your comment I realized this clone is necessary to avoid accidentally freezing user-provided scalar values in development, as I'm now testing in af94014.
Merging this preemptively so that @hwillson can begin work on restructuring the repo starting from the |
Due to the immutable of talkList the list had to be copied. Ref: apollographql/apollo-client#5153
This commit allows the default value of the `assumeImmutableResults` option to be determined by the cache (any implementation of `ApolloCache`), which allows our implementation of `InMemoryCache` to express the safety of assuming `assumeImmutableResults` is `true`, unlocking significant performance savings (fewer defensive deep copies of query results), even if `assumeImmutableResults` is not configured. Related past PRs: - #4543 - #5153 - #9680 - [Apollo Client 2.6 blog post](https://www.apollographql.com/blog/announcement/frontend/whats-new-in-apollo-client-2-6/#rewarding-immutability)
This option was first added in Apollo Client 2.6, as a way to help enforce immutability of cache results: #4514
As promised in the Apollo Client 2.6 blog post, all cache results will be frozen/immutable in the next major version (3.0):
I have not yet removed the
assumeImmutableResults
option from theApolloClient
constructor, since cache implementations other thanapollo-cache-inmemory
might not return immutable results.