Conversation
…s with "revalidateOnFocus" opt-in setting
…Properties" to explain cache key auto-generation
…nstead of object with create() and request()
- Introduced INFINITE_CACHE_TIME constant to handle cache expiration logic. - Updated isCacheExpired function to consider -1 as a valid cache time for infinite caching. - Modified getCache and pruneCache functions to accommodate new cache time logic. - Added cache reference counting utilities in a new cache-ref module for better cache management in React. - Updated useFetcher hook to integrate cache reference counting, ensuring proper cache cleanup. - Enhanced error handling and configuration options in useFetcher for improved user experience. - Created comprehensive integration tests for React components utilizing useFetcher, covering various scenarios including error handling, polling, and revalidation. - Implemented mockFetchResponse utility for simulating fetch responses in tests, improving test reliability and maintainability.
…ryParams, and PathParams templates
SWR Support + React hook + Stability improvements
…uestType for consistency
TypeScript Typings + integration improvements
devdgna
approved these changes
Jul 14, 2025
size-limit report 📦
|
Collaborator
|
+1 |
WlodarczykMarcin
approved these changes
Jul 14, 2025
red-game-dev
approved these changes
Jul 14, 2025
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.
Changelog
New Features
React
useFetcher(url, config)HookIntroduced 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
Added
staleTimeconfiguration 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
refetchOnFocussettingAdded support for
refetchOnFocus(boolean) feature that automatically refetches data when the browser tab becomes visible/focused.New
refetchOnReconnectsettingEnhance revalidation options by adding refetchOnReconnect (boolean) and updating related logic
Added
onRetry(response, attempt)interceptorImplemented
onRetryconfiguration to add interceptor based before each retry attempt.Added
onAbort(response)interceptorImplemented
onAbortconfiguration to add interceptor based before each abort attempt.Added
cacheErrorssettingImplemented
cacheErrors(boolean) configuration to cache error responses for improved error handling.Add
keepPreviousDatasettingWith
keepPreviousData: 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 toerrorobjectsThis 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**Add
select(data) => modifiedDatasetting to transform response data for better performance.Breaking changes
The
fetchersetting now accepts a function onlyPreviously it was an object with
createandrequest. To simplify this, it's enough to passfetcherfunction now. No instance creation is needed anymore.Removed old, unused
CanceledErrordetection for cancelled requestsUse
AbortErrororTimeoutErrorinstead.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
dataavailableThis will flatten up to the last
datain 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 examplesModule 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 shared
tsup.config.tsfile.Request and Cache Enhancements
Improved Cache Mutation and Busting
Enhanced
mutate()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
Replaced
queue-managerwithinflight-managerfor clearer request deduplication and timeout handling.shouldRetry can return null
shouldRetry can return
nullso 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
Bug Fixes
Base URL Handling
Ensured
baseURLdefaults 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.
Developer Experience
Exposed
subscribe(cacheKey, callback)functionAdded subscribe(cacheKey, callback) function for global real-time cache updates and data synchronization (tree-shakeable).
Exposed
abortRequest(cacheKey, error)functionAdded abortRequest(cacheKey, error) function for global request aborting (tree-shakeable).
Exposed
mutate(key, newData, settings)functionAdded
mutate(key, newData, {fetch: boolean})function for global request mutations (tree-shakeable).Exposed
setDefaultConfig(customConfig)functionAdded
setDefaultConfig(customConfig)function for default config overwrites (tree-shakeable).Exposed
isSlowConnection()functionAdded
isSlowConnection()function to detect slow connections in browsers (tree-shakeable).Exposed
getCache(key)functionAdded
getCache(key)function for directly retrieving cached data without triggering network requests (tree-shakeable).Exposed
setCache(key, response, ttl, staleTime)functionAdded
setCache(key, response, ttl, staleTime)function for low-level cache data management and direct cache entry creation (tree-shakeable).Exposed
deleteCache(key)functionAdded
deleteCache(key)function for selective cache invalidation and cleanup operations (tree-shakeable).Exposed
revalidate(key, isStaleRevalidation)functionAdded
revalidate(key, isStaleRevalidation)function for manual cache revalidation and fresh data fetching (tree-shakeable).Exposed
revalidateAll(type, isStaleRevalidation)functionAdded
revalidateAll(type, isStaleRevalidation)function for bulk revalidation of focus or online event-triggered cache entries (tree-shakeable).Exposed removeRevalidators(type) function
Added
removeRevalidators(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