Registry / storage / redux-storage-engine-cookies

redux-storage-engine-cookies

JSON →
library1.0.0jsnpmunverified

A cookie-based storage engine for redux-storage, version 1.0.0. It stores the entire Redux state in a single cookie via document.cookie. This engine is synchronous and blocking, with severe size limits (e.g., IE total cookie limit of 4096 bytes). It uses js-cookie for cookie handling and requires a Promise polyfill for IE<=11. Compared to other redux-storage engines (e.g., localStorage), cookies have cross-subdomain support but are far more restrictive in storage capacity.

npm install redux-storage-engine-cookies
INSTALL
IMPORT
SIG · REDUX-STORAGE-ENGI
R
redux-storage-engine-cookies
storagejavascriptv1.0.0
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.

createEngine
import createEngine from 'redux-storage-engine-cookies';
const createEngine = require('redux-storage-engine-cookies');
Default export; CommonJS require works but ESM is preferred.
createEngine (default import)
import createEngine from 'redux-storage-engine-cookies';
import { createEngine } from 'redux-storage-engine-cookies';
Named import is incorrect; the package uses a default export.
js-cookie (transitive dependency)
import Cookies from 'js-cookie';
const Cookies = require('js-cookie');
js-cookie is required by the engine; you can optionally use it directly.

Integrates the cookie engine with redux-storage: creates an engine, attaches middleware, and loads initial state from cookie.

import { createStore, applyMiddleware } from 'redux'; import { createMiddleware, createLoader } from 'redux-storage'; import createEngine from 'redux-storage-engine-cookies'; import reducer from './reducer'; const engine = createEngine('my-save-key', { expires: 7, // 7 days path: '/' }); const middleware = createMiddleware(engine); const store = createStore(reducer, applyMiddleware(middleware)); const load = createLoader(engine); load(store).then(() => console.log('State loaded from cookie')).catch(() => console.log('No saved state found'));
Debug
Known issues
gotchaBrowsers allocate very limited space to cookies (e.g., IE total 4096 bytes). Do not store large Redux states.
fix
Use localStorage if more space is needed, or compress the state.
affects: all
gotchadocument.cookie operations are synchronous and block the JS thread.
fix
Avoid frequent saves; consider debouncing.
affects: all
deprecatedSome browsers (IE<=11) do not support Promises; will throw if polyfill not provided.
fix
Install es6-promise polyfill before using the engine.
affects: all
gotchaIE has a bug with filenames in cookie path; avoid path like '/path/to/file.ext'.
fix
Use a directory path only, e.g., '/path/to/'.
affects: all
Errors
Common errors & fixes
Uncaught TypeError: Cannot read property 'then' of undefined
Promise is not polyfilled for older browsers (IE<=11).
fix
Add a Promise polyfill like es6-promise before using the engine.
Error: Invalid cookie value
The state string contains characters that break cookie encoding (e.g., semicolons).
fix
Ensure the state is serialized and encoded properly; js-cookie handles encoding, but custom strings may need escaping.
QuotaExceededError: Failed to execute 'setItem' on 'Storage'
Misleading error if mixing with localStorage; only relevant for cookie size exceeded.
fix
Reduce state size or use a different storage engine like redux-storage-engine-localstorage.
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies
js-cookierequiredUsed for setting and reading cookies with options like expires, path, domain, secure.
redux-storagerequiredThe parent library that this engine plugs into; provides the decorator and API.
Agent activity
20 hits · last 30 days
node
18
Amazon
1
Resources
redux-storage-engine-cookies — npm install redux-storage-engine-cookies · libregistry