Skip to content
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

Lazy component load #118

Open
ghost opened this issue Nov 16, 2017 · 4 comments
Open

Lazy component load #118

ghost opened this issue Nov 16, 2017 · 4 comments

Comments

@ghost
Copy link

ghost commented Nov 16, 2017

Does this library allow me to connect lazy loaded (with webpack) component to reducer?

@bertho-zero
Copy link

bertho-zero commented Jan 5, 2018

redux-connect can not be used with react-loadable, because of these lines:

const layered = filterComponents(matchRoutes(routes, location.pathname));

export function filterComponents(branch) {
return branch.reduce((result, { route, match }) => {
if (route.component && route.component.reduxAsyncConnect) {
result.push([route.component, { route, match }]);
}
return result;
}, []);
}

redux-connect should allow to preload the missing files before fetching all the route.component.reduxAsyncConnect, like that in the case of react-loadable (from here):

function getComponents(match /* the result of matchRoutes */ ) {
  return match.map(v => v.route.component).reduce(async (result, component) => {
    if (component.preload) {
      const res = await component.preload();
      const ret = [...(await result), component, ...[].concat(res)];
      return ret;
    }
    return [...(await result), component];
  }, []);
}

@AVVS
Copy link
Member

AVVS commented Jan 5, 2018

You are very welcome to provide a PR with this as a non-breaking feature, such as custom component preloading, however async/await would require too much of extra payload, so please refrain from using it and just exploit regular promises

Thanks!

@gerhardsletten
Copy link

Wrote a comment here #116, could it not be possible if you write your own helper preparing the route-config for redux-connect, you dont need to give it the "original" route-config, but rather a enhanced one where you map the component-field for each field, and if its a async function you add it to a promise.all and when this is done you pass a config with loaded components so redux-connect can reach the static loading-function?

@gloompi
Copy link

gloompi commented Sep 23, 2020

@AVVS Hey Vitaly!
I implemented ssr code-splitting by using this library https://loadable-components.com/docs/server-side-rendering/
but whenever I try to wrap the component with asyncConnect it just stops working on server side, and by stops working I mean server returns incorrect HTML and it leads to warning react_devtools_backend.js:2273 Warning: Did not expect server HTML to contain a <div> in <div>.

Any ideas on how to make it compatible>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants