Skip to content

Commit

Permalink
Fix isInitializing for prepared components
Browse files Browse the repository at this point in the history
Fix issue where isInitializing is true when components have
prepared and the intiMode switches to MODE_INIT_SELF
  • Loading branch information
Floris Bernard committed Aug 2, 2017
1 parent 34a1e3a commit 37c6ff4
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-redux-component-init",
"version": "0.3.2",
"version": "0.3.3",
"description": "A library to manage async cpmponent initialization in isomorphic React/Redux applications with server-side rendering",
"main": "./lib/index.js",
"scripts": {
Expand Down
5 changes: 4 additions & 1 deletion src/withInitAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,10 @@ export default (p1, p2, p3) => {
const { __componentInitState, __initComponent, __modeInitSelf, ...props } = this.props;
const { selfInitState, isPrepared } = __componentInitState;

const isInitializing = __modeInitSelf ? !selfInitState : (allowLazy && !isPrepared);
const isInitializing = __modeInitSelf ? (
(selfInitState === false) ||
((typeof selfInitState === 'undefined') && !this.state.initializedOnce)
) : (allowLazy && !isPrepared);

const cloak = isInitializing && (
(initSelf === INIT_SELF_UNMOUNT) ||
Expand Down
8 changes: 4 additions & 4 deletions tests/__snapshots__/withInitAction.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ exports[`withInitAction with a component that has been prepared and is re-initia
</div>
`;

exports[`withInitAction with a component that has been prepared and no initSelf state and initMode === MODE_INIT_SELF sets an { isInitializing: true } prop 1`] = `
exports[`withInitAction with a component that has been prepared and no initSelf state and initMode === MODE_PREPARE does not set an { isInitializing: true } prop 1`] = `
<div>
initializing
completed
</div>
`;

exports[`withInitAction with a component that has been prepared and no initSelf state and initMode === MODE_PREPARE does not set an { isInitializing: true } prop 1`] = `
exports[`withInitAction with a component with no initSelf state and initMode === MODE_INIT_SELF sets an { isInitializing: true } prop 1`] = `
<div>
completed
initializing
</div>
`;

0 comments on commit 37c6ff4

Please sign in to comment.