Gathering detailed insights and metrics for redux-state-sync-per-instance
Gathering detailed insights and metrics for redux-state-sync-per-instance
Gathering detailed insights and metrics for redux-state-sync-per-instance
Gathering detailed insights and metrics for redux-state-sync-per-instance
A lightweight middleware to sync your redux state across browser tabs
npm install redux-state-sync-per-instance
Typescript
Module System
Node Version
NPM Version
75.2
Supply Chain
98.4
Quality
73.6
Maintenance
100
Vulnerability
98.2
License
JavaScript (92.12%)
HTML (6.1%)
CSS (1.69%)
Shell (0.1%)
Total Downloads
2,664
Last Day
2
Last Week
7
Last Month
22
Last Year
1,187
MIT License
238 Stars
122 Commits
27 Forks
4 Watchers
41 Branches
11 Contributors
Updated on Apr 10, 2025
Minified
Minified + Gzipped
Latest Version
3.1.5
Package Id
redux-state-sync-per-instance@3.1.5
Unpacked Size
2.13 MB
Size
914.12 kB
File Count
77
NPM Version
6.14.2
Node Version
10.16.3
Cumulative downloads
Total Downloads
1
22
A lightweight middleware to sync your redux state across browser tabs. It will listen to the Broadcast Channel and dispatch exactly the same actions dispatched in other tabs to keep the redux state in sync.
It syncs your redux store across tabs with very minimal configuration.
Thanks to BroadcastChannel, we now have a more efficient way to communicate between tabs instead of using any type of local storage. However, Not all the browsers support BroadcastChannel API for now. So I used pubkey's BroadcastChannel to find the best way to communicate between tabs for redux-state-sync. pubkey's BroadcastChannel will make sure that the communication between tabs always works.
Install with npm.
npm install --save redux-state-sync
Install with yarn
yarn add redux-state-sync
Install with npm.
npm install --save-dev @types/redux-state-sync
Install with yarn
yarn add --dev @types/redux-state-sync
Types are defined here
Please take note that BroadcastChannel can only send data that is supported by the structured clone algorithm (Strings, Objects, Arrays, Blobs, ArrayBuffer, Map), so you need to make sure that the actions that you wanna send to other tabs doesn't include any functions in the payload.
If you are using redux-persist, you may need to blacklist some of the actions that is triggered by redux-persist. e.g. persist/PERSIST, persist/REHYDRATE, etc.
Create the state sync middleware with config:
1import { createStore, applyMiddleware } from 'redux'; 2import { createStateSyncMiddleware, initMessageListener } from 'redux-state-sync'; 3 4const config = { 5 // TOGGLE_TODO will not be triggered in other tabs 6 blacklist: ['TOGGLE_TODO'], 7}; 8const middlewares = [createStateSyncMiddleware(config)]; 9const store = createStore(rootReducer, {}, applyMiddleware(...middlewares)); 10// this is used to pass store.dispatch to the message listener 11initMessageListener(store);
Init new tabs with existing state:
1import { createStore, applyMiddleware } from 'redux'; 2import { createStateSyncMiddleware, initStateWithPrevTab } from 'redux-state-sync'; 3 4const config = { 5 // TOGGLE_TODO will not be triggered in other tabs 6 blacklist: ['TOGGLE_TODO'], 7}; 8const middlewares = [createStateSyncMiddleware(config)]; 9const store = createStore(rootReducer, {}, applyMiddleware(...middlewares)); 10// init state with other tabs 11initStateWithPrevTab(store); 12// initMessageListener(store);
withReduxStateSync
1import { withReduxStateSync } from 'redux-state-sync'; 2const rootReducer = combineReducers({ 3 todos, 4 visibilityFilter, 5}); 6 7export default withReduxStateSync(rootReducer);
redux-persist
, because you will always inite your app with the state in the storage. However, if you don't want to persist the state in the storage and still want to init new tabs with opening tabs' state, you can follow the example above.Unique name for Broadcast Channel
type: String
default: "redux_state_sync"
1const config = { 2 channel: 'my_broadcast_channel', 3}; 4const middlewares = [createStateSyncMiddleware(config)];
A function to let you filter the actions as you wanted.
type: Function
default: null
1const config = { 2 // All actions will be triggered in other tabs except 'TOGGLE_TODO' 3 predicate: action => action.type !== 'TOGGLE_TODO', 4}; 5const middlewares = [createStateSyncMiddleware(config)];
A list of action types that you don't want to be triggered in other tabs.
type: ArrayOf(<String>)
default: []
1const config = { 2 // All actions will be triggered in other tabs except 'TOGGLE_TODO' 3 blacklist: ['TOGGLE_TODO'], 4}; 5const middlewares = [createStateSyncMiddleware(config)];
Only actions in this list will be triggered in other tabs.
type: ArrayOf(<String>)
default: []
1const config = { 2 // Only 'TOGGLE_TODO' will be triggered in other tabs 3 whitelist: ['TOGGLE_TODO'], 4}; 5const middlewares = [createStateSyncMiddleware(config)];
Redux-state-sync is using BroadcastChannel to comunicate between tabs. broadcastChannelOption is the option passed to broadcastChannel when we creating the channel.
type: Object
default: null
1const config = { 2 // Only 'TOGGLE_TODO' will be triggered in other tabs 3 whitelist: ['TOGGLE_TODO'], 4 // enforce a type, oneOf['native', 'idb', 'localstorage', 'node'] 5 broadcastChannelOption: { type: 'localstorage' }, 6}; 7const middlewares = [createStateSyncMiddleware(config)];
Please check the example_immutable folder.
Prepare the initial state for sending to other tabs.
type: Function
default: state => state
1const config = { 2 // Map immutable object to js 3 prepareState: state => state.toJS(), 4}; 5const middlewares = [createStateSyncMiddleware(config)];
1import { combineReducers } from 'redux-immutable'; 2import { withReduxStateSync } from 'redux-state-sync'; 3const rootReducer = combineReducers({ 4 todos, 5 visibilityFilter, 6}); 7 8export default withReduxStateSync(appReducer, state => Immutable.fromJS(state));
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 8/24 approved changesets -- score normalized to 3
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
127 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-06-23
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreLast Day
0%
2
Compared to previous day
Last Week
0%
7
Compared to previous week
Last Month
-38.9%
22
Compared to previous month
Last Year
48.7%
1,187
Compared to previous year