Skip to content

Upgrade react/react-dom to 15.6.1 and react-router to 4.1.1 #90

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,15 @@
"isomorphic-fetch": "^2.2.1",
"join-classnames": "^1.0.0",
"npm-run-all": "^4.0.1",
"react": "^15.0.1",
"react-dom": "^15.0.1",
"react": "^15.6.1",
"react-dom": "^15.6.1",
"react-helmet": "^5.0.3",
"react-redux": "^5.0.2",
"react-router": "^3.0.2",
"react-router": "^4.1.1",
"react-router-dom": "^4.1.1",
"react-router-redux": "^4.0.7",
"redux": "^3.4.0",
"redux-thunk": "^2.0.1",
"string-hash": "^1.1.0"
}
}
}
8 changes: 4 additions & 4 deletions src/app/_client.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { Router, browserHistory } from 'react-router';
import { syncHistoryWithStore } from 'react-router-redux';
import React from 'react';
import { BrowserRouter } from 'react-router-dom';
import {render} from 'react-dom';
import {Provider} from 'react-redux';

import routes from './routes.js';
import getStore from './store.js';

const store = getStore();
const history = syncHistoryWithStore(browserHistory, store)

render(
<Provider store={store}>
<Router history={history} routes={routes} />
<BrowserRouter>
{routes}
</BrowserRouter>
</Provider>,

document.getElementById('app')
Expand Down
112 changes: 69 additions & 43 deletions src/app/_server.js
Original file line number Diff line number Diff line change
@@ -1,59 +1,85 @@
import React from 'react';
import docTemplate from './HTML.js';
import { renderToString } from 'react-dom/server';
import { match, RouterContext } from 'react-router';
import { StaticRouter } from 'react-router';
import { Provider } from 'react-redux';
import Helmet from 'react-helmet';
import {encode} from '@tuxsudo/b64';
import routes from './routes.js';
import getStore from './store.js';
import { minify } from 'html-minifier';
import { resolve } from './hocs/ss-resolve';
// import { resolve } from './hocs/ss-resolve';
import {selectHTTPResponseCode} from './store.js';

import * as env from './env.js';


export default (req, res, next) => {
match({ routes, location: req.url }, (err, redirect, props) => {

if (err) {
return next(err);

} else if (redirect) {
res.redirect(redirect.pathname + redirect.search)

} else if (props) {
const store = getStore();

resolve(props, store)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To update to RR4, we will need to enable the server side functionality first and so this resolve functionality needs to be enabled or replicated...

.then(() => {
const initialState = store.getState();
const httpStatus = selectHTTPResponseCode(initialState);
const opaqueStateString = encode(JSON.stringify(initialState));

const content = renderToString(
<Provider store={store}>
<RouterContext {...props} />
</Provider>
);

res.status(httpStatus).send(
minify(
docTemplate({
...(Helmet.rewind()),
content,
initialState: opaqueStateString,
env,
base_path: env.APP_WEB_BASE_PATH
}),
{ collapseWhitespace: true, removeAttributeQuotes: true }
)
);
}).catch(next);

} else {
res.status(404).send('Not Found')
}
})
const store = getStore();

const content = renderToString(
<StaticRouter context={{}} location={req.url}>
<Provider store={store}>
{routes}
</Provider>
</StaticRouter>
)

const initialState = store.getState();
const httpStatus = selectHTTPResponseCode(initialState);
const opaqueStateString = encode(JSON.stringify(initialState));

res.status(httpStatus).send(
minify(
docTemplate({
...(Helmet.rewind()),
content,
initialState: opaqueStateString,
env,
base_path: env.APP_WEB_BASE_PATH
}),
{ collapseWhitespace: true, removeAttributeQuotes: true }
)
);
// match({ routes, location: req.url }, (err, redirect, props) => {

// if (err) {
// return next(err);

// } else if (redirect) {
// res.redirect(redirect.pathname + redirect.search)

// } else if (props) {
// const store = getStore();

// resolve(props, store)
// .then(() => {
// const initialState = store.getState();
// const httpStatus = selectHTTPResponseCode(initialState);
// const opaqueStateString = encode(JSON.stringify(initialState));

// const content = renderToString(
// <Provider store={store}>
// <RouterContext {...props} />
// </Provider>
// );

// res.status(httpStatus).send(
// minify(
// docTemplate({
// ...(Helmet.rewind()),
// content,
// initialState: opaqueStateString,
// env,
// base_path: env.APP_WEB_BASE_PATH
// }),
// { collapseWhitespace: true, removeAttributeQuotes: true }
// )
// );
// }).catch(next);

// } else {
// res.status(404).send('Not Found')
// }
// })
}
6 changes: 3 additions & 3 deletions src/app/components/SiteHeader/SiteHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import style from './SiteHeader.css';
import SiteNav from '../SiteNav/SiteNav';
import classes from 'join-classnames';
import logo from './logo-placeholder.svg';
import {IndexLink} from 'react-router';
import {Link} from 'react-router-dom';

export default ({homelink="/", links = [], className=""}) => (
<header className={classes(style.header, className)}>
<IndexLink to={homelink} className={style.brand}>
<Link to={homelink} className={style.brand}>
<img className={style.logo} src={logo} alt="My Brand" />
<span>React Starter</span>
</IndexLink>
</Link>
<SiteNav className={style.nav} links={links} />
</header>
);
2 changes: 1 addition & 1 deletion src/app/components/SiteNav/SiteNav.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import styles from './SiteNav.css';
import { Link } from 'react-router';
import { Link } from 'react-router-dom';
import classes from 'join-classnames';

export default ({links=[], className=""}) => (
Expand Down
15 changes: 10 additions & 5 deletions src/app/routes.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
import React from 'react';
import { Route, IndexRoute } from 'react-router';
import { Route, Switch } from 'react-router-dom';
import App from './containers/app.js';
import Home from './containers/home.js';
import NotFound from './containers/not-found.js';
import {APP_WEB_BASE_PATH} from './env.js';

const routes = (
<Route path={`${APP_WEB_BASE_PATH||'/'}`} component={App} >
<IndexRoute component={Home} />
<Route path="*" component={NotFound} />
</Route>
<Route
path="/"
render={props => (
<Switch>
<Route exact path="/" component={Home} />
<Route path="*" component={NotFound} />
</Switch>
)}
/>
);

export default routes;