From 3e5a346848818c5d31aa8dc0b5592657dced0908 Mon Sep 17 00:00:00 2001 From: Sean Matheson Date: Wed, 5 Apr 2017 01:28:08 +0100 Subject: [PATCH] Moves state rehydrating deleting to componentWillMount to avoid issues with interop with other libs using react-async-bootstrapper. --- src/JobProvider.js | 4 ++++ src/withJob.js | 11 +++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/JobProvider.js b/src/JobProvider.js index 5950483..deb1904 100644 --- a/src/JobProvider.js +++ b/src/JobProvider.js @@ -29,6 +29,7 @@ class JobProvider extends Component { register: PropTypes.func.isRequired, get: PropTypes.func.isRequired, getRehydrate: React.PropTypes.func.isRequired, + removeRehydrate: React.PropTypes.func.isRequired, }).isRequired, }; @@ -48,6 +49,9 @@ class JobProvider extends Component { delete this.rehydrateState.jobs[id] return rehydration }, + removeRehydrate: (id) => { + delete this.rehydrateState.jobs[id] + }, }, } } diff --git a/src/withJob.js b/src/withJob.js index c3a7990..0378f6d 100644 --- a/src/withJob.js +++ b/src/withJob.js @@ -39,8 +39,9 @@ export default function withJob(config) { register: PropTypes.func.isRequired, get: PropTypes.func.isRequired, getRehydrate: React.PropTypes.func.isRequired, + removeRehydrate: React.PropTypes.func.isRequired, }), - } + }; constructor(props, context) { super(props, context) @@ -58,9 +59,7 @@ export default function withJob(config) { } // node - return serverMode === 'defer' - ? false - : this.resolveWork(this.props) + return serverMode === 'defer' ? false : this.resolveWork(this.props) } componentWillMount() { @@ -83,6 +82,10 @@ export default function withJob(config) { if (!this.state.completed) { this.resolveWork(this.props) } + + if (this.context.jobs && env === 'browser') { + this.context.jobs.removeRehydrate(id) + } } componentWillUnmount() {