Skip to content

Releases: MattCCC/fetchff

v4.1.1

05 Dec 01:05
25757c8

Choose a tag to compare

Improvements

  • Updated dev dependencies
  • OpenID Connect (OIDC) used for publishing to NPM

Full Changelog: v4.1.0...v4.1.1

v4.1.0

07 Aug 17:36

Choose a tag to compare

Improvements

  • Enhance useFetcher hook with additional flags: isError, isSuccess, isFirstLoad, isRefetching`
  • isFetching is now simply an alias for isLoading

Full Changelog: v4.0.4...v4.1.0

4.0.4

01 Aug 16:35

Choose a tag to compare

Improvements

  • Enhance refetch() functionality with Request Config by @MattCCC in #97
    • usage: refetch(forceRefresh, requestConfig)

Full Changelog: v4.0.3...v4.0.4

4.0.3

30 Jul 16:41

Choose a tag to compare

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

22 Jul 23:21

Choose a tag to compare

Bug fixes

  • Update react types path and enable dts generation for react build by @MattCCC in #95

Full Changelog: v4.0.1...v4.0.2

4.0.1

19 Jul 13:03

Choose a tag to compare

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

14 Jul 20:51

Choose a tag to compare

[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
    Added staleTime configuration 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 refetchOnFocus setting
    Added support for refetchOnFocus (boolean) feature that automatically refetches data when the browser tab becomes visible/focused.

  • New refetchOnReconnect setting
    Enhance revalidation options by adding refetchOnReconnect (boolean) and updating related logic

  • Added onRetry(response, attempt) interceptor
    Implemented onRetry configuration to add interceptor based before each retry attempt.

  • Added onAbort(response) interceptor
    Implemented onAbort configuration to add interceptor based before each abort attempt.

  • Added cacheErrors setting
    Implemented cacheErrors (boolean) configuration to cache error responses for improved error handling.

  • Add keepPreviousData setting
    With keepPreviousData: true the 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 isCancelled property to error objects
    This boolean lets us to quickly preview if request has been aborted.

  • Automatically set the Content-Type header 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) => modifiedData setting
    The setting to transform response data for better performance.

Breaking changes

  • The fetcher setting now accepts a function only
    Previously it was an object with create and request. To simplify this, it's enough to pass fetcher function now. No instance creation is needed anymore.

  • Removed old, unused CanceledError detection for cancelled requests
    Use AbortError or TimeoutError instead.

  • 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 data available
    This will flatten up to the last data in 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 shared tsup.config.ts file.

Request and Cache Enhancements

  • Improved Cache Mutation and Busting
    Enhanced mutate() with revalidation and subscriber notifications.
    getCachedResponse now supports full RequestConfig for cache busting.

  • Private Cache Implementation
    Internal _cache map is now fully encapsulated for better control and safety.

  • Inflight Manager Refactoring
    Replaced queue-manager with inflight-manager for clearer request deduplication and timeout handling.

  • shouldRetry can return null
    shouldRetry can return null so to fallback to retryOn status 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, integrity as 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
    Ensured baseURL defaults 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
    Added mutate(key, newData, {fetch: boolean}) function for global request mutations (tree-shakeable).

  • Exposed setDefaultConfig(customConfig) function
    Added setDefaultConfig(customConfig) function for default config overwrites (tree-shakeable).

  • Exposed isSlowConnection() function
    Added isSlowConnection() function to detect slow connections in browsers (tree-shakeable).

  • Exposed getCache(key) function
    Added getCache(key) function for directly retrieving cached data without triggering network requests (tree-shakeable).

  • Exposed setCache(key, response, ttl, staleTime) function
    Added setCache(key, response, ttl, staleTime) function for low-level cache data management and direct cache entry creation (tree-shakeable).

  • Exposed deleteCache(key) function
    Added deleteCache(key) function for selective cache invalidation and cleanup operations (tree-shakeable).

  • Exposed revalidate(key, isStaleRevalidation) function
    Added revalidate(key, isStaleRevalidation) function for manual cache revalidation and fresh data fetching (tree-shakeable).

  • Exposed revalidateAll(type, isStaleRevalidation) function
    Added 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

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

03 Jun 17:04

Choose a tag to compare

[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-After headers.
    • 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 dedupeTime and cacheTime semantics.
  • Opt-In Request Deduplication via dedupeTime (#88)

    • Also adds support for user-defined deduplication by specifying a cacheKey function.
    • Concurrent identical requests using the same cacheKey will 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).
  • Polling Behavior Enhancements (#89)

    • Polling system now respects maxPollingAttempts, pollingInterval, and shouldStopPolling with better precision.
    • Adds consistent abort and timeout behavior for polling requests.
    • Fixes edge cases where polling could continue indefinitely or silently fail.

🧰 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

22 May 21:24

Choose a tag to compare

🚀 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
    The sanitize() 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

06 May 02:41

Choose a tag to compare

Typings:

  • Preserve typings of the responses in shouldRetry function
  • shouldStopPolling and onError should properly infer response typings

Improvements:

  • Typings: shouldRetry allows for non-promise functions in TS
  • Retries can be triggered based on response data if shouldRetry function check is positive, not only when there are errors

Docs:

  • Documented resetTimeout for retries
  • Added explainer for retries based on response payloads