diff --git a/package.json b/package.json index 99d5c1c0..fcff5904 100644 --- a/package.json +++ b/package.json @@ -55,6 +55,7 @@ "lodash.values": "^4.3.0", "prop-types": "^15.5.6", "react-addons-shallow-compare": "^15.4.2", + "setimmediate": "^1.0.5", "superagent": "^1.6.1" }, "peerDependencies": { diff --git a/src/components/connect-request.js b/src/components/connect-request.js index d3479f2f..c5fdf0ef 100644 --- a/src/components/connect-request.js +++ b/src/components/connect-request.js @@ -3,6 +3,7 @@ import includes from 'lodash.includes'; import intersection from 'lodash.intersection'; import React from 'react'; import shallowCompare from 'react-addons-shallow-compare'; +import setImmediate from 'setimmediate'; import { requestAsync, cancelQuery } from '../actions'; import { reconcileQueryKey } from '../lib/query-key'; @@ -77,12 +78,14 @@ const connectRequest = (mapPropsToConfigs, options = {}) => WrappedComponent => } cancelPendingRequests(cancelKeys) { - const { dispatch } = this.context.store; - const pendingKeys = Object.keys(this._pendingRequests); + setImmediate(() => { + const { dispatch } = this.context.store; + const pendingKeys = Object.keys(this._pendingRequests); - ensureArray(cancelKeys) - .filter(key => includes(pendingKeys, key)) - .forEach(queryKey => dispatch(cancelQuery(queryKey))); + ensureArray(cancelKeys) + .filter(key => includes(pendingKeys, key)) + .forEach(queryKey => dispatch(cancelQuery(queryKey))); + }); } requestAsync(configs, force = false, retry = false) {