-
Notifications
You must be signed in to change notification settings - Fork 80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
react-redux 6.0.0 #172
Comments
Any ideas on a quick fix? Seeing as you maintain a lib that solves these things. I know there’s an open or to Link for redux 6 I’m in the middle of supporting react static which is close to release, so I’m tied up for this week monitoring finalizations and ptching a big issue. I’ll comms with you more soon as my RS stuff clears up by week end |
Looking back to this issue, we can see the first problem has been fixed in reduxjs/react-redux#1126 But the original problem is not fixed, the onLoad function is not working properly. The fourth parameter Example : a service worker for cache purposes wants to precache several routes. It will trigger multiple calls in parallel to the server. All these calls made at the same time will overlap the current store being used. Using a reference to the one and only store works with a Single Page Application (SPA) not with Server Side Rendering (SSR) context where multiple store can be instantiated. The only way to deal with it when injecting reducer in the store is to know the context store as before. @ScriptedAlchemy Do you think, there is a way to reinclude the context store in the fourth parameter? |
Sounds like a toughie, can you make a code example of how the end user would use it? |
Let me know, but i need to move RUC branch to react 16 and i know its stable. How’s the time to add any last things to it if you wish @GuillaumeCisco Hit me up on slack if neeed be |
Hey @ScriptedAlchemy, I spent yesterday afternoon on this issue and what it led me to think
Here the context is available. But what is As you can see in the example of the So I thought the easiest way was to simply add the Turning the import universal from 'react-universal-component';
import {ReactReduxContext} from 'react-redux';
const UniversalComponent = universal(props => import(`./${props.page}`), {
onLoad: (module, info, {context, ...props}) => { // modification for using context from a prop
context.store.replaceReducer({ ...otherReducers, foo: module.fooReducer })
// if a route triggered component change, new reducers needs to reflect it
context.store.dispatch({ type: 'INIT_ACTION_FOR_ROUTE', payload: { param: props.param } })
}
})
export default () =>
<div>
<ReactReduxContext.Consumer>
{(reduxContext) => <UniversalComponent page='Foo' context={reduxContext}/>}
</ReactReduxContext.Consumer>);
</div> Interestingly, it worked like a charm with one of my connected component which is lazy loaded (universal) and dynamically load a reducer (store.replaceReducer) with the new import React, {Component} from 'react';
import {ReactReduxContext} from 'react-redux';
export default function withRedux(WrappedComponent) {
class WithRedux extends Component {
constructor(...args) {
super(...args);
this.firstRender = true;
}
render() {
if (this.firstRender) {
this.firstRender = false;
return (
<ReactReduxContext.Consumer>
{(reduxContext) =>
<ReactReduxContext.Provider
value={{
...reduxContext,
storeState: reduxContext.store.getState(),
}}
>
<WrappedComponent {...this.props} />
</ReactReduxContext.Provider>
}
</ReactReduxContext.Consumer>
);
}
return <WrappedComponent {...this.props} />;
}
}
return WithRedux;
} Used as: export default withRedux(connect(mapStateToProps)(MyComponent)); But absolutely not for a second Component which seem to be build on the same architecture. |
Hello there, I succeeded to fix this issue, but another one appeared with You can see why it was not working on this codesandbox: The difference leaves in the We can see in the not working example this error:
This issue is now directly related to reduxjs/react-redux#1126. One more new issue appeared though :/ By the way, you can test modifying the working example in the codesandbox and you'll see the code is broken too after a codesandbox hot reload. Try clicking on the So I'm glad now I can use the context.store in the onLoad method of static contextTypes = {
store: PropTypes.object,
report: PropTypes.func
} It does not work with For now, the only recommendation I have for making react-universal-component and reducer injection working with multiple concurrent calls on the server is to change the onLoad documentation to: import universal from 'react-universal-component';
import {ReactReduxContext} from 'react-redux';
const UniversalComponent = universal(props => import(`./${props.page}`), {
onLoad: (module, info, {reduxcontext, ...props}) => { // modification for using context from a prop
reduxcontext.store.replaceReducer({ ...otherReducers, foo: module.fooReducer })
// if a route triggered component change, new reducers needs to reflect it
reduxcontext.store.dispatch({ type: 'INIT_ACTION_FOR_ROUTE', payload: { param: props.param } })
}
})
export default () =>
<div>
<ReactReduxContext.Consumer>
{(reduxContext) => <UniversalComponent page='Foo' reduxcontext={reduxContext}/>}
</ReactReduxContext.Consumer>);
</div> And talking about the Thoughts? |
Dude, this is exactly what onload is for, you unraveled one of James secrets (i think) there are a few hidden gems in RUC that we have not disclosed, however, with this one, it might be a good idea to document your implementations as you have done here. This is a really long issue, could we have a call around this, my dyslexia makes it very hard to follow your discoveries on this whole thing. If what you are saying is you found the gem in RUC and hot reloading is the only blocker, i know the maintainer of it personally and if you provide me a codesandbox - ill have him address it directly. Sorry its been a busy day and so many words are moving around that i cannot fully get your needs here. We can do a slack call tomorrow or later today if you wish? |
Hello @ScriptedAlchemy I succeeded to make it works with The new implementation I come with is: import React, {Component} from "react";
import universal from "react-universal-component";
import { injectReducer } from "redux-reducers-injector";
import { ReactReduxContext } from "react-redux";
class Universal extends Component {
constructor(props) {
super(props);
this.firstRender = true;
}
render() {
const UniversalComponent = universal(import("./component"), {
loading: <span>loading</span>,
onLoad: (module, info, { reduxcontext }) => {
if (reduxcontext && reduxcontext.store) {
injectReducer("api", module.reducer, false, reduxcontext.store);
}
}
if (this.firstRender) {
this.firstRender = false;
return (<ReactReduxContext.Consumer>
{(reduxContext) => <UniversalComponent reduxcontext={reduxContext}/>}
</ReactReduxContext.Consumer>);
}
return <UniversalComponent/>;
});
export default Universal; |
Can you open a pull request so I can better understand the changes proposed? Ideally on the React 16 branch. If it’s hot loading. I know the guy who built it so easy fix. Can this be abstracted into the HOC to some level. Seems like a lot of boilerplate. Can’t this just be in RUC? With facebooks suspense being built from merging in RUC, we will also be putting up documentation on that. Make a PR ideally to RUC and I’ll look it over for merge |
Hey @ScriptedAlchemy I think we can transpose some main guidelines into the README of Maybe we should write a tutorial on how to use I'd like to wait the point of view of other people interested with Right now, there is absolutely nothing to change in the code of |
If you would update the documentation on our end to point to those PRs or readmes that would be great information for us to have on hand!! |
I use RR with RUC in this way: class App extends Component {
render() {
return (
<ReactReduxContext.Consumer>
{props => {
return (
<Switcher store={props.store} /> /* or even {...props} */
)
}}
</ReactReduxContext.Consumer>
)
}
}
export default hot(module)(App) and somewhere in Switcher.js: let innerStore
const UniversalComponent = universal(determineHowToLoad, {
//...
onLoad: (module, { isSync, isServer }, props, context) => {
const { store } = props
innerStore = store
}
}
const Switcher = ({ store, page, type }) => (
<UniversalComponent
component={`${page}`}
onAfter={onAfterChanged}
type={type}
store={store}
/>
) |
Just ran into an issue with the new way react-redux behaves.
You can see more details about it in this thread: reduxjs/react-redux#935 (comment)
As we can see from the last release of react-redux 6.0.0: https://github.com/reduxjs/react-redux/releases
This makes the
onLoad
function not working properly. The fourth parametercontext
is no more populated with the store.Although it is not a real issue for me, as I use
redux-reducers-injector
(I'm the maintainer), I have a reference of the store that I can use, and can usereplaceReducer
.The real issue is that even with injecting my reducer correctly, the
mapStateToProps
will not reflect this change in its first parameterstate
and I won't be able to display my component correctly.You can read more about this issue in the link I post above on the react-redux project: reduxjs/react-redux#935 (comment)
Feel free to ask me more information about this.
The text was updated successfully, but these errors were encountered: