schiehll / react-alert

alerts for React
MIT License
608 stars 98 forks source link

ract-alert doesn't work with ssr #75

Closed stelro closed 6 years ago

stelro commented 6 years ago

Hello, seems that react-alert doesn't work with SSR and react 16.2.0! Any suggestion? It seems that whatever I wrap in AlertProvider it doesn't renderToString.

stelro commented 6 years ago

With some debugging I did, I think the problem is with that piece of code :

if (this.state.isClient) {
      if (!this.alertRootElement) {
        this.alertRootElement = document.createElement("div");
        document.body.appendChild(this.alertRootElement);
        console.log("created");
      }
    } else {
      return null;
    }

it prevents the component all of its children to be rendered on the server side.

schiehll commented 6 years ago

Hey @stelro thank you for open the issue!

I think the problem is now fixed in the latest release, please give it a try and feel free to reopen it if the problem persist.

The new version uses the new context api so you will need React v16.3.0 to be able to use it.