Skip to content

Commit bfd88f6

Browse files
author
rodik
committed
We need to change propsToShow only if loadAsyncData that called this promise is the last invocation of loadAsyncData method. Otherwise we can face situation when user is changing route several times and we finally show him route that has loaded props last time and not the last called route
1 parent bf100e6 commit bfd88f6

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

modules/ReduxAsyncConnect.js

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ export function loadOnServer({ components, params }, store, helpers) {
4747
});
4848
}
4949

50+
let loadDataCounter = 0;
51+
5052
class ReduxAsyncConnect extends React.Component {
5153
static propTypes = {
5254
components: array.isRequired,
@@ -100,13 +102,23 @@ class ReduxAsyncConnect extends React.Component {
100102
const store = this.context.store;
101103
const promises = asyncConnectPromises(filterAndFlattenComponents(components), params, store, helpers);
102104

105+
loadDataCounter++;
106+
103107
if (promises.length) {
104108
this.props.beginGlobalLoad();
105-
Promise.all(promises).catch(error => console.error('reduxAsyncConnect server promise error: ' + error))
106-
.then(() => {
107-
this.setState({propsToShow: props});
108-
this.props.endGlobalLoad();
109-
});
109+
(loadDataCounterOriginal => {
110+
Promise.all(promises).catch(error => console.error('reduxAsyncConnect server promise error: ' + error))
111+
.then(() => {
112+
// We need to change propsToShow only if loadAsyncData that called this promise
113+
// is the last invocation of loadAsyncData method. Otherwise we can face situation
114+
// when user is changing route several times and we finally show him route that has
115+
// loaded props last time and not the last called route
116+
if (loadDataCounter === loadDataCounterOriginal) {
117+
this.setState({propsToShow: props});
118+
}
119+
this.props.endGlobalLoad();
120+
});
121+
})(loadDataCounter);
110122
} else {
111123
this.setState({propsToShow: props});
112124
}
@@ -118,4 +130,4 @@ class ReduxAsyncConnect extends React.Component {
118130
}
119131
}
120132

121-
export default connect(() => ({}), {beginGlobalLoad, endGlobalLoad})(ReduxAsyncConnect);
133+
export default connect(null, {beginGlobalLoad, endGlobalLoad})(ReduxAsyncConnect);

0 commit comments

Comments
 (0)