redux-state-sync
redux-state-sync copied to clipboard
Support react SSR like next-js
is there any intent to support Next-js ?
It'd be very good to support that. I'm not familiar with next, if I got time recently, I will look into it.
Actually, it's work fine with Next-js just by adding a condition, so in the With-Redux example on Next, at store.js I've written this,
export function initializeStore(initialState = exampleInitialState) { const isServer = typeof window === "undefined"; if (isServer) { const store = createStore( reducers, initialState, composeWithDevTools(applyMiddleware()) ); return store; } else { const store = createStore( reducers, initialState, composeWithDevTools(applyMiddleware(...middlewares)) ); initStateWithPrevTab(store); return store; } }
Thanks, I will take a look on this.
Actually, it's work fine with Next-js just by adding a condition, so in the With-Redux example on Next, at store.js I've written this,
export function initializeStore(initialState = exampleInitialState) { const isServer = typeof window === "undefined"; if (isServer) { const store = createStore( reducers, initialState, composeWithDevTools(applyMiddleware()) ); return store; } else { const store = createStore( reducers, initialState, composeWithDevTools(applyMiddleware(...middlewares)) ); initStateWithPrevTab(store); return store; } }
Thanks @mustafa-alfar It worked for my Next js app and resolved this issue of getting a large number of warnings on CLI.
Hi everyone,
I had a similar issue on redux-state-sync
in my NextJs project, my store initializer function was similar to @mustafa-alfar 's solution (separating server store from client store), everything was fine till I realized that my project is making too many files after run and visit some pages, and finally it crashed and logged this:
[Error: EMFILE: too many open files, open '/.../.next/static/chunks/main.js'] {
errno: -24,
code: 'EMFILE',
syscall: 'open',
path: '.../.next/static/chunks/main.js',
expose: false,
statusCode: 500,
status: 500
}
You can check the number of created files with next project after/before using this package with this command on terminal (7313 is my node server pid, replace it with yours):
ps aux | grep -i "node server"
while sleep 1; do sudo lsof -p 7313 | wc -l; done
and this is why I had to stop using this amazing package (redux-state-sync) in my next js (SSR) project. can you please take a look at this issue?
OS: MacOS v11.0.1 node: v14.15.0 next js: v10.0.0 redux-state-sync: v3.1.2 redux: v4.0.5 react-redux: v7.2.2
Hi @aynzad Thanks for reporting the issue. I try to investigate the issue when I got time.
any updates on this?