Registry / testing / react-cache-refresh

react-cache-refresh

JSON →
library1.0.5jsnpmunverified

A modern, lightweight React utility (v1.0.5) that automatically detects new app versions and clears browser caches (Service Worker caches, HTTP caches) to ensure users always receive the latest application version. It works by comparing a version string from a public meta.json with the current app version, and on mismatch clears caches and reloads. Key differentiators: built-in reload cooldown to prevent infinite loops, custom metadata path support, error resilience, and zero dependencies beyond React 18/19 peer dependency. Maintained with occasional releases.

npm install react-cache-refresh
INSTALL
IMPORT
SIG · REACT-CACHE-REFRES
R
react-cache-refresh
testingjavascriptv1.0.5
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

CacheBuster
✓ import { CacheBuster } from 'react-cache-refresh'
✗ import CacheBuster from 'react-cache-refresh'
Named export, not default.
clearAllCaches
✓ import { clearAllCaches } from 'react-cache-refresh/utils'
✗ import { clearAllCaches } from 'react-cache-refresh'
Utility function is exported from a separate subpath: 'react-cache-refresh/utils'.

Shows basic setup: create meta.json, wrap app with CacheBuster component, pass current version string.

// 1. Install: npm install react-cache-refresh // 2. Create public/meta.json: { "version": "1.0.0" } // 3. Wrap your app with CacheBuster import React from 'react'; import { CacheBuster } from 'react-cache-refresh'; import App from './App'; const VERSION = '1.0.0'; function Root() { return ( <CacheBuster currentAppVersion={VERSION} loadingComponent={<div>Checking for updates...</div>} > <App /> </CacheBuster> ); } export default Root;
Debug
Known issues
gotchaThe meta.json file must be placed in the public directory (or static serving directory) to be accessible at the root path. If placed elsewhere, use the metaJsonPath prop.
fix
Ensure meta.json is in public/ or set metaJsonPath prop to the correct URL path.
affects: >=1.0.0
gotchaThe currentAppVersion prop must exactly match the version string in meta.json for no cache refresh to occur. Version mismatches (e.g., '1.0.0' vs '1.0.0.0') will trigger a reload.
fix
Use a consistent versioning scheme and automate version bumps (e.g., CI pipeline).
affects: >=1.0.0
gotchaclearAllCaches is exported from 'react-cache-refresh/utils', not from the main entry. Importing from the wrong path may cause build errors in bundlers that don't resolve subpath exports.
fix
Use import { clearAllCaches } from 'react-cache-refresh/utils'.
affects: >=1.0.0
gotchaThe package is ESM-only (no CommonJS). Using require('react-cache-refresh') will fail in Node.js environments (e.g., SSR). Only import syntax works.
fix
Use import syntax. If you need CJS, consider transpiling with a bundler like webpack or esbuild.
affects: >=1.0.0
Errors
Common errors & fixes
Attempted import error: 'clearAllCaches' is not exported from 'react-cache-refresh'.
Importing clearAllCaches from the main export instead of 'react-cache-refresh/utils'.
fix
import { clearAllCaches } from 'react-cache-refresh/utils'
Module not found: Error: Can't resolve 'react-cache-refresh' in '/path/to/project'
The package is ESM-only and require() is used, or the package is not installed.
fix
Install the package with npm install react-cache-refresh and use import instead of require.
Upgrade
Version history
1.0.5latest on npm
Audit
Dependencies
reactrequiredPeer dependency required for JSX and hooks.
Agent activity
2 hits · last 30 days
node
2
Resources
react-cache-refresh — npm install react-cache-refresh · libregistry