From cd22f9bbf650d1da6c3b2674132dc073d8d443ef Mon Sep 17 00:00:00 2001 From: Petr Stefan Date: Fri, 3 Nov 2017 09:32:48 +0100 Subject: [PATCH 1/3] Enable SSR on all pages --- .../LicencesTableContainer/LicencesTableContainer.js | 6 +----- src/containers/UsersNameContainer/UsersNameContainer.js | 4 +--- src/helpers/clientOnly.js | 1 - src/pages/Exercise/Exercise.js | 4 +--- src/pages/ReferenceSolution/ReferenceSolution.js | 4 +--- .../ReferenceSolutionEvaluation.js | 5 +---- src/pages/Submission/Submission.js | 3 +-- 7 files changed, 6 insertions(+), 21 deletions(-) delete mode 100644 src/helpers/clientOnly.js diff --git a/src/containers/LicencesTableContainer/LicencesTableContainer.js b/src/containers/LicencesTableContainer/LicencesTableContainer.js index c10ab182e..74394b568 100644 --- a/src/containers/LicencesTableContainer/LicencesTableContainer.js +++ b/src/containers/LicencesTableContainer/LicencesTableContainer.js @@ -9,8 +9,6 @@ import LicencesTable from '../../components/Instances/LicencesTable'; import { fetchInstanceLincences } from '../../redux/modules/licences'; import { getLicencesOfInstance } from '../../redux/selectors/licences'; -import { clientOnly } from '../../helpers/clientOnly'; - class LicencesTableContainer extends Component { static loadAsync = ({ instanceId }, dispatch) => dispatch(fetchInstanceLincences(instanceId)); @@ -44,8 +42,6 @@ export default connect( }), (dispatch, { instance }) => ({ loadAsync: () => - clientOnly(() => - LicencesTableContainer.loadAsync({ instanceId: instance.id }, dispatch) - ) + LicencesTableContainer.loadAsync({ instanceId: instance.id }, dispatch) }) )(LicencesTableContainer); diff --git a/src/containers/UsersNameContainer/UsersNameContainer.js b/src/containers/UsersNameContainer/UsersNameContainer.js index 5a1bbc335..3ff1c8c13 100644 --- a/src/containers/UsersNameContainer/UsersNameContainer.js +++ b/src/containers/UsersNameContainer/UsersNameContainer.js @@ -11,7 +11,6 @@ import UsersName, { LoadingUsersName, FailedUsersName } from '../../components/Users/UsersName'; -import { clientOnly } from '../../helpers/clientOnly'; class UsersNameContainer extends Component { componentWillMount() { @@ -66,7 +65,6 @@ export default connect( }), (dispatch, { userId }) => ({ loadProfileIfNeeded: () => dispatch(fetchProfileIfNeeded(userId)), - loadData: () => - clientOnly(() => UsersNameContainer.loadData(userId, dispatch)) + loadData: () => UsersNameContainer.loadData(userId, dispatch) }) )(UsersNameContainer); diff --git a/src/helpers/clientOnly.js b/src/helpers/clientOnly.js deleted file mode 100644 index 5720c507e..000000000 --- a/src/helpers/clientOnly.js +++ /dev/null @@ -1 +0,0 @@ -export const clientOnly = fn => setTimeout(fn, 1); diff --git a/src/pages/Exercise/Exercise.js b/src/pages/Exercise/Exercise.js index 8ef431cf4..e5e83e49a 100644 --- a/src/pages/Exercise/Exercise.js +++ b/src/pages/Exercise/Exercise.js @@ -55,7 +55,6 @@ import { exercisePipelinesSelector } from '../../redux/selectors/pipelines'; import { loggedInUserIdSelector } from '../../redux/selectors/auth'; import { supervisorOfSelector } from '../../redux/selectors/groups'; -import { clientOnly } from '../../helpers/clientOnly'; import withLinks from '../../hoc/withLinks'; import { getLocalizedName } from '../../helpers/getLocalizedData'; @@ -468,8 +467,7 @@ export default withLinks( }; }, (dispatch, { params: { exerciseId } }) => ({ - loadAsync: () => - clientOnly(() => Exercise.loadAsync(dispatch, exerciseId)), + loadAsync: () => Exercise.loadAsync(dispatch, exerciseId), assignExercise: groupId => dispatch(assignExercise(groupId, exerciseId)), push: url => dispatch(push(url)), diff --git a/src/pages/ReferenceSolution/ReferenceSolution.js b/src/pages/ReferenceSolution/ReferenceSolution.js index 6371744a1..36c6a9787 100644 --- a/src/pages/ReferenceSolution/ReferenceSolution.js +++ b/src/pages/ReferenceSolution/ReferenceSolution.js @@ -12,7 +12,6 @@ import { Row, Col, Button } from 'react-bootstrap'; import withLinks from '../../hoc/withLinks'; import Page from '../../components/layout/Page'; -import { clientOnly } from '../../helpers/clientOnly'; import { fetchReferenceSolutionsIfNeeded, @@ -212,8 +211,7 @@ export default withLinks( referenceSolutions: referenceSolutionsSelector(exerciseId)(state) }), (dispatch, { params }) => ({ - loadAsync: () => - clientOnly(() => ReferenceSolution.loadAsync(params, dispatch)), + loadAsync: () => ReferenceSolution.loadAsync(params, dispatch), refreshSolutionEvaluations: () => { dispatch(fetchReferenceSolutions(params.exerciseId)); }, diff --git a/src/pages/ReferenceSolutionEvaluation/ReferenceSolutionEvaluation.js b/src/pages/ReferenceSolutionEvaluation/ReferenceSolutionEvaluation.js index cc0ea5fd7..165bbe427 100644 --- a/src/pages/ReferenceSolutionEvaluation/ReferenceSolutionEvaluation.js +++ b/src/pages/ReferenceSolutionEvaluation/ReferenceSolutionEvaluation.js @@ -11,7 +11,6 @@ import ImmutablePropTypes from 'react-immutable-proptypes'; import withLinks from '../../hoc/withLinks'; import Page from '../../components/layout/Page'; -import { clientOnly } from '../../helpers/clientOnly'; import { fetchReferenceSolutionsIfNeeded } from '../../redux/modules/referenceSolutions'; import { referenceSolutionsSelector } from '../../redux/selectors/referenceSolutions'; @@ -162,9 +161,7 @@ export default withLinks( }), (dispatch, { params }) => ({ loadAsync: () => - clientOnly(() => - ReferenceSolutionEvaluation.loadAsync(params, dispatch) - ), + ReferenceSolutionEvaluation.loadAsync(params, dispatch), downloadEvaluationArchive: e => { e.preventDefault(); dispatch(downloadEvaluationArchive(params.evaluationId)); diff --git a/src/pages/Submission/Submission.js b/src/pages/Submission/Submission.js index a5d4a6998..5f319c3de 100644 --- a/src/pages/Submission/Submission.js +++ b/src/pages/Submission/Submission.js @@ -22,7 +22,6 @@ import { isSuperAdmin } from '../../redux/selectors/users'; import { loggedInUserIdSelector } from '../../redux/selectors/auth'; -import { clientOnly } from '../../helpers/clientOnly'; import { getLocalizedName } from '../../helpers/getLocalizedData'; class Submission extends Component { @@ -150,7 +149,7 @@ export default injectIntl( isSuperAdmin(loggedInUserIdSelector(state))(state) }), (dispatch, { params }) => ({ - loadAsync: () => clientOnly(() => Submission.loadAsync(params, dispatch)) + loadAsync: () => Submission.loadAsync(params, dispatch) }) )(Submission) ); From 8920f8c4cae8dffaeaf21c82109a717f93b7a36c Mon Sep 17 00:00:00 2001 From: Petr Stefan Date: Fri, 3 Nov 2017 21:25:32 +0100 Subject: [PATCH 2/3] SSR fixes --- .../GroupsNameContainer/GroupsNameContainer.js | 13 +++++++------ .../UsersNameContainer/UsersNameContainer.js | 10 +++++----- src/pages/Exercise/Exercise.js | 4 ++-- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/containers/GroupsNameContainer/GroupsNameContainer.js b/src/containers/GroupsNameContainer/GroupsNameContainer.js index 04cc9a063..1da3f2f4d 100644 --- a/src/containers/GroupsNameContainer/GroupsNameContainer.js +++ b/src/containers/GroupsNameContainer/GroupsNameContainer.js @@ -12,17 +12,17 @@ import GroupsName, { class GroupsNameContainer extends Component { componentWillMount() { - GroupsNameContainer.loadData(this.props); + this.props.loadAsync(); } componentWillReceiveProps(newProps) { if (this.props.groupId !== newProps.groupId) { - GroupsNameContainer.loadData(newProps); + newProps.loadAsync(); } } - static loadData = ({ loadGroupIfNeeded }) => { - loadGroupIfNeeded(); + static loadAsync = ({ groupId }, dispatch) => { + dispatch(fetchPublicGroupIfNeeded(groupId)); }; render() { @@ -38,7 +38,8 @@ class GroupsNameContainer extends Component { GroupsNameContainer.propTypes = { groupId: PropTypes.string.isRequired, group: ImmutablePropTypes.map, - noLink: PropTypes.bool + noLink: PropTypes.bool, + loadAsync: PropTypes.func.isRequired }; export default connect( @@ -46,6 +47,6 @@ export default connect( group: publicGroupSelector(groupId)(state) }), (dispatch, { groupId }) => ({ - loadGroupIfNeeded: () => dispatch(fetchPublicGroupIfNeeded(groupId)) + loadAsync: () => GroupsNameContainer.loadAsync({ groupId }, dispatch) }) )(GroupsNameContainer); diff --git a/src/containers/UsersNameContainer/UsersNameContainer.js b/src/containers/UsersNameContainer/UsersNameContainer.js index 3ff1c8c13..02d63ba3e 100644 --- a/src/containers/UsersNameContainer/UsersNameContainer.js +++ b/src/containers/UsersNameContainer/UsersNameContainer.js @@ -14,16 +14,16 @@ import UsersName, { class UsersNameContainer extends Component { componentWillMount() { - this.props.loadData(); + this.props.loadAsync(); } componentWillReceiveProps(newProps) { if (this.props.userId !== newProps.userId) { - newProps.loadData(); + newProps.loadAsync(); } } - static loadData = (userId, dispatch) => { + static loadAsync = ({ userId }, dispatch) => { dispatch(fetchProfileIfNeeded(userId)); }; @@ -55,7 +55,7 @@ UsersNameContainer.propTypes = { large: PropTypes.bool, user: ImmutablePropTypes.map, noLink: PropTypes.bool, - loadData: PropTypes.func.isRequired + loadAsync: PropTypes.func.isRequired }; export default connect( @@ -65,6 +65,6 @@ export default connect( }), (dispatch, { userId }) => ({ loadProfileIfNeeded: () => dispatch(fetchProfileIfNeeded(userId)), - loadData: () => UsersNameContainer.loadData(userId, dispatch) + loadAsync: () => UsersNameContainer.loadAsync({ userId }, dispatch) }) )(UsersNameContainer); diff --git a/src/pages/Exercise/Exercise.js b/src/pages/Exercise/Exercise.js index e5e83e49a..b941caa1d 100644 --- a/src/pages/Exercise/Exercise.js +++ b/src/pages/Exercise/Exercise.js @@ -76,7 +76,7 @@ const messages = defineMessages({ class Exercise extends Component { state = { forkId: null }; - static loadAsync = (dispatch, exerciseId) => + static loadAsync = ({ exerciseId }, dispatch) => Promise.all([ dispatch(fetchExerciseIfNeeded(exerciseId)), dispatch(fetchReferenceSolutionsIfNeeded(exerciseId)), @@ -467,7 +467,7 @@ export default withLinks( }; }, (dispatch, { params: { exerciseId } }) => ({ - loadAsync: () => Exercise.loadAsync(dispatch, exerciseId), + loadAsync: () => Exercise.loadAsync({ exerciseId }, dispatch), assignExercise: groupId => dispatch(assignExercise(groupId, exerciseId)), push: url => dispatch(push(url)), From 37440f6c5aab5e3aa5b3839f23ee31c37383ba82 Mon Sep 17 00:00:00 2001 From: Martin Krulis Date: Fri, 3 Nov 2017 22:14:38 +0100 Subject: [PATCH 3/3] SSR bug fixed. --- src/server.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/server.js b/src/server.js index 381e5348e..233eec51b 100644 --- a/src/server.js +++ b/src/server.js @@ -59,6 +59,7 @@ const renderWithoutSSR = (res, renderProps) => { }; const renderPage = (res, store, renderProps) => { + let reduxState = serialize(store.getState(), { isJSON: true }); let html = renderToString( @@ -69,7 +70,7 @@ const renderPage = (res, store, renderProps) => { res.render('index', { html, head, - reduxState: serialize(store.getState(), { isJSON: true }), + reduxState, bundle, style: '/style.css' });