cereallarceny / cra-ssr

[DEPRECATED] Server-side rendering with create-react-app, React Router v4, Helmet, Redux, and Thunk
484 stars 118 forks source link

SSR not working when call registerServiceWorker #2

Closed rizalibnu closed 6 years ago

rizalibnu commented 6 years ago

I try to comment function call registerServiceWorker in /src/index.js, SSR is working correctly, but when uncomment that, SSR not working. I think this is very important because disable service worker make app can't support offline.

// file : /src/index.js

import React from 'react';
import { render } from 'react-dom';
import { Provider } from 'react-redux';
import { Route } from 'react-router-dom';
import { ConnectedRouter } from 'react-router-redux';
import store, { history } from './store';
// import registerServiceWorker from './registerServiceWorker';

import App from './containers/app';

import './index.css';

render(
  <Provider store={store}>
    <ConnectedRouter history={history}>
      <Route component={App} />
    </ConnectedRouter>
  </Provider>,
  document.getElementById('root')
);

// registerServiceWorker();
cereallarceny commented 6 years ago

Can you be more specific about the error you're getting? Or why your app shouldn't be used offline?

cereallarceny commented 6 years ago

@rizalibnu Is this because you're trying to create a browser history from the server side?

Bramas commented 6 years ago

As I said in #5 , serviceworker tells the browser to use the cached page index.html in priority. It make sense that offline use with service worker and ssr are incompatible, because offline website must use a base page kept in cache that is independent from the data being fetch, and SSR returns the full page containing the latest data. They are incompatible but still it's usefull to have SSR for older browser that don't support service worker so that the first load of the page is faster.

cereallarceny commented 6 years ago

Service workers aren't supported in server-side rendering.