erikras / react-redux-universal-hot-example

A starter boilerplate for a universal webapp using express, react, redux, webpack, and react-transform
MIT License
12k stars 2.5k forks source link

Dummy @asyncConnect is required for server side rendering to work #1078

Open krukid opened 8 years ago

krukid commented 8 years ago

I've encountered a rather puzzling issue today, when a page reload yielded:

Server-side React render was discarded. Make sure that your initial render does not contain any client-side code.

Typically, when there's a difference between CSR and SSR, a short snippet of conflicting markup is shown, but not this time. As it happens, I have been heavily experimenting with client-side optimizations, so it took me quite a while to figure out none of that was at fault.

After substantial amount of hair pulling I've managed to narrow down the issue to the following fact that can be easily reproduced on the master branch: if none of the rendered components for the current route contain the @asyncConnect decorator, then SSR fails and you get the misleading message.

For now, I've worked around this issue in my project by defining a dummy @asyncConnect on my topmost component:

import React, { Component } from 'react';
import { asyncConnect } from 'redux-async-connect';

@asyncConnect([{
  promise: () => Promise.resolve()
}])
export default class App // ...
Node v4.3.1
Npm 2.14.12
mmahalwy commented 8 years ago

I dont think that's the case. What happens when you just remove @asyncConnect?

krukid commented 8 years ago

Commenting out @asyncConnect consistently causes the said message on SSR for my project. Yesterday I've checked out RRUHE master branch from scratch and removing @asyncConnect from the App container resulted in the same behavior on the home page. Source HTML showed no pre-generated content.

jspangler commented 8 years ago

Getting the same issue, no code is rendered server side unless including this dummy code.

Node v4.2.3
Npm 2.14.7
joshbuckley182 commented 8 years ago

I'm also having this issue. I think it might be related to this line: https://github.com/erikras/react-redux-universal-hot-example/blob/master/src/server.js#L94

In fact, it looks like server rendering (loadOnServer) is provided by redux-async-connect (https://github.com/erikras/react-redux-universal-hot-example/blob/master/src/server.js#L91-L104).

joshbuckley182 commented 8 years ago

Related: https://github.com/Rezonans/redux-async-connect/issues/69

FisherYu-CN commented 8 years ago

After changing back to redux-async-connect v1.0.0-rc3 the problem is gone. Thanks for the tips guys.