From 37c6ff464ff80e03ff0ed2d10b5e1310a61909a2 Mon Sep 17 00:00:00 2001 From: Floris Bernard Date: Wed, 2 Aug 2017 14:05:20 +0200 Subject: [PATCH] Fix isInitializing for prepared components Fix issue where isInitializing is true when components have prepared and the intiMode switches to MODE_INIT_SELF --- package.json | 2 +- src/withInitAction.js | 5 ++++- tests/__snapshots__/withInitAction.spec.js.snap | 8 ++++---- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 57ace64..b4832f4 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/src/withInitAction.js b/src/withInitAction.js index 09a64bc..df9c55b 100644 --- a/src/withInitAction.js +++ b/src/withInitAction.js @@ -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) || diff --git a/tests/__snapshots__/withInitAction.spec.js.snap b/tests/__snapshots__/withInitAction.spec.js.snap index 6a75f8c..2289f71 100644 --- a/tests/__snapshots__/withInitAction.spec.js.snap +++ b/tests/__snapshots__/withInitAction.spec.js.snap @@ -12,14 +12,14 @@ exports[`withInitAction with a component that has been prepared and is re-initia `; -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`] = `
- initializing + completed
`; -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`] = `
- completed + initializing
`;