aohua / redux-state-sync

A lightweight middleware to sync your redux state across browser tabs
MIT License
233 stars 29 forks source link

Memory Leak on Azure #167

Open TubaBayraktutar opened 1 year ago

TubaBayraktutar commented 1 year ago

Hello,

I am using the latest version of redux-state-sync. As you can see in the graph below, the usage of RAM is constantly increasing.

Node version is 14.16.1

image

Store configuration;

import { createStore, applyMiddleware, compose } from 'redux';

import {
  createStateSyncMiddleware,
  withReduxStateSync,
  initStateWithPrevTab
} from 'redux-state-sync';

import Router from 'next/router';

import reducer from './reducer';

import middlewares from './middleware';
import { actionType } from './actions';

const composeEnhancers = (typeof window !== 'undefined' && window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__) || compose;

const stateSyncConfig = {
  channel: 'my_project_redux_state_sync',
  whitelist: [
    actionType.StateClear,
    'StateMerge',
    'StatesMerge',
    'PrependToKey',
    'AddToKey',
    'RemoveFromKey'
  ]
};

export const initStore =
  (initialState = {
    apiUrl: process.env.API_URL || 'http://localhost:5000',
    auctionHubState: 'Initializing'
  }) => {
    console.log(JSON.stringify(process.env));
    const storeMiddlewares = [createStateSyncMiddleware(stateSyncConfig)];

    if (process.browser && Router.route === '/home') {

      storeMiddlewares.push(...middlewares);
    }

    const store =
      createStore(
        withReduxStateSync(reducer),
        initialState,
        composeEnhancers(
          applyMiddleware(...storeMiddlewares)
        )
      );

    if (process.browser && Router.route !== '/operator') {

      initStateWithPrevTab(store);
    }

    return store;
  };