react-server icon indicating copy to clipboard operation
react-server copied to clipboard

Redux isn't working with server rendering

Open Mlobaievskyi opened this issue 8 years ago • 4 comments

Tried to render pages with initial state from redux, but no luck. It always renders values from redux store only on client side. Used code from here

Mlobaievskyi avatar Jan 26 '17 23:01 Mlobaievskyi

Hey @MikeJSX not quite sure I follow? are elements not being sent down? Or are the initial values not correct? Did you modify the example code at all aside from calling createStore with the initial state value? is there an error?

sresant avatar Jan 26 '17 23:01 sresant

@sresant I didn't, used default code. As I understood store.getState() runs only on the client, I see redux value blinking after I try to reload page and also getting warning warning.js:36 Warning: React attempted to reuse markup in a container but the checksum was invalid. This generally means that you are using server rendering and the markup generated on the server was not what the client was expecting. React injected new markup to compensate which works but you have lost many of the benefits of server rendering. Instead, figure out why the markup being generated is different on the client or server: (client) !-- /react-text --><!-- react-text: 4 -- (server) !-- /react-text --></div></div>

Mlobaievskyi avatar Jan 27 '17 10:01 Mlobaievskyi

Also I noticed next error in server logs Warning: Failed prop type: The prop valueis marked as required inCounter, but its value is null. in Counter (created by Connect(Counter)) in Connect(Counter) in RootElement in Provider (created by RootProvider) in div (created by RootProvider) in RootProvider in RootElement But default value in redux is 0

Mlobaievskyi avatar Jan 27 '17 10:01 Mlobaievskyi

@MikeJSX weird, i can start up the example and even use an initial value of say value = 1 and it works fine? are you doing something else in the code or starting up react server with different settings?

sresant avatar Jan 27 '17 17:01 sresant