diff --git a/fixtures/nesting/package.json b/fixtures/nesting/package.json index 3a5a893714ec4..130ecfa54e772 100644 --- a/fixtures/nesting/package.json +++ b/fixtures/nesting/package.json @@ -3,7 +3,8 @@ "version": "0.1.0", "private": true, "dependencies": { - "react-scripts": "3.4.1" + "react-scripts": "3.4.1", + "redux": "^4.0.5" }, "scripts": { "postinstall": "run-p install:*", diff --git a/fixtures/nesting/src/legacy/Greeting.js b/fixtures/nesting/src/legacy/Greeting.js index b06ea7c9cc805..706e1b23ee7dc 100644 --- a/fixtures/nesting/src/legacy/Greeting.js +++ b/fixtures/nesting/src/legacy/Greeting.js @@ -2,10 +2,12 @@ import React from 'react'; import {Component} from 'react'; import {findDOMNode} from 'react-dom'; import {Link} from 'react-router-dom'; +import {connect} from 'react-redux'; + import ThemeContext from './shared/ThemeContext'; import Clock from './shared/Clock'; -export default class AboutSection extends Component { +class AboutSection extends Component { static contextType = ThemeContext; componentDidMount() { @@ -23,6 +25,13 @@ export default class AboutSection extends Component { This component is rendered by the nested React. +

+ Counter: {this.props.counter} + {' '} + +

Go to Home @@ -30,3 +39,10 @@ export default class AboutSection extends Component { ); } } + + +function mapStateToProps(state) { + return { counter: state }; +} + +export default connect(mapStateToProps)(AboutSection); diff --git a/fixtures/nesting/src/legacy/createLegacyRoot.js b/fixtures/nesting/src/legacy/createLegacyRoot.js index 982308756647d..3c5bb6787ac31 100644 --- a/fixtures/nesting/src/legacy/createLegacyRoot.js +++ b/fixtures/nesting/src/legacy/createLegacyRoot.js @@ -7,6 +7,7 @@ import ThemeContext from './shared/ThemeContext'; // Note: this is a semi-private API, but it's ok to use it // if we never inspect the values, and only pass them through. import {__RouterContext} from 'react-router'; +import {ReactReduxContext} from 'react-redux'; // Pass through every context required by this tree. // The context object is populated in src/modern/withLegacyRoot. @@ -14,7 +15,9 @@ function Bridge({children, context}) { return ( <__RouterContext.Provider value={context.router}> - {children} + + {children} + ); diff --git a/fixtures/nesting/src/legacy/package.json b/fixtures/nesting/src/legacy/package.json index 463193057d25c..38d9461993e90 100644 --- a/fixtures/nesting/src/legacy/package.json +++ b/fixtures/nesting/src/legacy/package.json @@ -4,6 +4,7 @@ "dependencies": { "react": "0.0.0-3d0895557", "react-dom": "0.0.0-3d0895557", + "react-redux": "^7.2.1", "react-router-dom": "5.2.0" } } diff --git a/fixtures/nesting/src/modern/AboutPage.js b/fixtures/nesting/src/modern/AboutPage.js index 3f7eb69051fcf..d8e3b4e8f5dce 100644 --- a/fixtures/nesting/src/modern/AboutPage.js +++ b/fixtures/nesting/src/modern/AboutPage.js @@ -1,5 +1,6 @@ import React from 'react'; import {useContext} from 'react'; +import {connect} from 'react-redux'; import ThemeContext from './shared/ThemeContext'; import lazyLegacyRoot from './lazyLegacyRoot'; @@ -7,7 +8,7 @@ import lazyLegacyRoot from './lazyLegacyRoot'; // Lazy-load a component from the bundle using legacy React. const Greeting = lazyLegacyRoot(() => import('../legacy/Greeting')); -export default function AboutPage() { +function AboutPage({ counter, dispatch }) { const theme = useContext(ThemeContext); return ( <> @@ -16,6 +17,20 @@ export default function AboutPage() { This component is rendered by the outer React. +
+

+ Counter: {counter} + {' '} + +

); } + +function mapStateToProps(state) { + return { counter: state }; +} + +export default connect(mapStateToProps)(AboutPage); diff --git a/fixtures/nesting/src/modern/HomePage.js b/fixtures/nesting/src/modern/HomePage.js index 43ab3bfe83351..13073e4acb6d8 100644 --- a/fixtures/nesting/src/modern/HomePage.js +++ b/fixtures/nesting/src/modern/HomePage.js @@ -5,7 +5,7 @@ import {Link} from 'react-router-dom'; import ThemeContext from './shared/ThemeContext'; import Clock from './shared/Clock'; -export default function HomePage() { +export default function HomePage({ counter, dispatch }) { const theme = useContext(ThemeContext); return ( <> diff --git a/fixtures/nesting/src/modern/index.js b/fixtures/nesting/src/modern/index.js index 17021479a4e54..940886e9bbaf2 100644 --- a/fixtures/nesting/src/modern/index.js +++ b/fixtures/nesting/src/modern/index.js @@ -1,11 +1,15 @@ import React from 'react'; import {StrictMode} from 'react'; import ReactDOM from 'react-dom'; +import {Provider} from 'react-redux'; import App from './App'; +import {store} from '../store'; ReactDOM.render( - + + + , document.getElementById('root') ); diff --git a/fixtures/nesting/src/modern/lazyLegacyRoot.js b/fixtures/nesting/src/modern/lazyLegacyRoot.js index 2e91691744879..94e8dc048dca7 100644 --- a/fixtures/nesting/src/modern/lazyLegacyRoot.js +++ b/fixtures/nesting/src/modern/lazyLegacyRoot.js @@ -1,7 +1,8 @@ import React from 'react'; import {useContext, useMemo, useRef, useState, useLayoutEffect} from 'react'; - import {__RouterContext} from 'react-router'; +import {ReactReduxContext} from 'react-redux'; + import ThemeContext from './shared/ThemeContext'; let rendererModule = { @@ -29,12 +30,14 @@ export default function lazyLegacyRoot(getLegacyComponent) { // Then in src/legacy/createLegacyRoot we will apply them. const theme = useContext(ThemeContext); const router = useContext(__RouterContext); + const reactRedux = useContext(ReactReduxContext); const context = useMemo( () => ({ theme, router, + reactRedux, }), - [theme, router] + [theme, router, reactRedux] ); // Create/unmount. diff --git a/fixtures/nesting/src/modern/package.json b/fixtures/nesting/src/modern/package.json index 5f0195ffdcec2..28583768d2697 100644 --- a/fixtures/nesting/src/modern/package.json +++ b/fixtures/nesting/src/modern/package.json @@ -4,6 +4,7 @@ "dependencies": { "react": "0.0.0-3d0895557", "react-dom": "0.0.0-3d0895557", + "react-redux": "^7.2.1", "react-router-dom": "5.2.0" } } diff --git a/fixtures/nesting/src/store.js b/fixtures/nesting/src/store.js new file mode 100644 index 0000000000000..5be26f9322c6e --- /dev/null +++ b/fixtures/nesting/src/store.js @@ -0,0 +1,12 @@ +import {createStore} from 'redux'; + +function reducer(state = 0, action) { + switch (action.type) { + case 'increment': + return state + 1; + default: + return state; + } +} + +export const store = createStore(reducer);