Skip to content

Commit

Permalink
Merge pull request #51 from mediamonks/develop
Browse files Browse the repository at this point in the history
Fix breaking changes regarding the server side rendering
  • Loading branch information
tommymm authored Apr 13, 2022
2 parents 36953f1 + 52276ae commit 59908c0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mediamonks/react-redux-component-init",
"version": "2.0.5",
"version": "2.0.6",
"description": "A library to manage async component initialization in isomorphic React/Redux applications with server-side rendering",
"main": "./lib/index.js",
"scripts": {
Expand Down
18 changes: 15 additions & 3 deletions src/actions/initComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import propNameValuesToObject from '../utils/propNameValuesToObject';
import { MODE_INIT_SELF, MODE_PREPARE } from '../initMode';
import PrepareValidationError from '../PrepareValidationError';
import { INIT_SELF_NEVER } from '../initSelfMode';

import { INIT_COMPONENT } from './actionTypes';

/**
Expand All @@ -25,7 +24,7 @@ import { INIT_COMPONENT } from './actionTypes';
* is generated by the `getPrepareKey()` util.
* @param {object} [options] Additional options
* @param {string} options.caller The function from which initialization is triggered. Valid options
* are 'prepareComponent', 'didMount', 'didUpdate'
* are 'prepareComponent', 'didMount', 'willMount', 'willReceiveProps'
* @returns {function} A thunk function that should be passed directly to the Redux `dispatch`
* function.
*/
Expand Down Expand Up @@ -61,7 +60,7 @@ export default (Component, initValues, prepareKey, { caller } = {}) => (dispatch
shouldCallInitAction = !!initAction && !isPrepared;
shouldCallInitActionClient = false;
break;
case 'didMount':
case 'constructor':
errorNotPrepared = !!initAction && mode === MODE_PREPARE && !allowLazy;
shouldCallInitAction =
!!initAction &&
Expand All @@ -71,6 +70,19 @@ export default (Component, initValues, prepareKey, { caller } = {}) => (dispatch
(mode === MODE_PREPARE && !isPrepared && allowLazy));
shouldCallInitActionClient = false;
break;
case 'didMount':
errorNotPrepared = false;
shouldCallInitAction =
!!initAction &&
// mounted on the client (after first render), lazy allowed
((mode === MODE_INIT_SELF && initSelf !== INIT_SELF_NEVER && allowLazy) ||
// first render, not already prepared, lazy allowed
(mode === MODE_PREPARE && !isPrepared && allowLazy));
shouldCallInitActionClient =
!!initActionClient &&
// mounted on the client (after first render)
initSelf !== INIT_SELF_NEVER;
break;
case 'didUpdate':
// reinitialize is checked in withInitAction
errorNotPrepared = false;
Expand Down
6 changes: 5 additions & 1 deletion src/withInitAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,16 @@ export default (p1, p2, p3) => {

const {
__modeInitSelf,
__componentInitState: { isPrepared },
__componentInitState: { isPrepared, initValues, prepareKey },
} = props;

this.state = {
initializedOnce: !__modeInitSelf && isPrepared && !initActionClient,
};

this.props
.__initComponent(initValues, prepareKey, { caller: 'constructor' })
.catch(this.handleInitError);
}

componentDidMount() {
Expand Down

0 comments on commit 59908c0

Please sign in to comment.