diff --git a/rollup.config.js b/rollup.config.js
index ae0c7264a..9a72d4eb2 100644
--- a/rollup.config.js
+++ b/rollup.config.js
@@ -2,7 +2,7 @@ import nodeResolve from 'rollup-plugin-node-resolve'
import babel from 'rollup-plugin-babel'
import replace from 'rollup-plugin-replace'
import commonjs from 'rollup-plugin-commonjs'
-import {uglify} from 'rollup-plugin-uglify'
+import { uglify } from 'rollup-plugin-uglify'
import pkg from './package.json'
const env = process.env.NODE_ENV
@@ -22,14 +22,17 @@ const config = {
nodeResolve(),
babel({
exclude: '**/node_modules/**',
- runtimeHelpers: true,
+ runtimeHelpers: true
}),
replace({
'process.env.NODE_ENV': JSON.stringify(env)
}),
commonjs({
namedExports: {
- 'node_modules/react-is/index.js': ['isValidElementType'],
+ 'node_modules/react-is/index.js': [
+ 'isValidElementType',
+ 'isContextConsumer'
+ ]
}
})
]
diff --git a/src/components/connectAdvanced.js b/src/components/connectAdvanced.js
index 4dbb9ff1a..cd9795ab4 100644
--- a/src/components/connectAdvanced.js
+++ b/src/components/connectAdvanced.js
@@ -1,7 +1,7 @@
import hoistStatics from 'hoist-non-react-statics'
import invariant from 'invariant'
import React, { Component, PureComponent } from 'react'
-import { isValidElementType } from 'react-is'
+import { isValidElementType, isContextConsumer } from 'react-is'
import { ReactReduxContext } from './Context'
@@ -213,7 +213,12 @@ export default function connectAdvanced(
}
render() {
- const ContextToUse = this.props.context || Context
+ const ContextToUse =
+ this.props.context &&
+ this.props.context.Consumer &&
+ isContextConsumer()
+ ? this.props.context
+ : Context
return (
diff --git a/test/components/connect.spec.js b/test/components/connect.spec.js
index 7a8629ec2..4ca9a2fd9 100644
--- a/test/components/connect.spec.js
+++ b/test/components/connect.spec.js
@@ -1564,6 +1564,36 @@ describe('React', () => {
expect(actualState).toEqual(expectedState)
})
+ it('should ignore non-react-context values that are passed as a prop to the component', () => {
+ class Container extends Component {
+ render() {
+ return
+ }
+ }
+
+ const nonContext = { someProperty: {} }
+
+ let actualState
+
+ const expectedState = { foos: {} }
+
+ const decorator = connect(state => {
+ actualState = state
+ return {}
+ })
+ const Decorated = decorator(Container)
+
+ const store = createStore(() => expectedState)
+
+ rtl.render(
+
+
+
+ )
+
+ expect(actualState).toEqual(expectedState)
+ })
+
it('should throw an error if the store is not in the props or context', () => {
const spy = jest.spyOn(console, 'error').mockImplementation(() => {})