query
query copied to clipboard
size improvements
context
The "big" bundle size is a constant topic when TanStack Query is compared to other libraries. I think there are a few things that can be done to improve the situation:
don't transpile optional chaining
Optional chaining is used a lot in the codebase, and it's supported in 93.44% of all browsers. Transpiling it is quite costly:
- this.retryer?.continue()
+ this.retryer == null ? void 0 : this.retryer.continue()
switch to private class fields and methods
Private class fields are supported in 92.7% of all browsers. They have a bunch of advantages:
- they are private at runtime, not just at compile time
- because of that, they can be minified by terser
- as per this discussion, they would help us with circular references to private fields from within the QueryCache.
proposal
- adapt our current supported browserslist:
- Chrome >= 73
+ Chrome >= 84
- Firefox >= 78
+ Firefox >= 90
- Edge >= 79
+ Edge >= 84
- Safari >= 12.0
+ Safari >= 15
- iOS >= 12.0
+ iOS >= 15
- opera >= 53
+ opera >= 70
Out of these changes, Safari would be the "newest" supported browser, with a release date of September 2021. This would still likely mean at least 1.5 years of browser support for Safari when we release v5.
If people want to support older browsers, they can always transpile the code themselves.
- use private class fields and methods instead of the
privateTypeScript keyword.