Releases: MattCCC/fetchff
v4.1.1
v4.1.0
Improvements
- Enhance useFetcher hook with additional flags:
isError,isSuccess,isFirstLoad,isRefetching` isFetchingis now simply an alias forisLoading
Full Changelog: v4.0.4...v4.1.0
4.0.4
4.0.3
Bug fixes
- response parser should allow empty body
- isLoading flag should properly update when retry mechanism is used
Full Changelog: v4.0.2...v4.0.3
4.0.2
4.0.1
Improvements:
- Enhanced the getRetryAfterMs function to handle additional rate-limiting headers such as ratelimit-reset-after and ratelimit-reset-at for more robust retry delay calculations.
- Updated the withRetry function to handle HTTP 503 (Service Unavailable) errors in addition to HTTP 429 (Too Many Requests) for rate-limiting scenarios.
Fixes:
- Typing error when importing fetchff after 4.0.0 upgrade
- Avoid response cloning when defaulting in response parser (response.text() is utilized in such cases)
- Additional checks if blob or formData exist before to utilize them
Full Changelog: v4.0.0...v4.0.1
4.0.0
[4.0.0] – 14-07-2025
New Features
-
React
useFetcher(url, config)Hook
Introduced a new React hook for data fetching with built-in caching, loading states, and revalidation. You can import { useFetcher } from 'fetchff/react';
Check the new React Integration section in the documentationf or more infromation. -
Stale-While-Revalidate (SWR) Support
AddedstaleTimeconfiguration for serving stale data while revalidating in the background. -
Custom Cache Keys and Infinite Cache
Added support for custom cache key functions and possibility to cache infinitely for permanent caching scenarios. -
Added
refetchOnFocussetting
Added support forrefetchOnFocus(boolean) feature that automatically refetches data when the browser tab becomes visible/focused. -
New
refetchOnReconnectsetting
Enhance revalidation options by adding refetchOnReconnect (boolean) and updating related logic -
Added
onRetry(response, attempt)interceptor
ImplementedonRetryconfiguration to add interceptor based before each retry attempt. -
Added
onAbort(response)interceptor
ImplementedonAbortconfiguration to add interceptor based before each abort attempt. -
Added
cacheErrorssetting
ImplementedcacheErrors(boolean) configuration to cache error responses for improved error handling. -
Add
keepPreviousDatasetting
WithkeepPreviousData: truethe last query’s data remains visible until the new one finishes loading. -
Adaptive timeouts based on connection speed
implement adaptive timeouts based on connection speed for improved user experience -
Added
isCancelledproperty toerrorobjects
This boolean lets us to quickly preview if request has been aborted. -
Automatically set the
Content-Typeheader based on th body type (beyond just JSON)
Updated Content-Type handling in fetchff to automatically set based on request body type and enhanced isJSONSerializable checks. -
Add
select(data) => modifiedDatasetting
The setting to transform response data for better performance.
Breaking changes
-
The
fetchersetting now accepts a function only
Previously it was an object withcreateandrequest. To simplify this, it's enough to passfetcherfunction now. No instance creation is needed anymore. -
Removed old, unused
CanceledErrordetection for cancelled requests
UseAbortErrororTimeoutErrorinstead. -
Only some of request headers are considered in auto-key generation
This is to improve cache hit rates. Carefully curated list is available in the readme file. -
flattenData setting can flatten when there are more keys beyond just
dataavailable
This will flatten up to the lastdatain an object available, recursively. -
Single object typings over 4 generics
The typings have been improved for performance and clarity reasons. Usage:{response: ResponseData, body: RequestBody, params: QueryParams, urlPathParams: UrlPathParams}. Check documentation for more examples
Module and Build Improvements
-
Exports Field in package.json
Defined module entry points for Node.js, browser, and React environments to improve compatibility. -
Centralized Build Configuration
Simplified build setup with a sharedtsup.config.tsfile.
Request and Cache Enhancements
-
Improved Cache Mutation and Busting
Enhancedmutate()with revalidation and subscriber notifications.
getCachedResponsenow supports fullRequestConfigfor cache busting. -
Private Cache Implementation
Internal_cachemap is now fully encapsulated for better control and safety. -
Inflight Manager Refactoring
Replacedqueue-managerwithinflight-managerfor clearer request deduplication and timeout handling. -
shouldRetry can return null
shouldRetry can returnnullso to fallback toretryOnstatus codes. -
Interceptors running in right order
Interceptors are now running in right order - FIFO for all, LIFO for On Response + added a section in documentation about it. -
Removed properties from cache key auto-generation
The following behavior controlled cache key properties are removed:cache,mode,redirect,referrer,integrityas they should not impact the key generation.
Testing
- Added tests for React hook, concurrent request behavior, cache consistency, and memory cleanup.
Bug Fixes
-
Base URL Handling
EnsuredbaseURLdefaults to an empty string when undefined. -
Memory Management
Improved cleanup of timers and subscriptions to prevent leaks. -
Cancellable requests abortion
Returning an aborted controller would cause any new fetch to fail instantly. -
Previous Cancellable requests were blocked by dedupeTime
Deduplication logic should not block cancellable requests. -
Absolute URLs in API Handler
Apply endpoint config to absolute URLs defined if defined.
New API functions exposed
-
Exposed
subscribe(cacheKey, callback)function
Added subscribe(cacheKey, callback) function for global real-time cache updates and data synchronization (tree-shakeable). -
Exposed
abortRequest(cacheKey, error)function
Added abortRequest(cacheKey, error) function for global request aborting (tree-shakeable). -
Exposed
mutate(key, newData, settings)function
Addedmutate(key, newData, {fetch: boolean})function for global request mutations (tree-shakeable). -
Exposed
setDefaultConfig(customConfig)function
AddedsetDefaultConfig(customConfig)function for default config overwrites (tree-shakeable). -
Exposed
isSlowConnection()function
AddedisSlowConnection()function to detect slow connections in browsers (tree-shakeable). -
Exposed
getCache(key)function
AddedgetCache(key)function for directly retrieving cached data without triggering network requests (tree-shakeable). -
Exposed
setCache(key, response, ttl, staleTime)function
AddedsetCache(key, response, ttl, staleTime)function for low-level cache data management and direct cache entry creation (tree-shakeable). -
Exposed
deleteCache(key)function
AddeddeleteCache(key)function for selective cache invalidation and cleanup operations (tree-shakeable). -
Exposed
revalidate(key, isStaleRevalidation)function
Addedrevalidate(key, isStaleRevalidation)function for manual cache revalidation and fresh data fetching (tree-shakeable). -
Exposed
revalidateAll(type, isStaleRevalidation)function
AddedrevalidateAll(type, isStaleRevalidation)function for bulk revalidation of focus or online event-triggered cache entries (tree-shakeable). -
Exposed removeRevalidators(type) function
AddedremoveRevalidators(type)function for cleanup of revalidation event listeners and memory leak prevention (tree-shakeable). -
Better Type Safety
Improved TypeScript definitions and type clarity throughout codebase -
Code Organization
Modularized code structure for better maintainability
Other fixes
- reorder type parameters for consistency in error handling classes and interfaces
- correct type definitions for request body in endpoint functions in createApiFetcher()
- update interceptor types for consistency across request and response handling
- EndpointsConfiguration deprecated in favour of more strict typing definitions
3.3.0
[3.3.0] – 2025-06-03
🚀 Features & Improvements
-
Improved Retry Mechanism (#86)
- Retry logic has been enhanced to better handle intermittent failures and retryable status codes.
- Adds support for more intelligent retry timing and control, including improved respect for
Retry-Afterheaders. - Ensures that retry attempts are better aligned with real-world API expectations.
-
Cache Performance Optimization (#87)
- Rewrites internal cache handling for faster key lookup and improved memory efficiency.
- Reduces the overhead introduced during repeated request-response cycles.
- Aligns the caching flow more closely with
dedupeTimeandcacheTimesemantics.
-
Opt-In Request Deduplication via
dedupeTime(#88)- Also adds support for user-defined deduplication by specifying a
cacheKeyfunction. - Concurrent identical requests using the same
cacheKeywill now resolve the same promise to avoid redundant calls. - Ensures request isolation for cases where keys are dynamic (e.g. query params or headers-based hashing).
- Also adds support for user-defined deduplication by specifying a
-
Polling Behavior Enhancements (#89)
- Polling system now respects
maxPollingAttempts,pollingInterval, andshouldStopPollingwith better precision. - Adds consistent abort and timeout behavior for polling requests.
- Fixes edge cases where polling could continue indefinitely or silently fail.
- Polling system now respects
🧰 Internal & Developer Experience
- Added unit tests to cover retry edge cases and concurrent deduplication.
- Improved code structure for internal queue and cache coordination logic.
- Better error propagation for polling and retry failures, making debugging easier.
v3.2.3
🚀 Performance Improvements
-
Avoid unnecessary cache key generation
Optimized the caching logic to skip cache key creation when it's not needed, reducing overhead. -
Skip body data checks for GET-like requests
GET and similar methods now skip unnecessary body checks for better performance. -
Avoid sanitizing empty objects
Thesanitize()function now bypasses processing for empty objects to save time. -
Early bail-out when no parameters to replace
Optimized parameter replacement by exiting early if no replacements are required.
🐛 Bug Fixes
- Fixed duplicated request interceptor call
Resolved an issue where request interceptors could be invoked more than once per request under certain conditions.
🧪 Test Enhancements
-
Added tests for
createCacheKey()
Added unit tests to ensure the correctness and stability of cache key creation logic. -
Added tests for
sanitize()
Verified the behavior of input sanitization across edge cases with new tests.
🧹 Code Maintenance
-
Refactored
sanitize()function
Simplified the code structure and improved readability of the sanitization logic. -
Refactored
createCacheKey()function
Cleaned up and clarified logic in the cache key generation process.
These changes improve caching performance and ensure correctness through better testing and code clarity.
v3.2.1
Typings:
- Preserve typings of the responses in shouldRetry function
shouldStopPollingandonErrorshould properly infer response typings
Improvements:
- Typings: shouldRetry allows for non-promise functions in TS
- Retries can be triggered based on response data if
shouldRetryfunction check is positive, not only when there are errors
Docs:
- Documented resetTimeout for retries
- Added explainer for retries based on response payloads